refactor(directory): use constants to adapt github actions

This commit is contained in:
Haoyu Xu
2023-08-23 19:29:23 +08:00
parent a02239c46d
commit ecd7cbc921
6 changed files with 23 additions and 79 deletions

View File

@@ -1,19 +0,0 @@
import { useCallback } from 'react';
import { atom, useAtom } from 'jotai';
const backgroundsAtom = atom([]);
export function useBackgrounds() {
const [backgrounds, setBackgrounds] = useAtom(backgroundsAtom);
const fetchBackgrounds = useCallback(async () => {
const res = await fetch('/_assets/backgrounds.json')
const data = await res.json()
setBackgrounds(data)
}, [setBackgrounds])
return {
backgrounds,
fetchBackgrounds
};
}

View File

@@ -1,31 +1,14 @@
import { useCallback } from 'react';
import { atom, useAtom } from 'jotai';
import CONFIG from '#/directory.json';
const configAtom = atom([]);
const operatorsAtom = atom([]);
const versionAtom = atom({});
let operators = []
CONFIG.operators.forEach((item) => {
operators = [...operators, ...item]
});
const OPERATORS = operators;
export function useConfig() {
const [config, setConfig] = useAtom(configAtom);
const [version, setVersion] = useAtom(versionAtom);
const [operators, setOperators] = useAtom(operatorsAtom);
const fetchConfig = useCallback(async () => {
const res = await fetch('/_assets/directory.json')
const data = await res.json()
setConfig(data);
let operatorsList = []
data.operators.forEach((item) => {
operatorsList = [...operatorsList, ...item]
})
setOperators(operatorsList)
}, [setConfig, setOperators])
const fetchVersion = useCallback(async () => {
const res = await fetch('/_assets/version.json')
const data = await res.json()
setVersion(data);
}, [setVersion])
return { config, version, operators, fetchConfig, fetchVersion };
const config = CONFIG;
const operators = OPERATORS;
return { config, operators };
}