Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 50x 8x 8x 8x 8x 8x 8x 8x | /**
* LanguageDataRefresh — drops the cached data a language switch invalidates.
*
* A label is translated by the dictionary, which the store applies as soon as the
* language changes. A record's name is not: it is translated by the query that
* reads it, in the language the read asked for (`D-635`). After a switch every
* cached row and every cached dropdown option still holds the previous language,
* so both are dropped here and read again — a dropdown is never translated in
* the browser, it is refetched.
*
* Mounted inside `BlongProvider`, which is where the query client lives. The first
* render is skipped: the caches are empty, and the initial load is what fills them.
*/
import {useQueryClient} from '@tanstack/react-query';
import React from 'react';
import {dropdownRegistry} from '../../model/dropdownRegistry.js';
import {useAppStore} from '../../state/appStore.js';
export function LanguageDataRefresh() {
const language = useAppStore(s => s.language);
const queryClient = useQueryClient();
const mountedRef = React.useRef(false);
React.useEffect(() => {
Eif (!mountedRef.current) {
mountedRef.current = true;
return;
}
dropdownRegistry.clear();
void queryClient.invalidateQueries();
}, [language, queryClient]);
return null;
}
|