Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions webapp/src/components/profile/ProfileSettingsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import BaseButton from "../ui/BaseButton.vue";
import FormField from "../ui/FormField.vue";
import BaseInput from "../ui/BaseInput.vue";
import { useToast } from "../../composables/useToast";
import { useAdsStore } from "../../stores/adsStore.ts";
import { useAdsStore } from "../../stores/adsStore";

const router = useRouter();
const authStore = useAuthStore();
Expand Down Expand Up @@ -174,9 +174,8 @@ onMounted(() => {
<label class="toggle-switch">
<input
type="checkbox"
:checked="adsStore.isEnabled"
v-model="adsStore.isEnabled"
aria-label="Afficher les publicités"
@change="adsStore.toggle"
/>
<span class="toggle-track">
<span class="toggle-thumb"></span>
Expand Down
16 changes: 7 additions & 9 deletions webapp/src/stores/adsStore.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import { ref, watch } from "vue";

const STORAGE_KEY = "display-ads";

export const useAdsStore = defineStore("ads", () => {
const isEnabled = ref(localStorage.getItem(STORAGE_KEY) !== "false");
const isEnabled = ref(localStorage.getItem(STORAGE_KEY) === "true");

watch(isEnabled, (value) => {
localStorage.setItem(STORAGE_KEY, String(value));
});

const enable = () => {
isEnabled.value = true;
localStorage.setItem(STORAGE_KEY, "true");
};

const disable = () => {
isEnabled.value = false;
localStorage.setItem(STORAGE_KEY, "false");
};

const toggle = () => {
if (isEnabled.value) {
disable();
} else {
enable();
}
isEnabled.value = !isEnabled.value;
};

return {
Expand Down
Loading