fix(app): file tree not always loading
This commit is contained in:
@@ -8,7 +8,6 @@ import {
|
|||||||
createMemo,
|
createMemo,
|
||||||
For,
|
For,
|
||||||
Match,
|
Match,
|
||||||
onCleanup,
|
|
||||||
Show,
|
Show,
|
||||||
splitProps,
|
splitProps,
|
||||||
Switch,
|
Switch,
|
||||||
@@ -124,28 +123,7 @@ export default function FileTree(props: {
|
|||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
const path = props.path
|
const path = props.path
|
||||||
const state = { cancelled: false, timer: undefined as number | undefined }
|
untrack(() => void file.tree.list(path))
|
||||||
|
|
||||||
const load = (attempt: number) => {
|
|
||||||
if (state.cancelled) return
|
|
||||||
if (file.tree.state(path)?.loaded) return
|
|
||||||
|
|
||||||
void untrack(() => file.tree.list(path)).finally(() => {
|
|
||||||
if (state.cancelled) return
|
|
||||||
if (file.tree.state(path)?.loaded) return
|
|
||||||
if (attempt >= 2) return
|
|
||||||
|
|
||||||
const wait = Math.min(2000, 250 * 2 ** attempt)
|
|
||||||
state.timer = window.setTimeout(() => load(attempt + 1), wait)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
load(0)
|
|
||||||
|
|
||||||
onCleanup(() => {
|
|
||||||
state.cancelled = true
|
|
||||||
if (state.timer !== undefined) clearTimeout(state.timer)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const nodes = createMemo(() => {
|
const nodes = createMemo(() => {
|
||||||
|
|||||||
@@ -1255,34 +1255,18 @@ export default function Page() {
|
|||||||
const wants = isDesktop() ? fileTreeTab() === "changes" : store.mobileTab === "changes"
|
const wants = isDesktop() ? fileTreeTab() === "changes" : store.mobileTab === "changes"
|
||||||
if (!wants) return
|
if (!wants) return
|
||||||
if (sync.data.session_diff[id] !== undefined) return
|
if (sync.data.session_diff[id] !== undefined) return
|
||||||
|
if (sync.status === "loading") return
|
||||||
|
|
||||||
const state = {
|
void sync.session.diff(id)
|
||||||
cancelled: false,
|
})
|
||||||
attempt: 0,
|
|
||||||
timer: undefined as number | undefined,
|
|
||||||
}
|
|
||||||
|
|
||||||
const load = () => {
|
createEffect(() => {
|
||||||
if (state.cancelled) return
|
if (!isDesktop()) return
|
||||||
const pending = sync.session.diff(id)
|
if (!layout.fileTree.opened()) return
|
||||||
if (!pending) return
|
if (sync.status === "loading") return
|
||||||
pending.catch(() => {
|
|
||||||
if (state.cancelled) return
|
|
||||||
const attempt = state.attempt + 1
|
|
||||||
state.attempt = attempt
|
|
||||||
if (attempt > 5) return
|
|
||||||
if (state.timer !== undefined) clearTimeout(state.timer)
|
|
||||||
const wait = Math.min(10000, 250 * 2 ** (attempt - 1))
|
|
||||||
state.timer = window.setTimeout(load, wait)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
load()
|
fileTreeTab()
|
||||||
|
void file.tree.list("")
|
||||||
onCleanup(() => {
|
|
||||||
state.cancelled = true
|
|
||||||
if (state.timer !== undefined) clearTimeout(state.timer)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const autoScroll = createAutoScroll({
|
const autoScroll = createAutoScroll({
|
||||||
|
|||||||
Reference in New Issue
Block a user