Move plotBackendRendering from atom into localStorage

This commit is contained in:
porink0424
2024-03-29 16:54:05 +09:00
parent e367ce6c1f
commit 4255aa4d65
2 changed files with 8 additions and 11 deletions
+3 -5
View File
@@ -11,8 +11,7 @@ import {
Box,
} from "@mui/material"
import ClearIcon from "@mui/icons-material/Clear"
import { useRecoilState } from "recoil"
import { plotBackendRenderingState, usePlotlyColorThemeState } from "../state"
import { usePlotBackendRendering, usePlotlyColorThemeState } from "../state"
interface SettingsProps {
handleClose: () => void
@@ -21,9 +20,8 @@ interface SettingsProps {
export const Settings = ({ handleClose }: SettingsProps) => {
const theme = useTheme()
const [plotlyColorTheme, setPlotlyColorTheme] = usePlotlyColorThemeState()
const [plotBackendRendering, setPlotBackendRendering] = useRecoilState(
plotBackendRenderingState
)
const [plotBackendRendering, setPlotBackendRendering] =
usePlotBackendRendering()
const handleDarkModeColorChange = (event: SelectChangeEvent) => {
const dark = event.target.value as PlotlyColorThemeDark
+5 -6
View File
@@ -43,11 +43,6 @@ export const artifactIsAvailable = atom<boolean>({
default: false,
})
export const plotBackendRenderingState = atom<boolean>({
key: "plotBackendRendering",
default: false,
})
export const plotlypyIsAvailableState = atom<boolean>({
key: "plotlypyIsAvailable",
default: true,
@@ -63,6 +58,10 @@ export const studyDetailLoadingState = atom<Record<number, boolean>>({
default: {},
})
export const usePlotBackendRendering = () => {
return useLocalStorage<boolean>("plotBackendRendering", false)
}
export const usePlotlyColorThemeState = () => {
return useLocalStorage<PlotlyColorTheme>("plotlyColorTheme", {
dark: "default",
@@ -124,7 +123,7 @@ export const usePlotlyColorTheme = (mode: string): Partial<Plotly.Template> => {
}
export const useBackendRender = (): boolean => {
const plotBackendRendering = useRecoilValue(plotBackendRenderingState)
const [plotBackendRendering, _] = usePlotBackendRendering()
const plotlypyIsAvailable = useRecoilValue(plotlypyIsAvailableState)
if (plotBackendRendering) {