Skip to content

Commit

Permalink
feat(store): add app store, set app theme
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov committed Apr 6, 2022
1 parent a27b042 commit a48d439
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/renderer/App.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
<template>
<div data-theme="light">
<div class="app-title-bar" />
<RouterView />
</div>
<div class="app-title-bar" />
<RouterView />
</template>

<script setup lang="ts">
import router from '@/router'
import { watch } from 'vue'
import { useAppStore } from './store/app'
// По какой то причине необходимо явно установить роут в '/'
// для корректного поведения в продакшен сборке
// TODO: выяснить причину
router.push('/')
const appStore = useAppStore()
const setTheme = (theme: string) => {
document.body.dataset.theme = theme
}
watch(
() => appStore.theme,
() => setTheme(appStore.theme),
{ immediate: true }
)
</script>

<style lang="scss">
Expand Down
9 changes: 9 additions & 0 deletions src/renderer/store/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { State } from '@shared/types/renderer/store/app'
import { defineStore } from 'pinia'

export const useAppStore = defineStore('app', {
state: () =>
({
theme: 'light'
} as State)
})
3 changes: 3 additions & 0 deletions src/shared/types/renderer/store/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface State {
theme: string
}

0 comments on commit a48d439

Please sign in to comment.