chore: moved to a new branch to save space

This commit is contained in:
Haoyu Xu
2023-03-16 21:49:29 -04:00
commit 6ef70824a1
116 changed files with 23521 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
import { atom, useAtom } from 'jotai';
const extraAreaAtom = atom([]);
export function useAppbar() {
const [extraArea, setExtraArea] = useAtom(extraAreaAtom);
return {
extraArea, setExtraArea
}
}

View File

@@ -0,0 +1,19 @@
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

@@ -0,0 +1,31 @@
import { useCallback } from 'react';
import { atom, useAtom } from 'jotai';
const configAtom = atom([]);
const operatorsAtom = atom([]);
const versionAtom = atom({});
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 };
}

View File

@@ -0,0 +1,34 @@
import { useEffect } from 'react';
import { atom, useAtom } from 'jotai';
import { useI18n } from "@/state/language"
const keyAtom = atom('');
const titleAtom = atom('');
const tabsAtom = atom([]);
const currentTabAtom = atom(null);
const appbarExtraAreaAtom = atom([]);
const headerIconAtom = atom(null);
export function useHeader() {
const [key, setTitle] = useAtom(keyAtom);
const [title, setRealTitle] = useAtom(titleAtom);
const [tabs, setTabs] = useAtom(tabsAtom);
const [currentTab, setCurrentTab] = useAtom(currentTabAtom);
const [appbarExtraArea, setAppbarExtraArea] = useAtom(appbarExtraAreaAtom);
const [headerIcon, setHeaderIcon] = useAtom(headerIconAtom);
const { i18n } = useI18n()
useEffect(() => {
const newTitle = i18n(key)
document.title = `${newTitle} - ${import.meta.env.VITE_APP_TITLE}`;
setRealTitle(newTitle)
}, [i18n, key, setRealTitle])
return {
title, setTitle,
tabs, setTabs,
currentTab, setCurrentTab,
appbarExtraArea, setAppbarExtraArea,
headerIcon, setHeaderIcon
}
}

View File

@@ -0,0 +1,35 @@
import { atom, useAtom, useAtomValue } from 'jotai';
import { atomWithStorage } from 'jotai/utils';
import i18nObject from '@/i18n'
const language = i18nObject.available.includes(navigator.language) ? navigator.language : "en-US"
const textDefaultLang = "en-US"
const languageAtom = atomWithStorage('language', language)
const alternateLangAtom = atom((get) => {
const language = get(languageAtom)
return language.startsWith("en") ? "zh-CN" : language
})
export function useI18n() {
const language = useAtomValue(languageAtom)
return {
i18n: (key, preferredLanguage = language) => {
if (i18nObject.key[key]) {
return i18nObject.key[key][preferredLanguage]
}
return key
},
i18nValues: i18nObject,
}
}
export function useLanguage() {
const [language, setLanguage] = useAtom(languageAtom)
const alternateLang = useAtomValue(alternateLangAtom)
return {
textDefaultLang,
language, setLanguage,
alternateLang,
}
}