switched theme functions to nasa instead of raw AsyncStorage
This commit is contained in:
parent
955b14ee61
commit
502a5305c2
30
App.tsx
30
App.tsx
|
|
@ -15,7 +15,16 @@ import TitleBar from './components/TitleBar';
|
||||||
import db from './lib/client';
|
import db from './lib/client';
|
||||||
|
|
||||||
const findTheme = async () => {
|
const findTheme = async () => {
|
||||||
const theme = await AsyncStorage.getItem('theme');
|
const res = await db.from("settings").select().eq({id: 'theme'})
|
||||||
|
let theme = 'auto'
|
||||||
|
if (!res.error){
|
||||||
|
if (res.data.length > 0){
|
||||||
|
theme = res.data[0].value
|
||||||
|
}else{
|
||||||
|
const res = await db.from('settings').insert({id: 'theme', value: 'auto'})
|
||||||
|
console.log(res)
|
||||||
|
}
|
||||||
|
}
|
||||||
if(theme === 'dark') {
|
if(theme === 'dark') {
|
||||||
return dark;
|
return dark;
|
||||||
} else if(theme === 'light') {
|
} else if(theme === 'light') {
|
||||||
|
|
@ -35,7 +44,13 @@ const findTheme = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const findThemeMode = async () => {
|
const findThemeMode = async () => {
|
||||||
const theme = await AsyncStorage.getItem('theme');
|
const res = await db.from("settings").select().eq({id:'theme'})
|
||||||
|
let theme = 'auto'
|
||||||
|
if (!res.error){
|
||||||
|
if (res.data.length > 0){
|
||||||
|
theme = res.data[0].value
|
||||||
|
}
|
||||||
|
}
|
||||||
if (theme){
|
if (theme){
|
||||||
return theme;
|
return theme;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -55,7 +70,6 @@ export default function App() {
|
||||||
const [others, setOthers] = useState([]);
|
const [others, setOthers] = useState([]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
const theme = await findTheme();
|
const theme = await findTheme();
|
||||||
|
|
@ -97,22 +111,22 @@ export default function App() {
|
||||||
case 'dark':
|
case 'dark':
|
||||||
setThemeMode('dark');
|
setThemeMode('dark');
|
||||||
setTheme(dark);
|
setTheme(dark);
|
||||||
await AsyncStorage.setItem('theme', 'dark');
|
await db.from("settings").update({value: 'dark'}).eq({id: 'theme'})
|
||||||
break;
|
break;
|
||||||
case 'light':
|
case 'light':
|
||||||
setThemeMode('light');
|
setThemeMode('light');
|
||||||
setTheme(light);
|
setTheme(light);
|
||||||
await AsyncStorage.setItem('theme', 'light');
|
await db.from('settings').update({value: 'light'}).eq({id: 'theme'})
|
||||||
break;
|
break;
|
||||||
case 'solorizedDark':
|
case 'solorizedDark':
|
||||||
setThemeMode('solorizedDark');
|
setThemeMode('solorizedDark');
|
||||||
setTheme(solorizedDark);
|
setTheme(solorizedDark);
|
||||||
await AsyncStorage.setItem('theme', 'solorizedDark');
|
await db.from('settings').update({value: 'solorizedDark'}).eq({id: 'theme'})
|
||||||
break;
|
break;
|
||||||
case 'oled':
|
case 'oled':
|
||||||
setThemeMode('oled');
|
setThemeMode('oled');
|
||||||
setTheme(oled);
|
setTheme(oled);
|
||||||
await AsyncStorage.setItem('theme', 'oled');
|
await db.from('settings').update({value: 'oled'}).eq({id: 'theme'})
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
setThemeMode('auto');
|
setThemeMode('auto');
|
||||||
|
|
@ -122,7 +136,7 @@ export default function App() {
|
||||||
} else {
|
} else {
|
||||||
setTheme(light);
|
setTheme(light);
|
||||||
}
|
}
|
||||||
await AsyncStorage.setItem('theme', "auto");
|
await db.from('settings').update({id: 'theme', value: 'auto'}).eq({id: 'theme'})
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue