From 2062beaefb549127fa7f011b0f60a8ec37d5e531 Mon Sep 17 00:00:00 2001 From: koehr Date: Fri, 3 Jul 2020 14:58:08 +0200 Subject: [PATCH] generalize notifications, popups via teleport, create/edit decks --- src/App.vue | 18 ++++++++-- src/components/Card.vue | 5 +-- src/components/DeckCard.vue | 17 ++++++++++ src/components/DeckForm.vue | 65 +++++++++++++++++++++++++++++++++++++ src/consts.ts | 50 ++++++++++++++++++++++++++++ src/lib/card.ts | 3 +- src/lib/deck.ts | 33 ++++++++++--------- src/state/actions.ts | 38 +++++++++++++++++++--- src/state/index.ts | 3 +- src/storage.ts | 3 +- src/types.ts | 28 ++-------------- src/views/Home.vue | 49 +++++++++++++++++++++++----- 12 files changed, 251 insertions(+), 61 deletions(-) create mode 100644 src/components/DeckCard.vue create mode 100644 src/components/DeckForm.vue create mode 100644 src/consts.ts diff --git a/src/App.vue b/src/App.vue index abf28c3..3fff759 100644 --- a/src/App.vue +++ b/src/App.vue @@ -8,6 +8,11 @@
+ + diff --git a/src/components/DeckForm.vue b/src/components/DeckForm.vue new file mode 100644 index 0000000..6ec76b4 --- /dev/null +++ b/src/components/DeckForm.vue @@ -0,0 +1,65 @@ + + + diff --git a/src/consts.ts b/src/consts.ts new file mode 100644 index 0000000..9799a92 --- /dev/null +++ b/src/consts.ts @@ -0,0 +1,50 @@ +// page width x page height +export const enum PageSize { + A4 = '210mm 297mm', + USLetter = '8.5in 11in', + JISB4 = '182mm 257mm', + A3 = '297mm 420mm', + A5 = '148mm 210mm', + USLegal = '8.5in 14in', + USLedger = '11in 17in', + JISB5 = '257mm 364mm' +} + +// card width x card height +export const enum CardSize { + Poker = '64x89', + Bridge = '57x89' +} + +export const enum Arrangement { + DoubleSided = 'doublesided', + FrontOnly = 'frontonly', + SideBySide = 'sidebyside' +} + + +export const cardSizeOptions = [ + { title: '88x62 (Poker)', value: CardSize.Poker }, + { title: '88x56 (Bridge)', value: CardSize.Bridge } +] + +export const pageSizeOptions = [ + { title: 'A4', value: PageSize.A4 }, // 210mm × 297mm + { title: 'US Letter', value: PageSize.USLetter }, // 8.5in × 11in + { title: 'JIS-B4', value: PageSize.JISB4 }, // 182mm × 257mm + { title: 'A3', value: PageSize.A3 }, // 297mm × 420mm + { title: 'A5', value: PageSize.A5 }, // 148mm × 210mm + { title: 'US Legal', value: PageSize.USLegal }, // 8.5in × 14in + { title: 'US Ledger', value: PageSize.USLedger }, // 11in × 17in + { title: 'JIS-B5', value: PageSize.JISB5 } // 257mm × 364mm +] + +export const arrangementOptions = [ + { title: 'Double Sided', value: Arrangement.DoubleSided }, + { title: 'Only Front Sides', value: Arrangement.FrontOnly }, + { title: 'Side by Side', value: Arrangement.SideBySide } +] + +export const defaultPageSize = pageSizeOptions[0].value +export const defaultCardSize = cardSizeOptions[0].value +export const defaultArrangement = arrangementOptions[0].value diff --git a/src/lib/card.ts b/src/lib/card.ts index d1c5984..2c780d0 100644 --- a/src/lib/card.ts +++ b/src/lib/card.ts @@ -1,4 +1,5 @@ -import { ICard, CardSize } from '../types' +import { CardSize } from '../consts' +import { ICard } from '../types' export function defaultCard (): ICard { return { diff --git a/src/lib/deck.ts b/src/lib/deck.ts index 687d662..418b470 100644 --- a/src/lib/deck.ts +++ b/src/lib/deck.ts @@ -1,26 +1,29 @@ -import { IDeck, CardSize, PageSize, Arrangement } from '../types' +import { CardSize, PageSize, Arrangement } from '../consts' +import { IDeck } from '../types' + +export const defaultDeckValues: IDeck = { + id: 0, + icon: 'robe', + name: 'the nameless', + description: '', + color: '#3C1C00', + cards: [], + cardSize: CardSize.Poker, + pageSize: PageSize.A4, + arrangement: Arrangement.DoubleSided, + roundedCorners: true +} export function defaultDeck (): IDeck { - return { - id: 0, - icon: 'robe', - name: 'the nameless', - description: '', - color: '#3C1C00', - cards: [], - cardSize: CardSize.Poker, - pageSize: PageSize.A4, - arrangement: Arrangement.DoubleSided, - roundedCorners: true - } + return { ...defaultDeckValues } } export function isValidDeck (deck: any): boolean { - const example = defaultDeck() as { [key: string]: any } + const example = defaultDeckValues as { [key: string]: any } for (const key in example) { const type = typeof example[key] - return typeof deck[key] === type + if (typeof deck[key] !== type) return false } return true diff --git a/src/state/actions.ts b/src/state/actions.ts index 58b39ce..8f20d8c 100644 --- a/src/state/actions.ts +++ b/src/state/actions.ts @@ -1,6 +1,6 @@ import { Ref } from 'vue' import { Notification, IDeck, KV } from '../types' -import { defaultDeck } from '../lib/deck' +import { defaultDeck, defaultDeckValues } from '../lib/deck' /// actions are called like action['sub/foo'](state.sub, payload) export default { @@ -22,7 +22,37 @@ export default { }, // DECK ACTIONS - 'decks/new' (decks: Ref) { - decks.value.push(defaultDeck()) - } + // returns index of newly created deck + 'decks/new' (decks: Ref): number { + const newDeck = defaultDeck() + const id = decks.value.push(newDeck) - 1 + newDeck.id = id + + return id + }, + // updates decks[updatedDeck.id] + 'decks/update' (decks: Ref, updatedDeck: IDeck): boolean { + const id = updatedDeck.id + if (!id || !decks.value[id]) return false // can't update non-existing deck + + decks.value[id] = { + ...decks.value[id], + ...updatedDeck + } + return true + }, + + // POPUP ACTIONS + 'popup/show' (popup: Ref): boolean { + popup.value = true + return popup.value + }, + 'popup/hide' (popup: Ref): boolean { + popup.value = false + return popup.value + }, + 'popup/toggle' (popup: Ref): boolean { + popup.value = !popup.value + return popup.value + }, } diff --git a/src/state/index.ts b/src/state/index.ts index 6ad99fb..4223490 100644 --- a/src/state/index.ts +++ b/src/state/index.ts @@ -9,7 +9,8 @@ const state: State = { settings: ref({}), decks: ref([]), notifications: ref([]), - initialized: ref(false) + icons: ref(['mouth-watering', 'robe', 'thorny-triskelion']), + popup: ref(false) } export function useState (prop: string): { [key: string]: any } { diff --git a/src/storage.ts b/src/storage.ts index 6519ee6..86436f5 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -1,5 +1,6 @@ import Dexie from 'dexie' -import { IDeck, ICard, CardSize, Arrangement, PageSize } from './types' +import { CardSize, Arrangement, PageSize } from './consts' +import { IDeck, ICard } from './types' interface IDeckTable { id: number; diff --git a/src/types.ts b/src/types.ts index a2d5059..8f4b25c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,28 +1,5 @@ import { Ref } from 'vue' - -// page width x page height -export const enum PageSize { - A4 = '210mm 297mm', - USLetter = '8.5in 11in', - JISB4 = '182mm 257mm', - A3 = '297mm 420mm', - A5 = '148mm 210mm', - USLegal = '8.5in 14in', - USLedger = '11in 17in', - JISB5 = '257mm 364mm' -} - -// card width x card height -export const enum CardSize { - Poker = '64x89', - Bridge = '57x89' -} - -export const enum Arrangement { - DoubleSided = 'doublesided', - FrontOnly = 'frontonly', - SideBySide = 'sidebyside' -} +import { PageSize, CardSize, Arrangement } from './consts' export interface KV { [key: string]: V; @@ -82,5 +59,6 @@ export interface State { settings: Ref; decks: Ref; notifications: Ref; - initialized: Ref; + icons: Ref; + popup: Ref; } diff --git a/src/views/Home.vue b/src/views/Home.vue index c2865d2..344e4d1 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -3,32 +3,63 @@
- - - + - +
+ +
+
Create a new deck of cards
+ +
+ You can also + + an existing deck. +
+
+
+