-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThemeContext.js
More file actions
85 lines (74 loc) · 2.43 KB
/
Copy pathThemeContext.js
File metadata and controls
85 lines (74 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React, { createContext, useEffect, useState } from "react";
import { getAuth, onAuthStateChanged } from "firebase/auth";
import { doc, getDoc } from "firebase/firestore";
import { FIRESTORE_DB } from "./FirebaseConfig";
import * as SplashScreen from "expo-splash-screen";
export const ThemeContext = createContext();
const customLightTheme = {
dark: false,
colors: {
primary: "#73000A", // garnet
garnetWhite: "#73000A",
background: "#FFFFFF", // white
card: "#F2F2F2", // light gray
text: "#000000", // black text
border: "#E0E0E0", // light border
notification: "#73000A", // match primary
alwaysWhite: "#FFFFFF", // white
placeholder: "#A9A9A9", // light gray placeholder
lightGarnet: "#D5B4BA", // light garnet
disabledDay: "#B6BCC2" // very light gray
},
};
const customDarkTheme = {
dark: true,
colors: {
primary: "#73000A", // dark version still using garnet
garnetWhite: "#FFFFFF",
background: "#757474", // deep dark background
card: "#2C2C2C", // card/drawer background
text: "#E0E0E0", // white text
border: "#5a5a5a", // darker border
notification: "#FF8A80", // lighter red
alwaysWhite: "#FFFFFF", // white
placeholder: "#A9A9A9", // light
lightGarnet: "#9C6B70", // light garnet
disabledDay: "#75797D" // darker gray
},
};
export const ThemeProvider = ({ children }) => {
const [isDarkTheme, setIsDarkTheme] = useState(false);
const [isLoaded, setIsLoaded] = useState(false);
useEffect(() => {
const unsubscribe = onAuthStateChanged(getAuth(), async (user) => {
if (!user) {
setIsLoaded(true);
await SplashScreen.hideAsync();
return;
}
try {
const docRef = doc(FIRESTORE_DB, "settings", user.uid);
const docSnap = await getDoc(docRef);
if (docSnap.exists()) {
const userSettings = docSnap.data().settings;
if (userSettings?.theme === "dark") {
setIsDarkTheme(true);
}
}
} catch (error) {
console.error("Error loading theme from Firestore:", error);
}
setIsLoaded(true);
await SplashScreen.hideAsync();
});
return () => unsubscribe();
}, []);
const theme = isDarkTheme ? customDarkTheme : customLightTheme;
return (
<ThemeContext.Provider
value={{ isDarkTheme, setIsDarkTheme, theme, isLoaded }}
>
{isLoaded ? children : null}
</ThemeContext.Provider>
);
};