mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 23:16:17 -05:00
app: status and settings contexts say whether their first poll landed (#734)
Both contexts start as {} and nothing distinguished that from a
server that reported nothing, so for up to one poll interval after a
page load consumers rendered the negative case as fact: the Settings
form appeared with blank values and an "undefined/config/wrolpi.yaml"
path (the ready check `settings ? true : undefined` was always true),
the Downloads toggle was clickable and read "Downloading Disabled",
the upgrade panel said "up to date, vundefined", and the five hardware
toggles on the Controller page claimed "not supported on this server".
Invariants now enforced and tested:
* StatusContext.loaded is true once a poll returned a real status;
the API being down does not count. SettingsContext.loaded is true
once settings were fetched, and `failed` when a fetch returned
nothing before that; a failed refresh after a load keeps the last
known values and `loaded`.
* The Settings page shows its loader until loaded and its error only
when failed. The upgrade panel shows a loader until status loaded.
The Downloads toggle is disabled with a neutral label until then.
* A subsystem toggle is disabled without claiming "unsupported" while
status is unknown (undefined); "unsupported" (null) is reserved for
a loaded status that lacks the field. A call in flight is unknown,
not unsupported.
The context fixtures declare loaded so existing specs render as
before.
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
306386e801
commit
eead78007d
8 changed files with 235 additions and 25 deletions
|
|
@ -101,8 +101,8 @@ export function ShutdownButton() {
|
|||
</APIButton>
|
||||
}
|
||||
|
||||
function UpgradeSegment() {
|
||||
const {status, fetchStatus} = React.useContext(StatusContext);
|
||||
export function UpgradeSegment() {
|
||||
const {status, fetchStatus, loaded} = React.useContext(StatusContext);
|
||||
const dockerized = useDockerized();
|
||||
const [upgrading, setUpgrading] = React.useState(false);
|
||||
const [checking, setChecking] = React.useState(false);
|
||||
|
|
@ -144,6 +144,14 @@ function UpgradeSegment() {
|
|||
</Panel>;
|
||||
}
|
||||
|
||||
// Nothing is known until the first status poll lands; "up to date" is a claim about the server.
|
||||
if (!loaded) {
|
||||
return <Panel id='upgrade'>
|
||||
<Header as='h3'>System Upgrade</Header>
|
||||
<Loading/>
|
||||
</Panel>;
|
||||
}
|
||||
|
||||
// No update available
|
||||
if (!status?.update_available) {
|
||||
return <Panel id='upgrade'>
|
||||
|
|
@ -325,7 +333,9 @@ export function SettingsPage() {
|
|||
const [isDevMode, setIsDevMode] = React.useState(false);
|
||||
|
||||
// Get current settings from the API.
|
||||
const {settings, saveSettings, fetchSettings} = React.useContext(SettingsContext);
|
||||
const {
|
||||
settings, saveSettings, fetchSettings, loaded: settingsLoaded, failed: settingsFailed,
|
||||
} = React.useContext(SettingsContext);
|
||||
const {status} = React.useContext(StatusContext);
|
||||
// Used to track changes to the settings form between saves/loads.
|
||||
const [state, setState] = React.useState({});
|
||||
|
|
@ -463,7 +473,8 @@ export function SettingsPage() {
|
|||
|
||||
React.useEffect(() => {
|
||||
console.debug('settings changed, replacing state...');
|
||||
setReady(settings ? true : undefined);
|
||||
// true = show the form, false = still loading, undefined = could not fetch.
|
||||
setReady(settingsLoaded ? true : settingsFailed ? undefined : false);
|
||||
setState({
|
||||
// Only these settings can be changed on the SettingsPage.
|
||||
archive_destination: settings.archive_destination,
|
||||
|
|
@ -490,7 +501,7 @@ export function SettingsPage() {
|
|||
playlists_destination: settings.playlists_destination,
|
||||
save_ffprobe_json: settings.save_ffprobe_json,
|
||||
});
|
||||
}, [JSON.stringify(settings)]);
|
||||
}, [JSON.stringify(settings), settingsLoaded, settingsFailed]);
|
||||
|
||||
const handleInputChange = async (name, value) => {
|
||||
setState({...state, [name]: value});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue