4848 <cdx-button weight =" quiet" action =" progressive" v-if =" isVoting('ranking')" @click =" saveRanking" >
4949 <content-save-outline style =" font-size : 6px " /> {{ $t('montage-round-save') }}
5050 </cdx-button >
51+
52+ <cdx-button weight =" quiet" action =" default" @click =" gobackToRound" >
53+ <ArrowLeftThick />
54+ <span >Back to Round</span >
55+ </cdx-button >
5156 </div >
5257 <div class =" image-grid" :class =" 'grid-size-' + gridSize" v-if =" !isVoting('ranking')" >
5358 <div v-for =" image in votes" :key =" image.id" class =" gallery-image link" :class =" getImageSizeClass()" >
125130</template >
126131
127132<script setup>
128- import { onMounted , onUnmounted , ref , watch } from ' vue'
133+ import { onMounted , onUnmounted , ref , watch } from ' vue'
129134import _ from ' lodash'
130135import { useRouter , useRoute } from ' vue-router'
131136import { useI18n } from ' vue-i18n'
@@ -145,6 +150,10 @@ import { CdxButton, CdxSelect } from '@wikimedia/codex'
145150import { VueDraggableNext as draggable } from ' vue-draggable-next'
146151import ImageReviewDialog from ' ./ImageReviewDialog.vue'
147152
153+ // Services
154+ // import { EventBus } from 'vue-toastification' // Currently depricated
155+ import { onBeforeRouteLeave } from ' vue-router'
156+
148157// Icons
149158import ContentSaveOutline from ' vue-material-design-icons/ContentSaveOutline.vue'
150159import ImageSizeSelectActual from ' vue-material-design-icons/ImageSizeSelectActual.vue'
@@ -155,6 +164,8 @@ import ThumbDown from 'vue-material-design-icons/ThumbDown.vue'
155164import Star from ' vue-material-design-icons/Star.vue'
156165import ArrowExpandAll from ' vue-material-design-icons/ArrowExpandAll.vue'
157166import Heart from ' vue-material-design-icons/Heart.vue'
167+ import ArrowRight from ' vue-material-design-icons/ArrowRight.vue'
168+ import ArrowLeftThick from ' vue-material-design-icons/ArrowLeftThick.vue'
158169
159170// Hooks
160171const { t: $t } = useI18n ()
@@ -358,6 +369,13 @@ watch(locale, (newLocale) => {
358369 dayjs .locale (newLocale)
359370})
360371
372+ const beforeUnloadListner = (event ) => {
373+ if (edits .value .length ){
374+ event .preventDefault ()
375+ event .returnValue = " " ;
376+ }
377+ };
378+
361379onMounted (() => {
362380 getRoundDetails (voteId)
363381 getPastVotes (voteId)
@@ -368,13 +386,30 @@ onMounted(() => {
368386
369387 handleResize ()
370388 window .addEventListener (' resize' , handleResize)
389+ window .addEventListener (' beforeunload' ,beforeUnloadListner)
390+ })
391+
392+ const gobackToRound = () => {
393+ router .push (` /vote/${ round .value .link } ` )
394+ }
395+
396+ onBeforeRouteLeave ((to ,from ,next )=> {
397+ if (edits .value .length ) {
398+ if (confirm (" There are unsaved changes. Are you sure you want to leave?" )) {
399+ next ()
400+ } else {
401+ next (false )
402+ }
403+ } else {
404+ next ()
405+ }
371406})
372407
373408onUnmounted (() => {
374409 if (editVoteContainer .value ) {
375410 editVoteContainer .value .removeEventListener (' scroll' , handleScroll)
376411 }
377-
412+ window . removeEventListener ( ' beforeunload ' ,beforeUnloadListner)
378413 window .removeEventListener (' resize' , handleResize)
379414})
380415 </script >
0 commit comments