From ab73ee6c2e6f86fd8af6ac85cf664847e2c44b85 Mon Sep 17 00:00:00 2001 From: kadiryazici Date: Sun, 22 Oct 2023 17:36:27 +0300 Subject: [PATCH] Add base structure --- .eslintrc.cjs | 2 + src/components/Dialog.vue | 85 +++++++++++++++++++ src/components/PageHeader.vue | 30 +++++++ src/components/SettingItem.vue | 2 +- src/components/SettingsSilentHours.vue | 76 +++++++++++++++++ .../SettingsSilentHoursAddButton.vue | 37 ++++++++ src/components/SettingsSilentHoursItem.vue | 17 ++++ src/composables/useI18n.ts | 5 +- src/pages/SettingsPage.vue | 4 +- src/utils/common.ts | 21 +++-- 10 files changed, 270 insertions(+), 9 deletions(-) create mode 100644 src/components/Dialog.vue create mode 100644 src/components/SettingsSilentHours.vue create mode 100644 src/components/SettingsSilentHoursAddButton.vue create mode 100644 src/components/SettingsSilentHoursItem.vue diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 7bd393b..f563c0a 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -7,6 +7,8 @@ module.exports = { 'vue/v-on-event-hyphenation': 'off', '@typescript-eslint/no-unused-vars': 'error', 'vue/custom-event-name-casing': 'off', + // Breaks vue's multiple script tags + 'import/first': 'off', 'vue/max-attributes-per-line': ['error', { singleline: { max: 1, diff --git a/src/components/Dialog.vue b/src/components/Dialog.vue new file mode 100644 index 0000000..785b10b --- /dev/null +++ b/src/components/Dialog.vue @@ -0,0 +1,85 @@ + + + + + + + diff --git a/src/components/PageHeader.vue b/src/components/PageHeader.vue index 9867319..ccc0078 100644 --- a/src/components/PageHeader.vue +++ b/src/components/PageHeader.vue @@ -1,7 +1,12 @@ + + + + diff --git a/src/components/SettingsSilentHoursAddButton.vue b/src/components/SettingsSilentHoursAddButton.vue new file mode 100644 index 0000000..ece5883 --- /dev/null +++ b/src/components/SettingsSilentHoursAddButton.vue @@ -0,0 +1,37 @@ + + + + + diff --git a/src/components/SettingsSilentHoursItem.vue b/src/components/SettingsSilentHoursItem.vue new file mode 100644 index 0000000..e627d44 --- /dev/null +++ b/src/components/SettingsSilentHoursItem.vue @@ -0,0 +1,17 @@ + + + + + diff --git a/src/composables/useI18n.ts b/src/composables/useI18n.ts index 1136c3c..42c8df4 100644 --- a/src/composables/useI18n.ts +++ b/src/composables/useI18n.ts @@ -1,7 +1,8 @@ -import { createSharedComposable, reactiveComputed } from '@vueuse/core' +import { reactiveComputed } from '@vueuse/core' import { Fragment, customRef, h } from 'vue' import { AppStorage } from '../storage' import { type NotificationReason } from '../constants' +import { singleton } from '../utils/common' export type Locale = 'en' | 'tr' @@ -141,7 +142,7 @@ const tr: typeof en = { const localeMap: Record = { en, tr } -export const useI18n = createSharedComposable(() => { +export const useI18n = singleton(() => { const currentLanguage = customRef((track, trigger) => { let locale: Locale = AppStorage.get('language') diff --git a/src/pages/SettingsPage.vue b/src/pages/SettingsPage.vue index 3c26a14..1051e71 100644 --- a/src/pages/SettingsPage.vue +++ b/src/pages/SettingsPage.vue @@ -22,6 +22,7 @@ import Switch from '../components/Switch.vue' import SettingItem from '../components/SettingItem.vue' import { Page, useRoute } from '../stores/route' import { useI18n } from '../composables/useI18n' +import SettingsSilentHours from '../components/SettingsSilentHours.vue' const route = useRoute() const { t, currentLanguage } = useI18n() @@ -303,6 +304,8 @@ function handleScroll(e: Event) { > + + @@ -313,7 +316,6 @@ function handleScroll(e: Event) { left: 0; top: 0; width: 100%; - height: 100%; display: flex; flex-flow: column nowrap; diff --git a/src/utils/common.ts b/src/utils/common.ts index 6367106..52fed95 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -1,8 +1,19 @@ -import { type Ref, type UnwrapRef } from 'vue' - /** - * Just returns value of passed ref, used for reactivity tracking. + * Used for singleton composable functions + * + * @example + * ```ts + * const fn = singletonFn(() => { + * const state = reactive({ count: 0 }) + * const increment = () => state.count++ + * const decrement = () => state.count-- + * return { state, increment, decrement } + * }) + * + * const { state, increment, decrement } = fn() + * ``` */ -export function trackRef>(ref: T): UnwrapRef { - return ref.value +export function singleton(fn: () => T): () => T { + const context = fn() + return () => context }