Skip to content

Commit 5bb2cdc

Browse files
committed
Use pinia for router
1 parent 8ff591e commit 5bb2cdc

File tree

10 files changed

+21
-20
lines changed

10 files changed

+21
-20
lines changed

src/App.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useStore } from './stores/store'
99
import LandingPage from './pages/LandingPage.vue'
1010
import { useInterval } from './composables/useInterval'
1111
import { AppStorage } from './storage'
12-
import { Page, useRoute } from './composables/useRoute'
12+
import { Page, useRoute } from './stores/route'
1313
1414
const store = useStore()
1515
const route = useRoute()
@@ -35,8 +35,8 @@ watchEffect(() => {
3535
<AppSidebar />
3636

3737
<AppScroller>
38-
<HomePage v-if="route.currentPage.value === Page.Home" />
39-
<SettingsPage v-else-if="route.currentPage.value === Page.Settings" />
40-
<LandingPage v-else-if="route.currentPage.value === Page.Landing" />
38+
<HomePage v-if="route.currentPage === Page.Home" />
39+
<SettingsPage v-else-if="route.currentPage === Page.Settings" />
40+
<LandingPage v-else-if="route.currentPage === Page.Landing" />
4141
</AppScroller>
4242
</template>

src/assets/main.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $colors: (
99
switch-bg: var(--gray) var(--gray),
1010
content-bg: rgba(30, 30, 30, .8) rgb(30, 30, 30),
1111
page-header-bg: rgba(43, 43, 43, .6) rgb(43, 43, 43),
12-
popover-bg: rgba(20, 20, 20, .6) rgb(26, 26, 26),
12+
popover-bg: rgba(30, 30, 30, .6) rgb(26, 26, 26),
1313
bottom-bar-bg: rgba(21, 21, 21, 0.2) rgb(21, 21, 21),
1414
sidebar-bg: rgba(50, 50, 50, .75) rgb(50, 50, 50),
1515
app-border: rgb(90, 90, 90) rgb(90, 90, 90),

src/components/AppScroller.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useStore } from '../stores/store'
88
import type { Option } from '../types'
99
import { batchFn } from '../utils/batch'
1010
import { ColorPreference } from '../constants'
11-
import { useRoute } from '../composables/useRoute'
11+
import { useRoute } from '../stores/route'
1212
1313
const store = useStore()
1414
const route = useRoute()
@@ -18,11 +18,11 @@ const focus = batchFn(() => {
1818
scrollView.value?.getElement()?.focus()
1919
})
2020
21-
watch(route.currentPage, focus, { flush: 'post' })
21+
watch(() => route.currentPage, focus, { flush: 'post' })
2222
useTauriEvent('window:hidden', focus)
2323
onMounted(focus)
2424
25-
watch(route.currentPage, () => {
25+
watch(() => route.currentPage, () => {
2626
const element = scrollView.value?.osInstance()?.elements().scrollOffsetElement
2727
if (element)
2828
element.scrollTop = 0
@@ -45,7 +45,7 @@ const options = computedEager<OverlayScrollbarsOptions>(() => ({
4545
tabindex="-1"
4646
class="main"
4747
:class="{
48-
'main-with-padding': route.meta.value.withPadding,
48+
'main-with-padding': route.meta.withPadding,
4949
}"
5050
>
5151
<slot />

src/components/AppSidebar.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { REPO_LINK } from '../constants'
66
import { useStore } from '../stores/store'
77
import { AppStorage } from '../storage'
88
import { useKey } from '../composables/useKey'
9-
import { Page, useRoute } from '../composables/useRoute'
9+
import { Page, useRoute } from '../stores/route'
1010
import { Icons } from './Icons'
1111
import SidebarButton from './SidebarButton.vue'
1212
import Popover from './Popover.vue'
@@ -47,7 +47,7 @@ const moreItems = computed(() => [
4747
4848
useKey('r', () => {
4949
store.fetchNotifications(true)
50-
}, { source: () => route.currentPage.value === Page.Home })
50+
}, { source: () => route.currentPage === Page.Home })
5151
</script>
5252

5353
<template>
@@ -107,7 +107,7 @@ useKey('r', () => {
107107
<SlotRef>
108108
<template #default>
109109
<SidebarButton
110-
:disabled="route.currentPage.value !== Page.Home"
110+
:disabled="route.currentPage !== Page.Home"
111111
@click="store.fetchNotifications(true)"
112112
>
113113
<Icons.Sync16 />

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { AppStorage, cacheStorageFromDisk } from './storage'
1616
import { useStore } from './stores/store'
1717
import { initDevtools } from './utils/initDevtools'
1818
import { useKey } from './composables/useKey'
19-
import { Page, useRoute } from './composables/useRoute'
19+
import { Page, useRoute } from './stores/route'
2020

2121
async function main() {
2222
if (import.meta.env.DEV) {

src/pages/HomePage.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import MenuItems, { menuItem } from '../components/MenuItems.vue'
2020
import { type UseKeyOptions, useKey } from '../composables/useKey'
2121
import { CheckedNotificationProcess, notificationApiMutex } from '../constants'
2222
import { everySome } from '../utils/array'
23-
import { useRoute } from '../composables/useRoute'
23+
import { useRoute } from '../stores/route'
2424
2525
const store = useStore()
2626
const route = useRoute()
2727
28-
if (route.state.value.fetchOnEnter)
28+
if (route.state.fetchOnEnter)
2929
store.fetchNotifications(true)
3030
3131
function handleOpenNotification(thread: Thread) {

src/pages/LandingPage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import EmptyState from '../components/EmptyState.vue'
1313
import { createAuthURL } from '../utils/github'
1414
import { useTimeoutPool } from '../composables/useTimeoutPool'
1515
import { getServerPort } from '../api/app'
16-
import { Page, useRoute } from '../composables/useRoute'
16+
import { Page, useRoute } from '../stores/route'
1717
1818
const store = useStore()
1919
const route = useRoute()

src/pages/SettingsPage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import MenuItems, { menuItem } from '../components/MenuItems.vue'
2020
import Popover from '../components/Popover.vue'
2121
import Switch from '../components/Switch.vue'
2222
import SettingItem from '../components/SettingItem.vue'
23-
import { Page, useRoute } from '../composables/useRoute'
23+
import { Page, useRoute } from '../stores/route'
2424
2525
const route = useRoute()
2626

src/composables/useRoute.ts renamed to src/stores/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { readonly, ref, shallowRef } from 'vue'
2-
import { computedEager, createSharedComposable } from '@vueuse/core'
2+
import { computedEager } from '@vueuse/core'
3+
import { defineStore } from 'pinia'
34
import { type Option } from '../types'
45

56
export enum Page {
@@ -22,7 +23,7 @@ const metaMap = {
2223
[Page.Landing]: {},
2324
}
2425

25-
export const useRoute = createSharedComposable(() => {
26+
export const useRoute = defineStore('route', () => {
2627
const currentPage = ref(Page.Landing)
2728
const pageFrom = ref<Option<Page>>(null)
2829
const state = shallowRef<PageState>({})

src/stores/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { CheckedNotificationProcess, ColorPreference, InvokeCommand, notificatio
1111
import { AppStorage } from '../storage'
1212
import type { NotificationList, Option } from '../types'
1313
import { filterNewThreads, isRepository, isThread, toNotificationList } from '../utils/notification'
14-
import { Page, useRoute } from '../composables/useRoute'
14+
import { Page, useRoute } from '../stores/route'
1515

1616
export const useStore = defineStore('store', () => {
1717
const notifications = shallowRef<NotificationList>([])

0 commit comments

Comments
 (0)