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 @@
+
+
+
+
![card icon]()
+
+
+
+
+
+
+
+
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 @@
-
-
-
![card icon]()
-
-
-
-
-
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 }})
-
+
+ {{ 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
}
}
})