Use pinia to persist card settings
Signed-off-by: Pascal Syma <pascal@syma.dev>
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
* text=auto eol=lf
|
* text=auto eol=lf
|
||||||
|
*.lockb binary diff=lockb
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tailwindcss/vite": "^4.0.17",
|
"@tailwindcss/vite": "^4.0.17",
|
||||||
|
"pinia": "^3.0.1",
|
||||||
|
"pinia-plugin-persistedstate": "^4.2.0",
|
||||||
"tailwindcss": "^4.0.17",
|
"tailwindcss": "^4.0.17",
|
||||||
"vue": "^3.5.13"
|
"vue": "^3.5.13"
|
||||||
},
|
},
|
||||||
|
|||||||
+8
-11
@@ -1,16 +1,9 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
|
||||||
import Card from '@/components/card.vue'
|
import Card from '@/components/card.vue'
|
||||||
import { type CardT, type Preset, presets, validPreset } from '@/colors.ts'
|
import { type CardT, type Preset, presets, validPreset } from '@/colors.ts'
|
||||||
|
import { useCards } from '@/stores/cards.ts'
|
||||||
|
|
||||||
const cards = ref<CardT[]>(
|
const cardStore = useCards()
|
||||||
new Array(8).fill(0).map((_) => ({
|
|
||||||
...presets.default,
|
|
||||||
name: 'Name',
|
|
||||||
textSize: 10,
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
|
|
||||||
function presetChange(card: CardT, preset: keyof typeof presets | 'none') {
|
function presetChange(card: CardT, preset: keyof typeof presets | 'none') {
|
||||||
if (!validPreset(preset)) {
|
if (!validPreset(preset)) {
|
||||||
return
|
return
|
||||||
@@ -25,7 +18,11 @@ function presetChange(card: CardT, preset: keyof typeof presets | 'none') {
|
|||||||
<template>
|
<template>
|
||||||
<div class="grid grid-cols-3">
|
<div class="grid grid-cols-3">
|
||||||
<div class="noPrint flex flex-col gap-3 border-r-4 bg-gray-100 mr-4 h-screen overflow-y-auto">
|
<div class="noPrint flex flex-col gap-3 border-r-4 bg-gray-100 mr-4 h-screen overflow-y-auto">
|
||||||
<div v-for="(card, i) in cards" :key="i" class="p-3 bg-gray-300 flex flex-col gap-1 m-2 mr-0">
|
<div
|
||||||
|
v-for="(card, i) in cardStore.cards"
|
||||||
|
:key="i"
|
||||||
|
class="p-3 bg-gray-300 flex flex-col gap-1 m-2 mr-0"
|
||||||
|
>
|
||||||
<input v-model="card.title" placeholder="Title" />
|
<input v-model="card.title" placeholder="Title" />
|
||||||
<div class="flex flex-row gap-2">
|
<div class="flex flex-row gap-2">
|
||||||
<input
|
<input
|
||||||
@@ -74,7 +71,7 @@ function presetChange(card: CardT, preset: keyof typeof presets | 'none') {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-span-2 grid grid-cols-2 page gap-2 h-screen overflow-y-auto">
|
<div class="col-span-2 grid grid-cols-2 page gap-2 h-screen overflow-y-auto">
|
||||||
<card v-for="(_, i) in cards" :key="i" v-model="cards[i]" />
|
<card v-for="(_, i) in cardStore.cards" :key="i" v-model="cardStore.cards[i]" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
+5
-1
@@ -2,5 +2,9 @@ import './assets/main.css'
|
|||||||
|
|
||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
|
import { createPinia } from 'pinia'
|
||||||
|
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
|
||||||
|
|
||||||
createApp(App).mount('#app')
|
const pinia = createPinia()
|
||||||
|
|
||||||
|
createApp(App).use(pinia.use(piniaPluginPersistedstate)).mount('#app')
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import type { CardT } from '@/colors.ts'
|
||||||
|
import { presets } from '@/colors.ts'
|
||||||
|
|
||||||
|
export const useCards = defineStore(
|
||||||
|
'cards',
|
||||||
|
() => {
|
||||||
|
const cards = ref<CardT[]>(
|
||||||
|
new Array(8).fill(0).map((_) => ({
|
||||||
|
...presets.default,
|
||||||
|
name: 'Name',
|
||||||
|
textSize: 10,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
|
||||||
|
return { cards }
|
||||||
|
},
|
||||||
|
{ persist: true },
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user