Dont revalidate shortcuts on focus to reduce flicker

This commit is contained in:
Jackson Harper 2024-06-25 09:24:51 +08:00
parent 613dd39aba
commit c3ae9e7ac6
4 changed files with 6 additions and 5 deletions

View file

@ -75,7 +75,6 @@ export function HomeContainer(): JSX.Element {
>
{homeData.sections?.map((homeSection, idx) => {
if (homeSection.items.length < 1) {
console.log('empty home section: ', homeSection)
return <SpanBox key={`section-${idx}`}></SpanBox>
}
switch (homeSection.layout) {
@ -224,7 +223,6 @@ const TopPicksHomeSection = (props: HomeSectionProps): JSX.Element => {
items?: HomeItem[]
}
) => {
console.log('handling action: ', action)
switch (action.type) {
case 'RESET':
return action.items ?? []

View file

@ -185,6 +185,8 @@ const Shortcuts = (props: LibraryFilterMenuProps): JSX.Element => {
initialValue: [],
})
console.log('got shortcuts: ', shortcuts)
// const shortcuts: Shortcut[] = [
// {
// id: '12asdfasdf',

View file

@ -375,6 +375,7 @@ async function setShortcuts(
async function resetShortcuts(path: string): Promise<Shortcut[]> {
const url = new URL(path, fetchEndpoint)
console.log('resetting shortcuts')
try {
const response = await fetch(url.toString(), {
method: 'DELETE',
@ -399,10 +400,12 @@ async function resetShortcuts(path: string): Promise<Shortcut[]> {
const cachedShortcutsData = (): Shortcut[] | undefined => {
if (typeof localStorage !== 'undefined') {
const str = localStorage.getItem('/api/shortcuts')
console.log('cached shortcuts: ', str)
if (str) {
return JSON.parse(str) as Shortcut[]
}
}
console.log('undefined shortcuts')
return undefined
}
@ -411,6 +414,7 @@ const ShortcutsTree = (props: ShortcutsTreeProps): JSX.Element => {
const { ref, width, height } = useResizeObserver()
const { isValidating, data } = useSWR('/api/shortcuts', getShortcuts, {
revalidateOnFocus: false,
fallbackData: cachedShortcutsData(),
onSuccess(data) {
localStorage.setItem('/api/shortcuts', JSON.stringify(data))

View file

@ -147,8 +147,6 @@ export function useGetHomeItems(): HomeItemResponse {
}
const result = data as HomeResult
console.log('result: ', result)
if (result && result.home.errorCodes) {
const errorCodes = result.home.errorCodes
return {
@ -159,7 +157,6 @@ export function useGetHomeItems(): HomeItemResponse {
}
if (result && result.home && result.home.edges) {
console.log('data', result.home)
return {
mutate,
error: false,