Skip to content

Commit 7e3744c

Browse files
committed
feat: hide quiz challenge if finished
1 parent 662d6b0 commit 7e3744c

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

frontend/app/api/generated.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2615,7 +2615,7 @@ export type ChallengesPageQueryVariables = Exact<{ [key: string]: never; }>;
26152615

26162616
export type ChallengesPageQuery = { __typename?: 'Query', myCurrentProject: { __typename?: 'Project', challenges: Array<
26172617
| { __typename: 'ExternalChallenge', url: string, id: string, name: string, description: any, image?: string | null, buttonText: string, publishedAt?: any | null, endTime?: any | null, visibleAt?: any | null, userCompletedAt?: any | null }
2618-
| { __typename: 'QuizChallenge', id: string, name: string, description: any, image?: string | null, buttonText: string, publishedAt?: any | null, endTime?: any | null, visibleAt?: any | null, userCompletedAt?: any | null }
2618+
| { __typename: 'QuizChallenge', id: string, name: string, description: any, image?: string | null, buttonText: string, publishedAt?: any | null, endTime?: any | null, visibleAt?: any | null, userCompletedAt?: any | null, quiz: { __typename?: 'Quiz', userCanStart: boolean } }
26192619
| { __typename: 'SimpleChallenge', allowSelfCompletion: boolean, id: string, name: string, description: any, image?: string | null, buttonText: string, publishedAt?: any | null, endTime?: any | null, visibleAt?: any | null, userCompletedAt?: any | null }
26202620
> } };
26212621

@@ -3412,6 +3412,11 @@ export const ChallengesPageDocument = gql`
34123412
... on ExternalChallenge {
34133413
url
34143414
}
3415+
... on QuizChallenge {
3416+
quiz {
3417+
userCanStart
3418+
}
3419+
}
34153420
}
34163421
}
34173422
}

frontend/app/components/challenges/ChallengeCard.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ const props = defineProps<{
55
66
const { track } = useAnalytics()
77
8+
const externalUrl = computed(() => {
9+
if (props.challenge.__typename === 'ExternalChallenge') {
10+
return props.challenge.url
11+
}
12+
return null
13+
})
14+
815
function onChallengeClick() {
916
track(AnalyticsEvent.ChallengeLinkClicked, {
1017
challenge_id: props.challenge.id,
1118
challenge_name: props.challenge.name,
12-
is_external: !!props.challenge.url,
19+
is_external: !!externalUrl.value,
1320
})
1421
}
1522
</script>
@@ -30,7 +37,7 @@ function onChallengeClick() {
3037
<div class="mt-auto grid">
3138
<NuxtLink
3239
:to="
33-
challenge.url || {
40+
externalUrl || {
3441
name: 'challenges-challengeId',
3542
params: { challengeId: challenge.id },
3643
}

frontend/app/graphql/queries/pages/challenges.gql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ query ChallengesPage {
1717
... on ExternalChallenge {
1818
url
1919
}
20+
... on QuizChallenge {
21+
quiz {
22+
userCanStart
23+
}
24+
}
2025
}
2126
}
2227
}

frontend/app/pages/challenges/index.vue

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,36 @@ const { isAuthReady } = useAuthReady()
44
const { data, fetching, error } = useChallengesPageQuery({
55
pause: computed(() => !isAuthReady.value),
66
})
7+
8+
// Filter out completed quiz challenges that can't be retaken
9+
const visibleChallenges = computed(() => {
10+
if (!data.value?.myCurrentProject.challenges) return []
11+
12+
return data.value.myCurrentProject.challenges.filter((challenge) => {
13+
// Hide completed quiz challenges that don't allow retakes
14+
if (challenge.__typename === 'QuizChallenge') {
15+
const isCompleted = !!challenge.userCompletedAt
16+
const canStart = challenge.quiz.userCanStart
17+
// Hide if completed and can't start again
18+
if (isCompleted && !canStart) {
19+
return false
20+
}
21+
}
22+
return true
23+
})
24+
})
725
</script>
826

927
<template>
1028
<PageLayout :title="$t('pages.challenges')">
1129
<LoadingState v-if="fetching" />
1230
<ErrorState v-else-if="error" :error />
1331
<div
14-
v-else-if="data?.myCurrentProject.challenges.length"
32+
v-else-if="visibleChallenges.length"
1533
class="space-y-list-section-gap p-list-outside"
1634
>
1735
<ChallengeCard
18-
v-for="challenge in data.myCurrentProject.challenges"
36+
v-for="challenge in visibleChallenges"
1937
:key="challenge.id"
2038
:challenge
2139
/>

0 commit comments

Comments
 (0)