@@ -10,65 +10,66 @@ import { useI18n } from 'vue-i18n'
1010import BaseMap from ' ./BaseMap.vue'
1111
1212interface Props {
13- tutorial: Tutorial ;
14- options: DefaultOption [];
15- tasks: TutorialTileTask [];
13+ tutorial: Tutorial
14+ options: DefaultOption []
15+ tasks: TutorialTileTask []
1616}
1717
18- const props = defineProps <Props >();
19- const { t } = useI18n ();
18+ const props = defineProps <Props >()
19+ const { t } = useI18n ()
2020
21- const currentTaskIndex = ref (0 );
22- const userAttempts = ref (0 );
23- const answersRevealed = ref (false );
24- const results = ref <Record <string , number >>({});
25- const selectedTasks = ref <Record <string , boolean >>({});
26- const debounceTimeoutRef = shallowRef ();
27- const tileSize = ref (0 );
21+ const currentTaskIndex = ref (0 )
22+ const userAttempts = ref (0 )
23+ const answersRevealed = ref (false )
24+ const results = ref <Record <string , number >>({})
25+ const selectedTasks = ref <Record <string , boolean >>({})
26+ const debounceTimeoutRef = shallowRef ()
27+ const tileSize = ref (0 )
2828
29- const containerRef = useTemplateRef (' container' );
29+ const containerRef = useTemplateRef (' container' )
3030
3131const optionMap = computed (() => {
32- const maxOptionIndex = props .options .length - 1
33-
34- return listToMap (
35- props .options .map ((option , index ) => ({
36- ... option ,
37- nextOptionKey:
38- index === maxOptionIndex ? props .options [0 ].value : props .options [index + 1 ].value ,
39- })),
40- ({ value }) => value ,
41- );
42- });
43-
44- const instruction = computed (
45- () => isDefined (props .tutorial .projectInstruction )
32+ const maxOptionIndex = props .options .length - 1
33+
34+ return listToMap (
35+ props .options .map ((option , index ) => ({
36+ ... option ,
37+ nextOptionKey:
38+ index === maxOptionIndex ? props .options [0 ].value : props .options [index + 1 ].value ,
39+ })),
40+ ({ value }) => value ,
41+ )
42+ })
43+
44+ const instruction = computed (() =>
45+ isDefined (props .tutorial .projectInstruction )
4646 ? props .tutorial .projectInstruction
47- : t (' projectView.youAreLookingFor' , { lookFor: props .tutorial .lookFor })
48- );
47+ : t (' projectView.youAreLookingFor' , { lookFor: props .tutorial .lookFor }),
48+ )
4949
50- const currentScreen = computed (() => (
51- // NOTE: this should be extracted from the `screen` property of current task
52- props .tutorial ?.screens [currentTaskIndex .value ]
53- ));
50+ const currentScreen = computed (
51+ () =>
52+ // NOTE: this should be extracted from the `screen` property of current task
53+ props .tutorial ?.screens [currentTaskIndex .value ],
54+ )
5455
5556const taskList = computed (() => {
5657 if (! props .tasks ) {
5758 return []
5859 }
5960
6061 return props .tasks .filter (({ screen }) => screen === currentTaskIndex .value + 1 )
61- });
62+ })
6263
63- const hasTasks = computed (() => isDefined (props .tasks ) && props .tasks .length !== 0 );
64+ const hasTasks = computed (() => isDefined (props .tasks ) && props .tasks .length !== 0 )
6465const hasCompletedAllTasks = computed (() => {
6566 if (! hasTasks .value ) {
6667 return false
6768 }
6869
6970 const maxIndex = props .tasks .length
7071 return currentTaskIndex .value === maxIndex
71- });
72+ })
7273
7374const answeredCorrectly = computed (() => {
7475 if (props .tasks .length === 0 ) {
@@ -88,14 +89,14 @@ const answeredCorrectly = computed(() => {
8889 )
8990
9091 return ! hasWrongAnswer
91- });
92+ })
9293
9394const alertContent = computed (() => {
9495 if (! currentScreen .value ) {
9596 return undefined
9697 }
9798
98- const { instructions, success, hint } = currentScreen .value ;
99+ const { instructions, success, hint } = currentScreen .value
99100
100101 if (! answersRevealed .value && answeredCorrectly .value && success ) {
101102 const icon = success .icon
@@ -131,35 +132,37 @@ const alertContent = computed(() => {
131132 text: instructions .description ,
132133 icon: icon ? matchIcon (icon ) : undefined ,
133134 }
134- });
135+ })
135136
136- const geoJson = computed (() => (
137- createGeoJsonFromTasks (taskList .value .map ((task ) => ({
138- ... task ,
139- taskZ: props .tutorial .zoomLevel ,
140- }))
141- )));
137+ const geoJson = computed (() =>
138+ createGeoJsonFromTasks (
139+ taskList .value .map ((task ) => ({
140+ ... task ,
141+ taskZ: props .tutorial .zoomLevel ,
142+ })),
143+ ),
144+ )
142145
143- const ROWS_PER_PAGE = 3 ;
144- const COLS_PER_PAGE = 2 ;
146+ const ROWS_PER_PAGE = 3
147+ const COLS_PER_PAGE = 2
145148
146- type GeoJsonProperties = NonNullable <( typeof geoJson .value ) >[' features' ][number ][' properties' ];
149+ type GeoJsonProperties = NonNullable <typeof geoJson .value >[' features' ][number ][' properties' ]
147150
148- const viewportWidth = computed (() => tileSize .value * COLS_PER_PAGE );
149- const viewportHeight = computed (() => tileSize .value * ROWS_PER_PAGE );
151+ const viewportWidth = computed (() => tileSize .value * COLS_PER_PAGE )
152+ const viewportHeight = computed (() => tileSize .value * ROWS_PER_PAGE )
150153
151154const overlayTileServer = computed (() => {
152155 if (isNotDefined (props .tutorial .overlayTileServer )) {
153156 return {
154157 type: ' raster' as const ,
155158 raster: props .tutorial .tileServerB ,
156- } as OverlayTileServer ;
159+ } as OverlayTileServer
157160 }
158161
159- return props .tutorial .overlayTileServer ;
160- });
162+ return props .tutorial .overlayTileServer
163+ })
161164
162- const mapState = computed (() => (
165+ const mapState = computed (() =>
163166 taskList .value .map ((task , i ) => ({
164167 featureId: i + 1 ,
165168 state: [
@@ -172,46 +175,40 @@ const mapState = computed(() => (
172175 value: selectedTasks .value [task .taskId ],
173176 },
174177 ],
175- }))
176- ));
178+ })),
179+ )
177180
178181function handleWindowResize() {
179- window .clearTimeout (debounceTimeoutRef .value );
182+ window .clearTimeout (debounceTimeoutRef .value )
180183 debounceTimeoutRef .value = window .setTimeout (() => {
181184 if (containerRef .value ) {
182- const clientRect = containerRef .value .getBoundingClientRect ();
183- const containerWidth = clientRect .width ;
185+ const clientRect = containerRef .value .getBoundingClientRect ()
186+ const containerWidth = clientRect .width
184187
185- const usableHeight = clientRect .height ;
188+ const usableHeight = clientRect .height
186189
187- const maxTileHeight = Math .floor (usableHeight / ROWS_PER_PAGE );
188- const tentetiveNumTiles = Math .max (
189- 2 ,
190- Math .floor (containerWidth / maxTileHeight ),
191- );
190+ const maxTileHeight = Math .floor (usableHeight / ROWS_PER_PAGE )
191+ const tentetiveNumTiles = Math .max (2 , Math .floor (containerWidth / maxTileHeight ))
192192
193- tileSize .value = Math .min (
194- maxTileHeight ,
195- Math .floor (containerWidth / tentetiveNumTiles ),
196- );
193+ tileSize .value = Math .min (maxTileHeight , Math .floor (containerWidth / tentetiveNumTiles ))
197194 }
198- }, 200 );
195+ }, 200 )
199196}
200197
201198onMounted (() => {
202- window .addEventListener (' resize' , handleWindowResize );
203- handleWindowResize ();
199+ window .addEventListener (' resize' , handleWindowResize )
200+ handleWindowResize ()
204201 results .value = listToMap (
205202 props .tasks ,
206203 ({ taskId }) => taskId ,
207204 () => props .options [0 ].value ,
208- );
209- });
205+ )
206+ })
210207
211208onUnmounted (() => {
212209 window .removeEventListener (' resize' , handleWindowResize )
213- window .clearTimeout (debounceTimeoutRef .value );
214- });
210+ window .clearTimeout (debounceTimeoutRef .value )
211+ })
215212
216213function nextTask() {
217214 if (! hasCompletedAllTasks .value ) {
@@ -251,15 +248,14 @@ function updateResult(taskId: string) {
251248}
252249
253250function handleTaskClick(featureProperties : GeoJsonProperties ) {
254- const { taskId } = featureProperties ;
251+ const { taskId } = featureProperties
255252
256253 const selectedTaskKeys = Object .keys (selectedTasks .value ).filter (
257254 (taskKey ) => !! selectedTasks .value [taskKey ],
258255 )
259256
260257 const hasSomeSelectedItem = selectedTaskKeys .length > 0
261- const isTaskFromSelectedItem =
262- selectedTaskKeys .findIndex ((taskKey ) => taskKey === taskId ) !== - 1
258+ const isTaskFromSelectedItem = selectedTaskKeys .findIndex ((taskKey ) => taskKey === taskId ) !== - 1
263259
264260 if (hasSomeSelectedItem ) {
265261 if (isTaskFromSelectedItem ) {
@@ -274,12 +270,12 @@ function handleTaskClick(featureProperties: GeoJsonProperties) {
274270}
275271
276272function handleTaskContextMenu(featureProperties : GeoJsonProperties ) {
277- const { taskId } = featureProperties ;
273+ const { taskId } = featureProperties
278274
279275 if (isDefined (results .value [taskId ])) {
280- selectedTasks .value [taskId ] = ! selectedTasks .value [taskId ];
276+ selectedTasks .value [taskId ] = ! selectedTasks .value [taskId ]
281277 } else {
282- selectedTasks .value [taskId ] = true ;
278+ selectedTasks .value [taskId ] = true
283279 }
284280}
285281
@@ -304,7 +300,6 @@ export default defineComponent({
304300 },
305301})
306302*/
307-
308303 </script >
309304
310305<template >
@@ -344,10 +339,7 @@ export default defineComponent({
344339 </v-row >
345340 <v-row >
346341 <v-col >
347- <div
348- ref =" container"
349- class =" container"
350- >
342+ <div ref =" container" class =" container" >
351343 <BaseMap
352344 v-if =" isDefined(geoJson) && isDefined(overlayTileServer)"
353345 :geo-json =" geoJson"
0 commit comments