-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use a json file for state storage instead of web LocalStorage
- Loading branch information
1 parent
05d7f7d
commit 1cac4e1
Showing
6 changed files
with
76 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,54 @@ | ||
import ReactDOM from "react-dom/client"; | ||
import "./locales"; | ||
import App from "./App"; | ||
import "./locales"; | ||
import { useGenericPersistentState } from "./states/genericStates"; | ||
import { usePersistentServers } from "./states/servers"; | ||
import { useSettings } from "./states/settings"; | ||
import { useTheme } from "./states/theme"; | ||
import nativeStorage from "./utils/nativeStorage"; | ||
|
||
async function runner() { | ||
const favsStr = localStorage.getItem("favorites-and-recentlyjoined-storage"); | ||
const genericStr = localStorage.getItem("generic-state-storage"); | ||
const settingsStr = localStorage.getItem("settings-storage"); | ||
const themeStr = localStorage.getItem("theme-storage"); | ||
|
||
if (favsStr) { | ||
const favs = JSON.parse(favsStr); | ||
const settingsNewStr = await nativeStorage.getItem("settings-storage"); | ||
|
||
const hasNativeData = | ||
settingsNewStr === null | ||
? false | ||
: JSON.parse(settingsNewStr).state.dataMerged; | ||
|
||
if ( | ||
Array.isArray(favs.state.favorites) && | ||
favs.state.favorites.length && | ||
!hasNativeData | ||
) { | ||
usePersistentServers.setState(favs.state); | ||
|
||
if (genericStr) { | ||
const generic = JSON.parse(genericStr); | ||
useGenericPersistentState.setState(generic.state); | ||
} | ||
|
||
if (settingsStr) { | ||
const settings = JSON.parse(settingsStr); | ||
useSettings.setState({ ...settings.state, dataMerged: true }); | ||
} | ||
|
||
if (themeStr) { | ||
const theme = JSON.parse(themeStr); | ||
useTheme.setState(theme.state); | ||
} | ||
} | ||
} | ||
|
||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( | ||
<App /> | ||
); | ||
} | ||
|
||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( | ||
<App /> | ||
); | ||
runner(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters