-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from arikama/show-hide-surah
UI changes
- Loading branch information
Showing
9 changed files
with
238 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Button } from "./button" | ||
|
||
export const ShowHideButton = (props: { | ||
what: string | ||
isHiding: boolean | ||
onClick: () => void | ||
}) => { | ||
return ( | ||
<Button | ||
onClick={props.onClick} | ||
> | ||
{props.isHiding ? "show" : "hide"} {props.what} | ||
</Button> | ||
) | ||
} |
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,2 +1,5 @@ | ||
export const USER_LOCAL_STORAGE_KEY = "userlocalstoragekey" | ||
export const BOOKMARK_SETTINGS_STORAGE_KEY = "bookmarksettingsstoragekey" | ||
export const STORAGE = { | ||
USER_LOCAL_STORAGE_KEY: "userlocalstoragekey", | ||
BOOKMARK_SETTINGS_STORAGE_KEY: "bookmarksettingsstoragekey", | ||
SURAH_SETTINGS_STORAGE_KEY: "surahsettingsstoragekey" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useEffect, useState } from "react" | ||
|
||
export function usePersistentState<T>(storageKey: string, initialState: T): [T, (newState: T) => boolean] { | ||
const [state, setState] = useState<T>(initialState) | ||
|
||
useEffect(() => { | ||
if (typeof window !== "undefined") { | ||
const blob = window.localStorage.getItem(storageKey) | ||
if (blob) { | ||
const parsed = JSON.parse(blob) as T | ||
if (parsed) { | ||
setState(parsed) | ||
} | ||
} | ||
} | ||
}, [storageKey]) | ||
|
||
const update = (newState: T) => { | ||
setState(newState) | ||
if (typeof window !== "undefined") { | ||
const blob = JSON.stringify(newState) | ||
window.localStorage.setItem(storageKey, blob) | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
|
||
return [state, update] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type SurahSettings = { | ||
hideVerse: boolean | ||
hideTranslation: boolean | ||
} |