@@ -7,7 +7,8 @@ const ProfileContext = createContext<IProfileContext>({} as IProfileContext);
7
7
// TODO: Potentially this should be moved to @cssloader as it isn't decky dependent
8
8
// TODO: Also, this should be zustand using .subscribe on the cssloader store, I just was lazy implementing it this way here
9
9
interface IProfileContextValues {
10
- displayMode : "offline" | "loggedout" | "loggedin" ;
10
+ displayMode : "offline" | "online" ;
11
+ loading : boolean ;
11
12
downloadedProfiles : Theme [ ] ;
12
13
localProfiles : Theme [ ] ;
13
14
uploadedProfiles : PartialCSSThemeInfo [ ] ;
@@ -24,15 +25,20 @@ export function ProfileContextProvider({ children }: { children: React.ReactNode
24
25
const { getUploadedThemes } = useCSSLoaderActions ( ) ;
25
26
const profiles = themes . filter ( ( e ) => e . flags . includes ( Flags . isPreset ) ) ;
26
27
27
- const [ displayMode , setDisplayMode ] = useState < "offline" | "loggedout" | "loggedin" > ( "offline" ) ;
28
- const localProfiles = profiles . filter (
29
- ( e ) => updateStatuses . find ( ( status ) => status [ 0 ] === e . id ) ?. [ 1 ] === "local"
30
- ) ;
28
+ const [ displayMode , setDisplayMode ] = useState < "offline" | "online" > ( "offline" ) ;
29
+ const [ loading , setLoading ] = useState ( true ) ;
31
30
32
31
const [ uploadedProfileRemoteEntries , setUploadedProfileRemoteEntries ] = useState <
33
32
PartialCSSThemeInfo [ ]
34
33
> ( [ ] ) ;
35
34
35
+ const localProfiles = profiles . filter ( ( e ) => {
36
+ const isLocal = updateStatuses . find ( ( status ) => status [ 0 ] === e . id ) ?. [ 1 ] === "local" ;
37
+ const isInUploaded = uploadedProfileRemoteEntries . some (
38
+ ( uploadedProfile ) => uploadedProfile . id === e . id
39
+ ) ;
40
+ return isLocal && ! isInUploaded ;
41
+ } ) ;
36
42
const downloadedProfiles = profiles . filter ( ( profile ) => {
37
43
const isInLocal = localProfiles . some ( ( localProfile ) => localProfile . id === profile . id ) ;
38
44
const isInUploaded = uploadedProfileRemoteEntries . some (
@@ -46,18 +52,20 @@ export function ProfileContextProvider({ children }: { children: React.ReactNode
46
52
setDisplayMode ( "offline" ) ;
47
53
return ;
48
54
}
55
+
56
+ setDisplayMode ( "online" ) ;
49
57
if ( ! apiMeData ) {
50
- setDisplayMode ( "loggedout" ) ;
51
58
return ;
52
59
}
53
60
61
+ setLoading ( true ) ;
54
62
// Logged in mode, separate downloaded and local, and show uploaded profiles
55
63
const uploadedThemes = await getUploadedThemes ( ) ;
56
64
const uploadedProfileRemoteEntries = uploadedThemes . filter ( ( theme ) =>
57
65
theme . targets . includes ( "Profile" )
58
66
) ;
59
67
setUploadedProfileRemoteEntries ( uploadedProfileRemoteEntries ) ;
60
- setDisplayMode ( "loggedin" ) ;
68
+ setLoading ( false ) ;
61
69
}
62
70
63
71
useEffect ( ( ) => {
@@ -68,6 +76,7 @@ export function ProfileContextProvider({ children }: { children: React.ReactNode
68
76
< ProfileContext . Provider
69
77
value = { {
70
78
displayMode,
79
+ loading,
71
80
downloadedProfiles,
72
81
localProfiles,
73
82
uploadedProfiles : uploadedProfileRemoteEntries ,
@@ -80,58 +89,3 @@ export function ProfileContextProvider({ children }: { children: React.ReactNode
80
89
}
81
90
82
91
export const useProfileContext = ( ) => useContext ( ProfileContext ) ;
83
-
84
- // const profileStore = createStore<IProfileStore>((set, get) => {
85
- // return {
86
- // displayMode: "offline",
87
- // downloadedProfiles: [],
88
- // localProfiles: [],
89
- // uploadedProfiles: [],
90
- // async initialize() {
91
- // const { apiMeData, updateStatuses, themes, getUploadedThemes } = getCSSLoaderState();
92
- // const profiles = themes.filter((e) => e.flags.includes(Flags.isPreset));
93
- // if (!updateStatuses) {
94
- // // Offline mode, no profile sorting, just one list
95
- // set({ displayMode: "offline", downloadedProfiles: profiles });
96
- // return;
97
- // }
98
-
99
- // let downloadedProfiles: Theme[] = [];
100
- // let localProfiles: Theme[] = [];
101
- // profiles.forEach((e) => {
102
- // if (updateStatuses.find((status) => status[0] === e.id)?.[1] === "local") {
103
- // localProfiles.push(e);
104
- // } else {
105
- // downloadedProfiles.push(e);
106
- // }
107
- // });
108
-
109
- // if (!apiMeData) {
110
- // // Logged out mode, separate downloaded and local, but no 'Uploaded' section
111
- // set({ displayMode: "loggedout", downloadedProfiles, localProfiles });
112
- // return;
113
- // }
114
-
115
- // // Logged in mode, separate downloaded and local, and show uploaded profiles
116
- // const uploadedThemes = await getUploadedThemes();
117
- // const uploadedProfileRemoteEntries = uploadedThemes.filter((theme) =>
118
- // theme.targets.includes("Profile")
119
- // );
120
-
121
- // // Since uploaded profiles are also technically 'downloaded', we have to manually filter them out
122
- // downloadedProfiles = downloadedProfiles.filter(
123
- // (profile) =>
124
- // !uploadedProfileRemoteEntries.some((uploadedProfile) => uploadedProfile.id === profile.id)
125
- // );
126
- // set({
127
- // displayMode: "loggedin",
128
- // downloadedProfiles,
129
- // localProfiles,
130
- // uploadedProfiles: uploadedProfileRemoteEntries,
131
- // });
132
- // },
133
- // };
134
- // });
135
-
136
- // export const useProfileStoreValues = generateStoreSelector<IProfileStoreValues>(profileStore);
137
- // export const useProfileStoreActions = generateStoreSelector<IProfileStoreActions>(profileStore);
0 commit comments