Skip to content

Commit

Permalink
Merge branch 'master' into add-review-column-workspace-planner
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammadUmer44 authored Jan 5, 2025
2 parents c61b168 + aa495cf commit defd498
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 96 deletions.
25 changes: 1 addition & 24 deletions src/people/WorkSpacePlanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ColumnsContainer = styled.div`
gap: 1rem;
padding: 1rem;
overflow-x: auto;
background: whote;
background: white;
height: calc(100vh - 200px) !important;
&::-webkit-scrollbar {
Expand Down Expand Up @@ -102,21 +102,6 @@ const ColumnContent = styled.div`
}
`;

const LoadMoreButton = styled.button`
width: 100%;
padding: 0.5rem;
background: ${colors.light.grayish.G800};
color: white;
border: none;
border-top: 1px solid ${colors.light.grayish.G700};
cursor: pointer;
transition: background 0.2s;
&:hover {
background: ${colors.light.grayish.G700};
}
`;

const LoadingContainer = styled.div`
display: flex;
justify-content: center;
Expand Down Expand Up @@ -233,14 +218,6 @@ const WorkspacePlanner = observer(() => {
))
)}
</ColumnContent>

{id === 'Todo' &&
bountyCardStore.pagination.currentPage * bountyCardStore.pagination.pageSize <
bountyCardStore.pagination.total && (
<LoadMoreButton onClick={() => bountyCardStore.loadNextPage()}>
Load More
</LoadMoreButton>
)}
</Column>
))}
</ColumnsContainer>
Expand Down
26 changes: 0 additions & 26 deletions src/store/__test__/bountyCard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ describe('BountyCardStore', () => {
expect(store.bountyCards).toEqual([]);
expect(store.currentWorkspaceId).toBe(mockWorkspaceId);
expect(store.loading).toBeFalsy();
expect(store.pagination).toEqual({
currentPage: 1,
pageSize: 10,
total: 0
});
});
});

Expand Down Expand Up @@ -93,7 +88,6 @@ describe('BountyCardStore', () => {

await waitFor(() => store.switchWorkspace(newWorkspaceId));
expect(store.currentWorkspaceId).toBe(newWorkspaceId);
expect(store.pagination.currentPage).toBe(1);
expect(store.bountyCards).toEqual([{ ...mockBounties[0], status: 'Todo' }]);
});

Expand All @@ -107,26 +101,6 @@ describe('BountyCardStore', () => {
});
});

describe('loadNextPage', () => {
it('should not load next page if already loading', async () => {
store = await waitFor(() => new BountyCardStore(mockWorkspaceId));

store.loading = true;

await waitFor(() => store.loadNextPage());
});

it('should not load next page if all items are loaded', async () => {
store = await waitFor(() => new BountyCardStore(mockWorkspaceId));

store.pagination.total = 10;
store.pagination.currentPage = 1;
store.pagination.pageSize = 10;

await waitFor(() => store.loadNextPage());
});
});

describe('calculateBountyStatus', () => {
let store: BountyCardStore;

Expand Down
52 changes: 6 additions & 46 deletions src/store/bountyCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ export class BountyCardStore {
currentWorkspaceId: string;
loading = false;
error: string | null = null;
pagination = {
currentPage: 1,
pageSize: 10,
total: 0
};

@observable selectedFeatures: string[] = [];

constructor(workspaceId: string) {
Expand All @@ -28,14 +24,6 @@ export class BountyCardStore {
this.restoreFilterState();
}

private constructQueryParams(): string {
const { currentPage, pageSize } = this.pagination;
return new URLSearchParams({
page: currentPage.toString(),
limit: pageSize.toString()
}).toString();
}

private calculateBountyStatus(bounty: BountyCard): BountyCardStatus {
if (bounty.paid) {
return 'Paid';
Expand Down Expand Up @@ -68,8 +56,7 @@ export class BountyCardStore {
this.error = null;
});

const queryParams = this.constructQueryParams();
const url = `${TribesURL}/gobounties/bounty-cards?workspace_uuid=${this.currentWorkspaceId}&${queryParams}`;
const url = `${TribesURL}/gobounties/bounty-cards?workspace_uuid=${this.currentWorkspaceId}`;

const response = await fetch(url, {
method: 'GET',
Expand Down Expand Up @@ -115,21 +102,10 @@ export class BountyCardStore {
);

runInAction(() => {
if (this.pagination.currentPage === 1) {
this.bountyCards = bountyCardsWithProofs.map((bounty: BountyCard) => ({
...bounty,
status: this.calculateBountyStatus(bounty)
}));
} else {
this.bountyCards = [
...this.bountyCards,
...bountyCardsWithProofs.map((bounty: BountyCard) => ({
...bounty,
status: this.calculateBountyStatus(bounty)
}))
];
}
this.pagination.total = data?.length || 0;
this.bountyCards = bountyCardsWithProofs.map((bounty: BountyCard) => ({
...bounty,
status: this.calculateBountyStatus(bounty)
}));
});
} catch (error) {
console.error('Error loading bounties:', error);
Expand All @@ -148,28 +124,12 @@ export class BountyCardStore {

runInAction(() => {
this.currentWorkspaceId = newWorkspaceId;
this.pagination.currentPage = 1;
this.bountyCards = [];
});

await this.loadWorkspaceBounties();
};

loadNextPage = async (): Promise<void> => {
if (
this.loading ||
this.pagination.currentPage * this.pagination.pageSize >= this.pagination.total
) {
return;
}

runInAction(() => {
this.pagination.currentPage += 1;
});

await this.loadWorkspaceBounties();
};

@computed get todoItems() {
return this.bountyCards.filter((card: BountyCard) => card.status === 'Todo');
}
Expand Down

0 comments on commit defd498

Please sign in to comment.