-
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.
Show & hide buttons in Bookmark (#13)
* show & hide buttons * renames * fix name * dont use package version
- Loading branch information
Showing
6 changed files
with
139 additions
and
30 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const USER_LOCAL_STORAGE_KEY = "koranappuserjson" | ||
export const USER_LOCAL_STORAGE_KEY = "userlocalstoragekey" | ||
export const BOOKMARK_SETTINGS_STORAGE_KEY = "bookmarksettingsstoragekey" |
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,33 @@ | ||
import { useEffect, useState } from "react" | ||
|
||
import { BOOKMARK_SETTINGS_STORAGE_KEY } from "../constants/storage" | ||
import { BookmarkSettings } from "../types/bookmark_settings" | ||
|
||
export function useBookmarkSettings() { | ||
const [bookmarkSettings, setBookmarkSettings] = useState<BookmarkSettings>({ | ||
hideVerse: true, | ||
hideTranslation: true | ||
}) | ||
|
||
useEffect(() => { | ||
if (typeof window !== "undefined") { | ||
const blob = window.localStorage.getItem(BOOKMARK_SETTINGS_STORAGE_KEY) | ||
if (blob) { | ||
const parsed = JSON.parse(blob) as BookmarkSettings | ||
if (parsed) { | ||
setBookmarkSettings(parsed) | ||
} | ||
} | ||
} | ||
}, []) | ||
|
||
const updateBookmarkSettings = (update: BookmarkSettings) => { | ||
if (typeof window !== "undefined") { | ||
const blob = JSON.stringify(update) | ||
window.localStorage.setItem(BOOKMARK_SETTINGS_STORAGE_KEY, blob) | ||
} | ||
setBookmarkSettings(update) | ||
} | ||
|
||
return { bookmarkSettings, updateBookmarkSettings } | ||
} |
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 BookmarkSettings = { | ||
hideVerse: boolean | ||
hideTranslation: boolean | ||
} |