feat(directory): added ability to show if any new operator is available

This commit is contained in:
Haoyu Xu
2023-10-08 02:01:20 -04:00
parent c5a301ecc7
commit 8f09b01851
6 changed files with 94 additions and 16 deletions

View File

@@ -1,4 +1,8 @@
import CONFIG from '@/_directory.json';
import { useCallback } from 'react';
import { atom, useAtom } from 'jotai';
const officalUpdateAtom = atom({});
let operators = []
CONFIG.operators.forEach((item) => {
@@ -9,6 +13,18 @@ const OPERATORS = operators;
export function useConfig() {
const config = CONFIG;
const operators = OPERATORS;
const [officalUpdate, setOfficalUpdate] = useAtom(officalUpdateAtom);
return { config, operators };
const fetchOfficalUpdate = useCallback(async () => {
const res = await fetch('https://raw.githubusercontent.com/Halyul/aklive2d/main/offical_update.json')
const data = await res.json().catch((e) => {
console.error(e)
return {
length: 0
}
})
setOfficalUpdate(data);
}, [setOfficalUpdate])
return { config, operators, officalUpdate, fetchOfficalUpdate };
}