fix: restore current page after refresh
This commit is contained in:
+24
-7
@@ -6,7 +6,7 @@ import {
|
||||
Settings, Trash2, X, Repeat2,
|
||||
} from 'lucide-vue-next'
|
||||
import { buildTaskRrule, defaultTaskDueAt, filterTasks, fromDateTimeLocal, groupTaskTree, moveItemWithinScope, parseTaskRrule, renderMarkdown, toDateTimeLocal, type TaskRepeatConfig } from './lib/task-utils'
|
||||
import { defaultView, isTaskView, nextTotalAfterLocalTaskAdd, readStoredBoolean, shouldToggleRowSwipe, writeCountdownCache, writeStoredBoolean } from './lib/mvp-utils'
|
||||
import { isTaskView, nextTotalAfterLocalTaskAdd, readStoredBoolean, readStoredNavigation, shouldToggleRowSwipe, writeCountdownCache, writeStoredBoolean, writeStoredNavigation } from './lib/mvp-utils'
|
||||
import { csrfHeader } from './lib/csrf'
|
||||
import MvpPanel from './MvpPanel.vue'
|
||||
import CountdownPanel from './CountdownPanel.vue'
|
||||
@@ -30,8 +30,10 @@ const archivedLists = ref<TaskList[]>([])
|
||||
const tasks = ref<Task[]>([])
|
||||
const overdueTasks = ref<Task[]>([])
|
||||
const trash = ref<Task[]>([])
|
||||
const activeList = ref('')
|
||||
const activeView = ref<View>(defaultView())
|
||||
const NAVIGATION_STORAGE_KEY = 'dodo.navigation'
|
||||
const restoredNavigation = readStoredNavigation(window.localStorage, NAVIGATION_STORAGE_KEY)
|
||||
const activeList = ref(restoredNavigation.listId)
|
||||
const activeView = ref<View>(restoredNavigation.view)
|
||||
const selectedTask = ref<Task | null>(null)
|
||||
const query = ref('')
|
||||
const error = ref('')
|
||||
@@ -274,6 +276,20 @@ function toast(message: string) {
|
||||
}
|
||||
function fail(reason: unknown) { error.value = reason instanceof Error ? reason.message : '请求失败' }
|
||||
|
||||
function restoreNavigation(inboxId: string) {
|
||||
if (restoredNavigation.view === 'tasks' && restoredNavigation.listId) {
|
||||
activeList.value = lists.value.some((item) => item.id === restoredNavigation.listId) ? restoredNavigation.listId : inboxId
|
||||
} else {
|
||||
activeList.value = inboxId
|
||||
}
|
||||
}
|
||||
|
||||
async function loadRestoredView() {
|
||||
if (activeView.value === 'trash') await loadTrash()
|
||||
else if (isTaskView(activeView.value)) await loadAll()
|
||||
else { tasks.value = []; totalTasks.value = 0 }
|
||||
}
|
||||
|
||||
async function bootstrap() {
|
||||
authReady.value = false
|
||||
try {
|
||||
@@ -285,11 +301,11 @@ async function bootstrap() {
|
||||
folders.value = data.folders ?? []
|
||||
lists.value = data.lists ?? []
|
||||
navigationLoaded.value = true
|
||||
activeList.value = data.inbox_id || lists.value.find((item: TaskList) => item.is_inbox)?.id || lists.value[0]?.id || ''
|
||||
restoreNavigation(data.inbox_id || lists.value.find((item: TaskList) => item.is_inbox)?.id || lists.value[0]?.id || '')
|
||||
expandedFolders.value = new Set(folders.value.map((folder) => folder.id))
|
||||
await loadArchivedLists()
|
||||
void preloadCountdowns()
|
||||
await loadAll()
|
||||
await loadRestoredView()
|
||||
}
|
||||
} catch {
|
||||
authenticated.value = false
|
||||
@@ -308,10 +324,10 @@ async function submitAuth() {
|
||||
folders.value = data.folders ?? []
|
||||
lists.value = data.lists ?? []
|
||||
navigationLoaded.value = true
|
||||
activeList.value = data.inbox_id || lists.value.find((item: TaskList) => item.is_inbox)?.id || lists.value[0]?.id || ''
|
||||
restoreNavigation(data.inbox_id || lists.value.find((item: TaskList) => item.is_inbox)?.id || lists.value[0]?.id || '')
|
||||
expandedFolders.value = new Set(folders.value.map((folder) => folder.id))
|
||||
void preloadCountdowns()
|
||||
await loadAll()
|
||||
await loadRestoredView()
|
||||
} catch (reason) { fail(reason) }
|
||||
}
|
||||
async function loadTaskPages(path: string) {
|
||||
@@ -393,6 +409,7 @@ async function loadTrash() {
|
||||
async function switchView(view: View, listId?: string) {
|
||||
activeView.value = view
|
||||
if (listId) activeList.value = listId
|
||||
writeStoredNavigation(window.localStorage, NAVIGATION_STORAGE_KEY, view, activeList.value)
|
||||
page.value = 1
|
||||
selectedTask.value = null; mobileSidebar.value = false; mobileDetail.value = false; mobileMore.value = false; taskComposeOpen.value = false
|
||||
if (view === 'trash') await loadTrash()
|
||||
|
||||
Reference in New Issue
Block a user