-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Persistent cache #3721
base: main
Are you sure you want to change the base?
feat: Persistent cache #3721
Changes from all commits
3e74d49
181f08e
462f1e2
a260088
55240bd
5735d04
e3f4dce
3b6bda0
acbf83e
c3c3882
6db2343
77eef05
889f9b1
b4a773e
fb5b149
80ad810
3f5be5f
32cf049
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import { | |
SidebarMenuItem, | ||
} from './common'; | ||
import { AuthTriggersType } from '../../lib/auth'; | ||
import { TextPlaceholder } from '../widgets/common'; | ||
|
||
export interface SectionCommonProps | ||
extends Pick<ItemInnerProps, 'shouldShowLabel'> { | ||
|
@@ -24,8 +25,32 @@ interface SectionProps extends SectionCommonProps { | |
title?: string; | ||
items: SidebarMenuItem[]; | ||
isItemsButton: boolean; | ||
isLoading?: boolean; | ||
} | ||
|
||
const ItemsSkeleton = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created a quick loading animation for the squad section in the sidebar, as squads may not always be loaded at render time There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably good to check how many squads the average normal user has to avoid shifts for the mass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did a query on db, looks like only ~10.000 has more then 5, so probably not bad default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. found a better query, i think select count(*) from public.user u where (select count(1) from source_member sm where sm."userId" = u.id) > 5 9,009 and more then 1 is 55,435 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so probably 1 is the best 😆 |
||
return ( | ||
<> | ||
<div className="flex items-center"> | ||
<TextPlaceholder className="m-3 h-5 w-5 rounded-full" /> | ||
<TextPlaceholder className="w-[40%]" /> | ||
</div> | ||
<div className="flex items-center"> | ||
<TextPlaceholder className="m-3 h-5 w-5 rounded-full" /> | ||
<TextPlaceholder className="w-[40%]" /> | ||
</div> | ||
<div className="flex items-center"> | ||
<TextPlaceholder className="m-3 h-5 w-5 rounded-full" /> | ||
<TextPlaceholder className="w-[40%]" /> | ||
</div> | ||
<div className="flex items-center"> | ||
<TextPlaceholder className="m-3 h-5 w-5 rounded-full" /> | ||
<TextPlaceholder className="w-[40%]" /> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export function Section({ | ||
title, | ||
items, | ||
|
@@ -35,6 +60,7 @@ export function Section({ | |
activePage, | ||
isItemsButton, | ||
className, | ||
isLoading, | ||
}: SectionProps): ReactElement { | ||
const { user, showLogin } = useContext(AuthContext); | ||
|
||
|
@@ -57,6 +83,7 @@ export function Section({ | |
{title} | ||
</NavHeader> | ||
)} | ||
{isLoading && <ItemsSkeleton />} | ||
{items.filter(mobileItemsFilter).map((item) => ( | ||
<NavItem | ||
key={`${item.title}-${item.path}`} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query'; | |
import { ClientError } from 'graphql-request'; | ||
import { useContext } from 'react'; | ||
import { Squad } from '../../graphql/sources'; | ||
import { getSquad } from '../../graphql/squads'; | ||
import { getSquad, getSquads } from '../../graphql/squads'; | ||
import { ApiError, ApiErrorResult, getApiError } from '../../graphql/common'; | ||
import AuthContext from '../../contexts/AuthContext'; | ||
import { isNullOrUndefined } from '../../lib/func'; | ||
|
@@ -41,3 +41,24 @@ export const useSquad = ({ handle }: UseSquadProps): UseSquad => { | |
: !!getApiError(error as ApiErrorResult, ApiError.Forbidden), | ||
}; | ||
}; | ||
|
||
type UseSquads = { | ||
squads: Squad[]; | ||
isLoading: boolean; | ||
}; | ||
|
||
export const useSquads = (): UseSquads => { | ||
const { isFetched: isBootFetched, user } = useContext(AuthContext); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we care if boot is fetched? |
||
|
||
const { data: squads, isLoading } = useQuery( | ||
[RequestKey.Squads], | ||
() => getSquads(user?.id), | ||
{ | ||
enabled: isBootFetched && !!user, | ||
}, | ||
); | ||
Comment on lines
+53
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing I noticed is that if I create a new squad on another device, or another tab not sharing local storage the cache will never be updated, probably only after stale time goes by. It should always invalidate in the bg I think. |
||
return { | ||
squads, | ||
isLoading, | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will conflict with: #3718
Just to note we might have to choose how to release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, also looking at your comments in that PR, I will have to change some syntax here too when it comes to queryKeys and queryFns