From ed8bcda86d59339fedc6e4aa0fbea60fdab2fb38 Mon Sep 17 00:00:00 2001 From: koehr Date: Wed, 1 Jul 2020 16:24:52 +0200 Subject: [PATCH] list decks and add new ones --- src/components/Card.vue | 71 +++++++++++++++++++++++++++++++++++++ src/components/CardBack.vue | 24 ------------- src/state/actions.ts | 4 +-- src/state/index.ts | 10 +++--- src/views/Home.vue | 18 +++++----- 5 files changed, 88 insertions(+), 39 deletions(-) create mode 100644 src/components/Card.vue delete mode 100644 src/components/CardBack.vue diff --git a/src/components/Card.vue b/src/components/Card.vue new file mode 100644 index 0000000..7e11499 --- /dev/null +++ b/src/components/Card.vue @@ -0,0 +1,71 @@ + + + + + diff --git a/src/components/CardBack.vue b/src/components/CardBack.vue deleted file mode 100644 index 14aa8e3..0000000 --- a/src/components/CardBack.vue +++ /dev/null @@ -1,24 +0,0 @@ - - - diff --git a/src/state/actions.ts b/src/state/actions.ts index ec5beb0..58b39ce 100644 --- a/src/state/actions.ts +++ b/src/state/actions.ts @@ -22,7 +22,7 @@ export default { }, // DECK ACTIONS - 'decks/new' (): IDeck { - return defaultDeck() + 'decks/new' (decks: Ref) { + decks.value.push(defaultDeck()) } } diff --git a/src/state/index.ts b/src/state/index.ts index efee537..6ad99fb 100644 --- a/src/state/index.ts +++ b/src/state/index.ts @@ -1,9 +1,9 @@ import { reactive, ref } from 'vue' import { State, KV } from '../types' import { DeckDB } from '../storage' -import stateActions from './actions' import { defaultDeck } from '../lib/deck' import { defaultCard } from '../lib/card' +import stateActions from './actions' const state: State = { settings: ref({}), @@ -12,11 +12,11 @@ const state: State = { initialized: ref(false) } -export function useState (field: string): { [key: string]: any } { - const collection = ref(state[field]) +export function useState (prop: string): { [key: string]: any } { + const collection = state[prop] const actions = Object.keys(stateActions).reduce((acc, key) => { - if (key.startsWith(`${field}/`)) { - const newKey = key.split('/')[1] + if (key.startsWith(`${prop}/`)) { + const newKey = key.slice(prop.length + 1) acc[newKey] = (payload: KV) => stateActions[key](collection, payload) } return acc diff --git a/src/views/Home.vue b/src/views/Home.vue index dce6542..c2865d2 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -3,11 +3,11 @@
- - {{ deck.name }} ({{ deck.cards.length }}) - + + + - +
@@ -16,17 +16,19 @@ import { defineComponent } from 'vue' import { useState } from '@/state' -import CardBack from '@/components/CardBack.vue' +import Card from '@/components/Card.vue' export default defineComponent({ name: 'Home', - components: { CardBack }, + components: { Card }, setup () { - const { collection: decks, actions } = useState('decks') + const { collection: decks, actions: deckActions } = useState('decks') + return { decks, - newDeck: actions['decks/new'] + // TODO: open popup with Deck settings after creation + newDeck: deckActions.new } } })