Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cleanup #221

Merged
merged 9 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/decks/inbox/components/InboxCardDeclamationsSide.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Declamation, Synonym } from '@akdasa-studios/shlokas-core'
import { onMounted, ref, watch, shallowRef, computed, onBeforeUnmount } from 'vue'
import { CircleProgress, useAudio } from '@/app/decks/inbox'
import { VerseSynonyms } from '@/app/library'
import { useDownloadService, useEnv } from '@/app/shared'
import { useDownloader, useEnv } from '@/app/shared'
import { TutorialSteps, useTutorialStore } from '@/app/tutorial'

/* -------------------------------------------------------------------------- */
Expand All @@ -45,7 +45,7 @@ defineExpose({

const audio = useAudio()
const env = useEnv()
const downloader = useDownloadService()
const downloader = useDownloader()
const tutorial = useTutorialStore()


Expand Down
2 changes: 1 addition & 1 deletion src/app/decks/inbox/components/InboxFlipCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { Declamation, InboxCard, InboxCardType, Verse, VerseImage } from '@akdas
import { toRefs } from 'vue'
import { InboxCardDeclamationsSide, InboxCardSynonymsSide, InboxCardTranslationSide, InboxCardVerseTextSide } from '@/app/decks/inbox'
import FlipCard from '@/app/decks/shared/components/FlipCard.vue'
import { testId } from '@/app/TestId'
import { testId } from '@/app/shared'


/* -------------------------------------------------------------------------- */
Expand Down
3 changes: 1 addition & 2 deletions src/app/decks/inbox/pages/InboxDeckPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@
import { InboxCard, InboxCardMemorized, UpdateVerseStatus, Verse, VerseId } from '@akdasa-studios/shlokas-core'
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar, onIonViewWillEnter, onIonViewDidLeave } from '@ionic/vue'
import { computed, ref, reactive, watch } from 'vue'
import { testId } from '@/app/TestId'
import { testId , useApplication } from '@/app/shared'
import { InboxFlipCard, InboxCardSwipeOverlay, InboxDeckEmpty } from '@/app/decks/inbox'
import { useLibraryCache, useIndexedList, StackedFlipCardsDeck } from '@/app/decks/shared'
import { useTutorialStore, TutorialSteps } from '@/app/tutorial'
import { useApplication } from '@/app/shared'


/* -------------------------------------------------------------------------- */
Expand Down
3 changes: 1 addition & 2 deletions src/app/decks/review/components/ReviewFlipCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@

<script lang="ts" setup>
import { ReviewCard, Verse } from '@akdasa-studios/shlokas-core'

import { testId } from '@/app/TestId'
import { testId } from '@/app/shared'
import { ReviewCardTextSide, ReviewCardTranslationSide, ReviewCardVerseNumberSide } from '@/app/decks/review'
import FlipCard from '@/app/decks/shared/components/FlipCard.vue'

Expand Down
2 changes: 1 addition & 1 deletion src/app/decks/review/pages/ReviewDeckPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const cardsToShow = ref<CardState[]>([])
const swipePopup = reactive<SwipePopup>({ show: false, status: 'none', interval: 0 })
const isEmpty = computed(() => cardsToShow.value.length === 0)
const topCard = useArrayFind(cardsToShow, x => x.index === 0)
const showGradeButtons = computed(() => topCard.value?.flipped && settings.appearanceSettings.gradeButtons)
const showGradeButtons = computed(() => topCard.value?.flipped && settings.appearance.gradeButtons)
const { currentStep } = storeToRefs(tutorial)

let reviewCards: readonly ReviewCard[] = []
Expand Down
2 changes: 1 addition & 1 deletion src/app/decks/shared/components/FlipCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const colorHueRotate = computed(() => getHueRotate())
/* -------------------------------------------------------------------------- */

function getHueRotate() {
if (!settings.appearanceSettings.colorfulCards) { return 0 }
if (!settings.appearance.colorfulCards) { return 0 }
return hasher.hash(props.hueColorHash) % 360
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions src/app/decks/shared/components/VerseTextLines.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import { onMounted, ref } from 'vue'
import { SVGTextLines } from '@akdasa-studios/shlokas-uikit'
import { usePreferredDark } from '@vueuse/core'
import { DarkImage, useDownloadService, useEnv } from '@/app/shared'
import { DarkImage, useDownloader, useEnv } from '@/app/shared'

/* -------------------------------------------------------------------------- */
/* Interface */
Expand All @@ -37,7 +37,7 @@ const props = defineProps<{
/* Dependencies */
/* -------------------------------------------------------------------------- */

const downloadService = useDownloadService()
const downloadService = useDownloader()
const isDark = usePreferredDark()
const env = useEnv()

Expand Down
4 changes: 2 additions & 2 deletions src/app/home/components/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ import {
import { storeToRefs } from 'pinia'
import { useStatisticsStore } from '@/app/statistics'
import { TutorialPlayer, useTutorialStore } from '@/app/tutorial'
import { useSyncTask } from '@/app/shared'
import { useSync } from '@/app/shared'

/* -------------------------------------------------------------------------- */
/* Dependencies */
/* -------------------------------------------------------------------------- */

const statisticsStore = useStatisticsStore()
const tutorialStore = useTutorialStore()
const syncTask = useSyncTask()
const syncTask = useSync()

/* -------------------------------------------------------------------------- */
/* State */
Expand Down
3 changes: 1 addition & 2 deletions src/app/library/components/VersesListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ import { Decks, Verse, VerseStatus } from '@akdasa-studios/shlokas-core'
import { IonItem, IonLabel, IonIcon } from '@ionic/vue'
import { computed } from 'vue'
import { enter, albums } from 'ionicons/icons'
import { go } from '@/app/shared'
import { testId } from '@/app/TestId'
import { go, testId } from '@/app/shared'

/* -------------------------------------------------------------------------- */
/* Interface */
Expand Down
4 changes: 2 additions & 2 deletions src/app/library/pages/LibraryPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const tutorial = useTutorialStore()
const searchQuery = ref('')
const filteredVerses = shallowRef<Verse[]>([])
const verseStatuses = shallowRef<{ [verseId: string]: VerseStatus}>({})
const { localeSettings } = storeToRefs(settings)
const { locale } = storeToRefs(settings)


/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -101,7 +101,7 @@ async function onSearchQueryChanged(value: string) {
const app = application.instance()

// NOTE: assign filteredVerses AFTER verseStatuses are fetched
const languageCode = localeSettings.value.language
const languageCode = locale.value.language
const verses = await app.library.findByContent(new Language(languageCode, languageCode), value)
verseStatuses.value = await app.library.getStatuses(verses.map(x => x.id))
filteredVerses.value = Array.from(verses).sort((a, b) => compareVerseNumber(a.number.value, b.number.value))
Expand Down
4 changes: 4 additions & 0 deletions src/app/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ export { default as AccountSettingsPage } from './pages/AccountPage.vue'
export { default as SettingsPage } from './pages/SettingsPage.vue'
export { default as AppInfoPage } from './pages/AppInfoPage.vue'

// tasks:
export * from './tasks/runSettingsPersistenceTask'
export * from './tasks/runSettingsRestoreTask'

// routes:
export * from './routes/settings'
9 changes: 4 additions & 5 deletions src/app/settings/pages/AccountPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,19 @@ import {
IonHeader, IonPage, IonTitle, IonToolbar, IonLoading, IonIcon, useIonRouter, alertController
} from '@ionic/vue'
import { mail, logoApple, logoGoogle } from 'ionicons/icons'
import { computed, inject } from 'vue'
import { EventEmitter2 } from 'eventemitter2'
import { go, useAuthentication, useSyncTask } from '@/app/shared'
import { computed } from 'vue'
import { go, useAuthentication, useEmitter, useSync } from '@/app/shared'
import { useSettingsStore } from '@/app/settings'

/* -------------------------------------------------------------------------- */
/* Dependencies */
/* -------------------------------------------------------------------------- */

const emitter = inject('emitter') as EventEmitter2
const emitter = useEmitter()
const settings = useSettingsStore()
const auth = useAuthentication()
const router = useIonRouter()
const syncTask = useSyncTask()
const syncTask = useSync()


/* -------------------------------------------------------------------------- */
Expand Down
6 changes: 3 additions & 3 deletions src/app/settings/pages/SettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<ion-item>
<ion-select
v-model="settings.localeSettings.language"
v-model="settings.locale.language"
interface="action-sheet"
placeholder="Language"
data-testid="language"
Expand All @@ -40,15 +40,15 @@

<ion-item>
<ion-toggle
v-model="settings.appearanceSettings.gradeButtons"
v-model="settings.appearance.gradeButtons"
>
{{ $t('settings.gradeButtons') }}
</ion-toggle>
</ion-item>

<ion-item>
<ion-toggle
v-model="settings.appearanceSettings.colorfulCards"
v-model="settings.appearance.colorfulCards"
>
{{ $t('settings.colorfulCards') }}
</ion-toggle>
Expand Down
69 changes: 4 additions & 65 deletions src/app/settings/stores/useSettingsStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineStore } from 'pinia'
import { ref, watch } from 'vue'
import { useDeviceStore } from '@/app/shared'
import { ref } from 'vue'


interface LocaleSettings {
Expand Down Expand Up @@ -31,17 +30,15 @@ interface AuthSettings {


export const useSettingsStore = defineStore('settings', () => {
const storage = useDeviceStore()

/* -------------------------------------------------------------------------- */
/* State */
/* -------------------------------------------------------------------------- */

const localeSettings = ref<LocaleSettings>({
const locale = ref<LocaleSettings>({
language: 'en'
})

const appearanceSettings = ref<AppearanceSettings>({
const appearance = ref<AppearanceSettings>({
gradeButtons: true,
colorfulCards: true
})
Expand All @@ -63,67 +60,9 @@ export const useSettingsStore = defineStore('settings', () => {
expiresAt: 0
})


watch([
localeSettings.value,
appearanceSettings.value,
library.value,
welcome.value,
auth.value
], () => onSettingsChanged())


/* -------------------------------------------------------------------------- */
/* Actions */
/* -------------------------------------------------------------------------- */

async function load() {
const loadedLocale = JSON.parse(await storage.get('locale'))
const loadedAppearance = JSON.parse(await storage.get('appearance'))
const loadedLibrary = JSON.parse(await storage.get('library'))
const loadedWelcome = JSON.parse(await storage.get('welcome'))
const loadedAuth = JSON.parse(await storage.get('auth'))

if (loadedLocale) {
localeSettings.value.language = loadedLocale.language
}
if (loadedAppearance) {
appearanceSettings.value.gradeButtons = loadedAppearance.gradeButtons
appearanceSettings.value.colorfulCards = loadedAppearance.colorfulCards
}
if (loadedLibrary) {
library.value.lastSyncDate = loadedLibrary.lastSyncDate
}
if (loadedWelcome) {
welcome.value.done = loadedWelcome.done
}
if (loadedAuth) {
auth.value.collectionId = loadedAuth.collectionId
auth.value.token = loadedAuth.token
auth.value.sessionId = loadedAuth.sessionId
auth.value.strategy = loadedAuth.strategy
auth.value.refreshedAt = loadedAuth.refreshedAt
auth.value.expiresAt = loadedAuth.expiresAt
}
}


/* -------------------------------------------------------------------------- */
/* Handlers */
/* -------------------------------------------------------------------------- */

async function onSettingsChanged() {
await storage.set('locale', JSON.stringify(localeSettings.value))
await storage.set('appearance', JSON.stringify(appearanceSettings.value))
await storage.set('library', JSON.stringify(library.value))
await storage.set('welcome', JSON.stringify(welcome.value))
await storage.set('auth', JSON.stringify(auth.value))
}


/* -------------------------------------------------------------------------- */
/* Interface */
/* -------------------------------------------------------------------------- */

return { localeSettings, appearanceSettings, library, welcome, load, auth }
return { locale, appearance, library, welcome, auth }
})
54 changes: 54 additions & 0 deletions src/app/settings/tasks/runSettingsPersistenceTask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { storeToRefs } from 'pinia'
import { watch } from 'vue'
import { useDeviceStore, useLogger } from '@/app/shared'
import { useSettingsStore } from '@/app/settings'


/**
* Saves settings state to device storage.
*/
export function runSettingsPersistenceTask() {

/* -------------------------------------------------------------------------- */
/* Dependencies */
/* -------------------------------------------------------------------------- */

const logger = useLogger('settings:persistence')
const settingsStore = useSettingsStore()
const deviceStore = useDeviceStore()

/* -------------------------------------------------------------------------- */
/* State */
/* -------------------------------------------------------------------------- */

const {
locale, appearance, library, welcome, auth
} = storeToRefs(settingsStore)


/* -------------------------------------------------------------------------- */
/* Triggers */
/* -------------------------------------------------------------------------- */

watch([
locale.value,
appearance.value,
library.value,
welcome.value,
auth.value
], onSettingsChanged)


/* -------------------------------------------------------------------------- */
/* Handlers */
/* -------------------------------------------------------------------------- */

async function onSettingsChanged() {
logger.debug('Saving settings state')
await deviceStore.set('locale', JSON.stringify(locale.value))
await deviceStore.set('appearance', JSON.stringify(appearance.value))
await deviceStore.set('library', JSON.stringify(library.value))
await deviceStore.set('welcome', JSON.stringify(welcome.value))
await deviceStore.set('auth', JSON.stringify(auth.value))
}
}
Loading