Skip to content

Commit

Permalink
fix: bar
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-ae committed Jan 10, 2025
1 parent 57dba0c commit e4e77c1
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/store/bountyCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface FilterState {
selectedPhases: string[];
selectedStatuses: string[];
timestamp: number;
searchText: string;
}

export class BountyCardStore {
Expand All @@ -20,6 +21,7 @@ export class BountyCardStore {
@observable selectedFeatures: string[] = [];
@observable selectedPhases: string[] = [];
@observable selectedStatuses: string[] = [];
@observable searchText = '';

constructor(workspaceId: string) {
this.currentWorkspaceId = workspaceId;
Expand Down Expand Up @@ -145,6 +147,7 @@ export class BountyCardStore {
selectedFeatures: this.selectedFeatures,
selectedPhases: this.selectedPhases,
selectedStatuses: this.selectedStatuses,
searchText: this.searchText,
timestamp: Date.now()
})
);
Expand Down Expand Up @@ -205,6 +208,8 @@ export class BountyCardStore {
this.selectedPhases = [];
sessionStorage.removeItem('bountyFilterState');
this.saveFilterState();
this.selectedStatuses = [];
this.searchText = '';
}

@action
Expand Down Expand Up @@ -241,6 +246,13 @@ export class BountyCardStore {
@computed
get filteredBountyCards() {
return this.bountyCards.filter((card: BountyCard) => {
const searchMatch =
!this.searchText ||
[card.title, card.features?.name, card.phase?.name].some(
(field: string | undefined) =>
field?.toLowerCase().includes(this.searchText.toLowerCase().trim())
);

const featureMatch =
this.selectedFeatures.length === 0 ||
(this.selectedFeatures.includes('no-feature') && !card.features?.uuid) ||
Expand All @@ -254,14 +266,33 @@ export class BountyCardStore {
this.selectedStatuses.length === 0 ||
(card.status && this.selectedStatuses.includes(card.status));

return featureMatch && phaseMatch && statusMatch;
return searchMatch && featureMatch && phaseMatch && statusMatch;
});
}

@computed
get hasCardsWithoutFeatures() {
return this.bountyCards.some((card: BountyCard) => !card.features?.uuid);
}

@action
setSearchText(text: string) {
this.searchText = text.trim();
this.saveFilterState();
}

@action
clearSearch() {
this.searchText = '';
this.saveFilterState();
}

private sanitizeSearchText(text: string): string {
return text
.replace(/\s+/g, ' ')
.replace(/[^\w\s-]/g, '')
.trim();
}
}

export const useBountyCardStore = (workspaceId: string) =>
Expand Down

0 comments on commit e4e77c1

Please sign in to comment.