|
10 | 10 | import '$lib/i18n.js';
|
11 | 11 | import { isLoading, t } from 'svelte-i18n';
|
12 | 12 | import { submitHeroQuestion, skipSurvey } from '$lib/Surveys/surveyUtils';
|
13 |
| - import { surveyStore, showSurveyModal } from '$stores/surveyStore'; |
| 13 | + import { surveyStore, showSurveyModal, markSurveyAnswered } from '$stores/surveyStore'; |
14 | 14 | import { getUserId } from '$lib/utils/user';
|
15 | 15 | import HeroQuestion from '$components/surveys/HeroQuestion.svelte';
|
16 | 16 | import analytics from '$lib/Analytics/PlausibleAnalytics';
|
|
37 | 37 |
|
38 | 38 | let interval = null;
|
39 | 39 | let currentStopSurvey = $state(null);
|
| 40 | + let remainingSurveyQuestions = $state([]); |
40 | 41 |
|
41 | 42 | async function loadData(stopID) {
|
42 | 43 | loading = true;
|
|
102 | 103 | let surveyPublicIdentifier = $state(null);
|
103 | 104 | let showHeroQuestion = $state(true);
|
104 | 105 |
|
105 |
| - async function handleNext() { |
| 106 | + async function handleSurveyButtonClick() { |
106 | 107 | let heroQuestion = currentStopSurvey.questions[0];
|
107 |
| -
|
| 108 | + remainingSurveyQuestions = currentStopSurvey.questions.slice(1); |
108 | 109 | if (heroQuestion.content.type !== 'label' && (!heroAnswer || heroAnswer.trim() === '')) {
|
109 | 110 | return;
|
110 | 111 | }
|
111 |
| - showSurveyModal.set(true); |
| 112 | +
|
| 113 | + // If there are more questions, show the modal |
| 114 | + if (remainingSurveyQuestions.length > 0) { |
| 115 | + showSurveyModal.set(true); |
| 116 | + } |
112 | 117 | nextSurveyQuestion = true;
|
113 | 118 |
|
114 | 119 | let surveyResponse = {
|
|
129 | 134 |
|
130 | 135 | surveyPublicIdentifier = await submitHeroQuestion(surveyResponse);
|
131 | 136 | showHeroQuestion = false;
|
| 137 | +
|
| 138 | + markSurveyAnswered(currentStopSurvey.id); |
132 | 139 | }
|
133 | 140 |
|
134 | 141 | function handleSkip() {
|
|
183 | 190 | {/if}
|
184 | 191 |
|
185 | 192 | {#if showHeroQuestion && currentStopSurvey}
|
186 |
| - <HeroQuestion {currentStopSurvey} {handleSkip} {handleNext} {handleHeroQuestionChange} /> |
| 193 | + <HeroQuestion |
| 194 | + {currentStopSurvey} |
| 195 | + {handleSkip} |
| 196 | + {handleSurveyButtonClick} |
| 197 | + {handleHeroQuestionChange} |
| 198 | + remainingQuestionsLength={remainingSurveyQuestions.length} |
| 199 | + /> |
187 | 200 | {/if}
|
188 | 201 | {#if nextSurveyQuestion}
|
189 | 202 | <SurveyModal
|
|
0 commit comments