Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
feat: reset stores (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjent authored Apr 30, 2024
1 parent 198f431 commit 21b329f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 53 deletions.
25 changes: 21 additions & 4 deletions components/TheHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import { ref } from "vue";
import { storeToRefs } from "pinia";
import {
ArrowUpOnSquareIcon,
ArrowDownOnSquareIcon,
ArrowUpOnSquareIcon,
ArrowPathIcon,
} from "@heroicons/vue/24/outline";
import { useEditorStore } from "@/stores/editor";
import { useLetterStore } from "@/stores/letter";
Expand All @@ -20,9 +21,12 @@ const { documentType, zoomLevel } = storeToRefs(useEditorStore());
const { template } = storeToRefs(useProfileStore());
const profile = storeToRefs(useProfileStore());
const letter = storeToRefs(useLetterStore());
const resume = storeToRefs(useResumeStore());
const profileStore = useProfileStore();
const profile = storeToRefs(profileStore);
const letterStore = useLetterStore();
const letter = storeToRefs(letterStore);
const resumeStore = useResumeStore();
const resume = storeToRefs(resumeStore);
const isImportError = ref(false);
Expand Down Expand Up @@ -93,6 +97,12 @@ function importFromJson(event: Event) {
isImportError.value = true;
}
}
function resetStores() {
profileStore.$reset();
letterStore.$reset();
resumeStore.$reset();
}
</script>

<template>
Expand All @@ -110,6 +120,13 @@ function importFromJson(event: Event) {
</h1>
</NuxtLink>
<div class="flex items-end gap-8 h-[60%]">
<button
class="text-blue-500 flex items-center gap-1"
@click="resetStores"
>
<ArrowPathIcon class="h-6" />
Reset
</button>
<div>
<label
for="editorFileReader"
Expand Down
23 changes: 8 additions & 15 deletions stores/letter.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { ref } from "vue";
import { defineStore } from "pinia";

// @ts-expect-error - TS error with "state: () => {}" syntax
// Use option API to take advantage of automatic persistence
// @ts-expect-error - TS does not handle option API syntax
export const useLetterStore = defineStore("letter", {
state: () => {
const recipientDetails = ref<string[]>([]);
const subject = ref("");
const reference = ref("");
const paragraphs = ref<string[]>([]);

return {
paragraphs,
recipientDetails,
reference,
subject,
};
},
state: () => ({
paragraphs: [] as string[],
recipientDetails: [] as string[],
reference: "",
subject: "",
}),
persist: true,
});
28 changes: 9 additions & 19 deletions stores/profile.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
import { ref } from "vue";
import { defineStore } from "pinia";
import type { Template } from "@/types";
import { templateColors, templates } from "@/globals";

// @ts-expect-error - TS error with "state: () => {}" syntax
// Use option API to take advantage of automatic persistence
// @ts-expect-error - TS does not handle option API syntax
export const useProfileStore = defineStore("profile", {
state: () => {
const template = ref<Template>(templates[0]);

const name = ref("");
const title = ref("");

const isThemeCustomized = ref(false);
const colors = ref(templateColors[template.value]);

return {
colors,
isThemeCustomized,
name,
template,
title,
};
},
state: () => ({
colors: templateColors[templates[0]],
isThemeCustomized: false,
name: "",
template: templates[0] as Template,
title: "",
}),
persist: true,
});
23 changes: 8 additions & 15 deletions stores/resume.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import { ref } from "vue";
import { defineStore } from "pinia";
import type { Category, Detail, Link } from "@/types";

// @ts-expect-error - TS error with "state: () => {}" syntax
// Use option API to take advantage of automatic persistence
// @ts-expect-error - TS does not handle option API syntax
export const useResumeStore = defineStore("resume", {
state: () => {
const about = ref("");
const contactDetails = ref<Detail[]>([]);
const socialLinks = ref<Link[]>([]);
const categories = ref<Category[]>([]);

return {
about,
categories,
contactDetails,
socialLinks,
};
},
state: () => ({
about: "",
categories: [] as Category[],
contactDetails: [] as Detail[],
socialLinks: [] as Link[],
}),
persist: true,
});

0 comments on commit 21b329f

Please sign in to comment.