mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 23:16:17 -05:00
controller: restore useConfigs and useDownloads
The toggle-hook de-duplication replaced a range of customHooks.js that also contained these two unrelated hooks, breaking the production build. Restored byte-identical from master; exports now match master exactly. Jest missed this because it only compiles what tests import — `npm run build` is what catches a missing export. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
07af0c9f28
commit
61428c8233
1 changed files with 66 additions and 0 deletions
|
|
@ -1024,6 +1024,72 @@ export const useBrowseFiles = () => {
|
||||||
return {browseFiles, openFolders, setOpenFolders, fetchFiles};
|
return {browseFiles, openFolders, setOpenFolders, fetchFiles};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useConfigs = () => {
|
||||||
|
const [configs, setConfigs] = useState(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const fetchConfigs = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
console.log('fetching configs...');
|
||||||
|
try {
|
||||||
|
const data = await getConfigs();
|
||||||
|
setConfigs(data['configs']);
|
||||||
|
console.debug('fetching configs successful');
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore SyntaxError because they happen when the API is down.
|
||||||
|
if (!(e instanceof SyntaxError)) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
setConfigs(undefined);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const importConfig = async (fileName) => {
|
||||||
|
try {
|
||||||
|
await postImportConfig(fileName);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const saveConfig = async (fileName) => {
|
||||||
|
try {
|
||||||
|
await postDumpConfig(fileName);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {configs, loading, fetchConfigs, importConfig, saveConfig}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useDownloads = () => {
|
||||||
|
const [onceDownloads, setOnceDownloads] = useState(null);
|
||||||
|
const [recurringDownloads, setRecurringDownloads] = useState(null);
|
||||||
|
const [pendingOnceDownloads, setPendingOnceDownloads] = useState(null);
|
||||||
|
|
||||||
|
const fetchDownloads = async () => {
|
||||||
|
try {
|
||||||
|
const data = await getDownloads();
|
||||||
|
setOnceDownloads(data['once_downloads']);
|
||||||
|
setRecurringDownloads(data['recurring_downloads']);
|
||||||
|
setPendingOnceDownloads(data['pending_once_downloads']);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
// Display errors.
|
||||||
|
setOnceDownloads(undefined);
|
||||||
|
setRecurringDownloads(undefined);
|
||||||
|
setPendingOnceDownloads(undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useRecurringTimeout(fetchDownloads, 3 * 1000);
|
||||||
|
|
||||||
|
return {onceDownloads, recurringDownloads, pendingOnceDownloads, fetchDownloads}
|
||||||
|
}
|
||||||
|
|
||||||
// Every hardware toggle works the same way: one field of the shared status object
|
// Every hardware toggle works the same way: one field of the shared status object
|
||||||
// says whether the subsystem is on, and starting/stopping it is a Controller call.
|
// says whether the subsystem is on, and starting/stopping it is a Controller call.
|
||||||
// `on` is null when the status is unknown, which the UI renders as unsupported.
|
// `on` is null when the status is unknown, which the UI renders as unsupported.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue