Skip to content

Commit

Permalink
feat: install navigation store + bouton retour dynamique
Browse files Browse the repository at this point in the history
  • Loading branch information
Matteo-OCTO committed Mar 4, 2025
1 parent 2d28e39 commit 202def5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import Header from '@/components/dsfr/Header.vue';
import router from '@/router';
import { RouteCompteName } from '@/router/compte/routeCompteName';
import { useNavigationStore } from '@/store/navigationStore';
import { utilisateurStore } from '@/store/utilisateur';
const appName = "- J'agis";
Expand All @@ -38,6 +39,12 @@
if (title) {
document.title = `${title as string} ${appName}`;
}
const navigationStore = useNavigationStore();
if (from.fullPath) {
navigationStore.addRoute(from.fullPath, from.name as string);
}
const estConnecte = utilisateurStore().utilisateur.id.length > 0;
const onboardingTermine = utilisateurStore().utilisateur.onboardingAEteRealise;
if (estPublique) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/custom/Action/ActionBase.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="action fr-my-1w">
<h1 class="action__titre text--normal fr-mb-2w" v-html="actionBaseViewModel.titreAffiche" />
<h1 class="action__titre text--normal fr-mb-4w" v-html="actionBaseViewModel.titreAffiche" />
<p v-if="actionBaseViewModel.sousTitre" class="fr-text--lg fr-mb-4w" v-html="actionBaseViewModel.sousTitre" />

<slot />
Expand Down
14 changes: 12 additions & 2 deletions src/components/custom/Action/ActionQuizTerminee.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<p class="bravo-encouragement">{{ felicitations ?? scoreViewModel.encouragement }}</p>

<div class="flex flex-center align-items--center gap--small">
<router-link :to="{ name: RouteActionsName.CATALOGUE_ACTION }" class="fr-btn display-block fr-my-0">
Revenir au catalogue
<router-link :to="{ path: dernierePageStore.path }" class="fr-btn display-block fr-my-0">
Revenir {{ labelBouton }}
</router-link>

<button class="fr-btn fr-btn--secondary" @click="recommencerQuiz">Recommencer le quiz</button>
Expand All @@ -43,6 +43,8 @@
import { ScoreActionQuizViewModel } from '@/domaines/quiz/ports/scoreActionQuiz.presenter';
import { RecupererScoreActionQuizUsecase } from '@/domaines/quiz/recupererScoreActionQuiz.usecase';
import { RouteActionsName } from '@/router/actions/routes';
import { RouteThematiquesName } from '@/router/thematiques/routes';
import { useNavigationStore } from '@/store/navigationStore';
import { utilisateurStore } from '@/store/utilisateur';
defineProps<{
Expand All @@ -65,6 +67,14 @@
function recommencerQuiz() {
window.location.reload();
}
const dernierePageStore = useNavigationStore().pagePrecedente;
const labelBouton =
dernierePageStore.name === RouteActionsName.CATALOGUE_ACTION
? 'au catalogue'
: dernierePageStore.name === RouteThematiquesName.THEMATIQUE_V2
? 'à la thématique'
: "à l'accueil";
</script>

<style scoped>
Expand Down
4 changes: 2 additions & 2 deletions src/components/pages/PageAction.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="fr-container fr-mt-3w">
<router-link
:to="{ name: RouteActionsName.CATALOGUE_ACTION }"
:to="{ path: useNavigationStore().pagePrecedente.path }"
class="fr-btn fr-btn--icon-left fr-btn--tertiary-no-outline fr-icon-arrow-left-line fr-pl-0"
>
Retour
Expand Down Expand Up @@ -29,7 +29,7 @@
import { ChargerActionClassiqueUsecase } from '@/domaines/actions/chargerActionClassique.usecase';
import { ChargerActionQuizUsecase } from '@/domaines/actions/chargerActionQuiz.usecase';
import { ActionClassiqueViewModel, ActionQuizzesViewModel } from '@/domaines/actions/ports/action.presenter';
import { RouteActionsName } from '@/router/actions/routes';
import { useNavigationStore } from '@/store/navigationStore';
import { utilisateurStore } from '@/store/utilisateur';
const isLoading = ref<boolean>(false);
Expand Down
15 changes: 15 additions & 0 deletions src/store/navigationStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineStore } from 'pinia';

export const useNavigationStore = defineStore('navigation', {
state: () => ({
pagePrecedente: { path: '', name: '' },
}),
actions: {
addRoute(path: string, name: string) {
this.pagePrecedente = { path, name };
},
},
persist: {
storage: localStorage,
},
});

0 comments on commit 202def5

Please sign in to comment.