Set queryLabel after query on page first load

This commit is contained in:
yangdx
2025-04-06 14:56:55 +08:00
parent 0defac0e29
commit df0594852a
2 changed files with 31 additions and 15 deletions

View File

@@ -119,6 +119,10 @@ const fetchGraph = async (label: string, maxDepth: number, maxNodes: number) =>
// Continue with graph fetch even if labels fetch fails
}
}
// Trigger GraphLabels component to check if the label is valid
// console.log('Setting labelsFetchAttempted to true');
useGraphStore.getState().setLabelsFetchAttempted(true)
// If label is empty, use default label '*'
const queryLabel = label || '*';
@@ -339,6 +343,7 @@ const useLightrangeGraph = () => {
}
// Only fetch data when graphDataFetchAttempted is false (avoids re-fetching on vite dev mode)
// GraphDataFetchAttempted must set to false when queryLabel is changed
if (!isFetching && !useGraphStore.getState().graphDataFetchAttempted) {
// Set flags
fetchInProgressRef.current = true
@@ -445,6 +450,13 @@ const useLightrangeGraph = () => {
state.setRawGraph(data);
state.setGraphIsEmpty(false);
// ensusre GraphLabels show the current label on first load
const lastSuccessfulQueryLabel = useGraphStore.getState().lastSuccessfulQueryLabel;
if (!lastSuccessfulQueryLabel){
useSettingsStore.getState().setQueryLabel('');
useSettingsStore.getState().setQueryLabel(queryLabel);
console.log('Set queryLabel after query on page first load');
}
// Update last successful query label
state.setLastSuccessfulQueryLabel(currentQueryLabel);