mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 10:24:05 +00:00
fix(settings): the desktop photo provider badge follows the live status check
On the desktop, the Immich (or Synology) card could show "Connected" for a server that was down. The settings page loads two answers at once: the saved settings, whose connected flag for Immich only says that a URL and an API key are stored, and the status route, which actually reaches the server. Whichever landed last set the badge. usePhotoProviderConnections had a statusRouteOwnsBadge option that only the phone turned on. The option is gone: whenever a provider declares a status route, only that route sets the badge, on both views. A provider without a status route still takes the badge from its settings read. Regression test FE-COMP-PHOTOPROVIDERS-028 (PhotoProvidersSection.test.tsx) was red on the old code: "Unable to find an element with the text: Not connected" (the late settings read had turned the badge to Connected). Changed assertions: - usePhotoProviderConnections.test.ts FE-COMP-PHOTOCONN-005: it expected the later settings read (connected: false) to override the status route's connected: true; it now checks that a provider without a status route takes the badge from the settings read. - usePhotoProviderConnections.test.ts: render() no longer takes the option, so every call drops its true or false argument.
This commit is contained in:
@@ -49,22 +49,13 @@ export const getProviderFields = (provider: PhotoProviderAddon): ProviderField[]
|
||||
return [...(provider.fields || [])].sort((a, b) => a.sort_order - b.sort_order);
|
||||
};
|
||||
|
||||
export interface PhotoProviderConnectionOptions {
|
||||
/**
|
||||
* When the provider has a status route, let only that route set the badge and
|
||||
* ignore the `connected` flag of the settings read, so the two responses cannot
|
||||
* race. The phone does this; the desktop takes whichever answer lands last.
|
||||
*/
|
||||
statusRouteOwnsBadge: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* The photo provider connection cards behind both settings shells: every enabled
|
||||
* photo_provider addon with its declared fields, seeded and hydrated values
|
||||
* (secrets never prefilled), the connection badge, and save and test. The desktop
|
||||
* section and its phone twin render their own markup over this.
|
||||
*/
|
||||
export function usePhotoProviderConnections({ statusRouteOwnsBadge }: PhotoProviderConnectionOptions) {
|
||||
export function usePhotoProviderConnections() {
|
||||
const { t } = useTranslation();
|
||||
const toast = useToast();
|
||||
const { isEnabled: addonEnabled, addons } = useAddonStore();
|
||||
@@ -156,7 +147,10 @@ export function usePhotoProviderConnections({ statusRouteOwnsBadge }: PhotoProvi
|
||||
...prev,
|
||||
[provider.id]: { ...(prev[provider.id] || {}), ...nextValues },
|
||||
}));
|
||||
if (!(statusRouteOwnsBadge && cfg.status_get) && typeof res.data?.connected === 'boolean') {
|
||||
// A provider with a status route lets only that route set the badge: the settings
|
||||
// read can only say credentials are stored, and taking whichever of the two answers
|
||||
// lands last would show an unreachable server as connected.
|
||||
if (!cfg.status_get && typeof res.data?.connected === 'boolean') {
|
||||
setProviderConnected((prev) => ({ ...prev, [provider.id]: !!res.data.connected }));
|
||||
}
|
||||
})
|
||||
@@ -169,7 +163,7 @@ export function usePhotoProviderConnections({ statusRouteOwnsBadge }: PhotoProvi
|
||||
return () => {
|
||||
isCancelled = true;
|
||||
};
|
||||
}, [activePhotoProviders, activeProviderSignature, statusRouteOwnsBadge]);
|
||||
}, [activePhotoProviders, activeProviderSignature]);
|
||||
|
||||
const handleProviderFieldChange = (providerId: string, key: string, value: string) => {
|
||||
setProviderValues((prev) => ({
|
||||
|
||||
Reference in New Issue
Block a user