Skip to content

Commit

Permalink
fixed the rest of the filters not working with all filter
Browse files Browse the repository at this point in the history
  • Loading branch information
vihangckale committed Jul 17, 2024
1 parent 4808e3b commit 823fccc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions shared/data/utils/challenges.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export function getChallengesByDifficulties(challenges: IChallenge[], difficulti
return challenges.filter((challenge) => difficultyValues.includes(challenge.difficulty));
}

export function getChallengesByTags(challenges: IChallenge[], tags: ETag[]) {
if (!tags || tags.length === 0) return challenges;
export function getChallengesByTags(challenges: IChallenge[], tags: ETag[], isResetTags: boolean) {
if (isResetTags) return challenges;
return challenges.filter((challenge) => {
if (!challenge.tags) return false;
return tags.some((tag: ETag) => (challenge.tags as ETag[])?.includes(tag));
Expand All @@ -87,11 +87,12 @@ export function getChallengesByid({
difficulties,
tags,
}: IGetChallengesByid) {
const isResetTags = !tags || tags.length === 0 || (tags?.length == 1 && tags[0] == ETag.all);
if (
(!title || title.length === 0) &&
(!contributors || contributors.length === 0) &&
(!difficulties || difficulties.length === 0) &&
(!tags || tags.length === 0 || (tags?.length == 1 && tags[0] == ETag.all))
isResetTags
) {
return challenges;
}
Expand All @@ -101,7 +102,7 @@ export function getChallengesByid({
filteredChallenges = getChallengesByContributors(filteredChallenges, contributors);

filteredChallenges = getChallengesByDifficulties(filteredChallenges, difficulties);
filteredChallenges = getChallengesByTags(filteredChallenges, tags);
filteredChallenges = getChallengesByTags(filteredChallenges, tags, isResetTags);

return filteredChallenges;
}

0 comments on commit 823fccc

Please sign in to comment.