-
-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
48 changed files
with
1,975 additions
and
1,094 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
50 changes: 50 additions & 0 deletions
50
MythicReactUI/src/components/MythicComponents/MythicSavedUserSetting.js
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useReactiveVar } from '@apollo/client'; | ||
import { meState } from '../../cache'; | ||
import React from 'react'; | ||
|
||
/* | ||
setting_name options: | ||
hideUsernames | ||
showIP | ||
showHostname | ||
showCallbackGroups | ||
showMedia | ||
*/ | ||
export function useMythicSetting({setting_name, default_value, output="boolean"}){ | ||
const me = useReactiveVar(meState); | ||
// get the initial value we have stored | ||
const localStorageSetting = localStorage.getItem(`${me?.user?.user_id || 0}-${setting_name}`); | ||
let initialStorageSetting = localStorageSetting === null ? default_value : localStorageSetting; | ||
|
||
switch(output){ | ||
case "boolean": | ||
initialStorageSetting = (localStorageSetting.toLowerCase() === "true"); | ||
break; | ||
case "number": | ||
initialStorageSetting = Number(localStorageSetting); | ||
break; | ||
default: | ||
console.log("unknown output type", output); | ||
} | ||
|
||
const [setting, setSetting] = React.useState(initialStorageSetting); | ||
React.useEffect( () => { | ||
// update the initial value if the user changes | ||
const localStorageSetting = localStorage.getItem(`${me?.user?.user_id || 0}-${setting_name}`); | ||
let initialStorageSetting = localStorageSetting === null ? default_value : localStorageSetting; | ||
|
||
switch(output){ | ||
case "boolean": | ||
initialStorageSetting = (localStorageSetting.toLowerCase() === "true"); | ||
break; | ||
case "number": | ||
initialStorageSetting = Number(localStorageSetting); | ||
break; | ||
default: | ||
console.log("unknown output type", output); | ||
} | ||
|
||
setSetting(initialStorageSetting); | ||
}, [me]); | ||
return setting; | ||
} |
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
Oops, something went wrong.