mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Don't nag git updates so much
This commit is contained in:
1 file changed
+11
-3
@@ -34,6 +34,7 @@ export function useGitFetch(projectId: string | null) {
|
||||
const previousStateRef = useRef<{
|
||||
defaultBranchOid: string | null;
|
||||
currentBranchOid: string | null;
|
||||
dataUpdatedAt: number;
|
||||
} | null>(null);
|
||||
|
||||
const query = useQuery({
|
||||
@@ -300,16 +301,17 @@ export function useGitFetch(projectId: string | null) {
|
||||
|
||||
// Show toast notifications when changes are detected
|
||||
useEffect(() => {
|
||||
if (!query.data || !query.isSuccess) {
|
||||
if (!query.data || !query.isSuccess || query.dataUpdatedAt === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentState = {
|
||||
defaultBranchOid: query.data.defaultBranchOid,
|
||||
currentBranchOid: query.data.currentBranchOid,
|
||||
dataUpdatedAt: query.dataUpdatedAt,
|
||||
};
|
||||
|
||||
// Skip on first load
|
||||
// Initialize on first load or after component remount
|
||||
if (previousStateRef.current === null) {
|
||||
previousStateRef.current = currentState;
|
||||
return;
|
||||
@@ -317,6 +319,12 @@ export function useGitFetch(projectId: string | null) {
|
||||
|
||||
const prevState = previousStateRef.current;
|
||||
|
||||
// Skip if this is the same data we've already seen (same dataUpdatedAt timestamp)
|
||||
// This prevents showing toasts when navigating back to a project with cached data
|
||||
if (prevState.dataUpdatedAt === currentState.dataUpdatedAt) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Detect default branch changes
|
||||
const defaultBranchChanged =
|
||||
prevState.defaultBranchOid !== null &&
|
||||
@@ -356,7 +364,7 @@ export function useGitFetch(projectId: string | null) {
|
||||
|
||||
// Update previous state
|
||||
previousStateRef.current = currentState;
|
||||
}, [query.data, query.isSuccess, toast, queryClient, projectId]);
|
||||
}, [query.data, query.isSuccess, query.dataUpdatedAt, toast, queryClient, projectId]);
|
||||
|
||||
return query;
|
||||
}
|
||||
Reference in new issue
Block a user