-
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.
🎨 Improve local storage management and episode navigation
- Loading branch information
Showing
4 changed files
with
51 additions
and
73 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
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,75 +1,45 @@ | ||
export function saveOrder(webtoonId: number, order: boolean): void{ | ||
if(import.meta.server) | ||
return; | ||
let orders = localStorage.getItem("order"); | ||
if(orders){ | ||
orders = JSON.parse(orders); | ||
orders[webtoonId] = order; | ||
localStorage.setItem("order", JSON.stringify(orders)); | ||
} else { | ||
localStorage.setItem("order", JSON.stringify({[webtoonId]: order})); | ||
import {useLocalStorage} from "@vueuse/core"; | ||
|
||
export function useOrder(){ | ||
const orders = useLocalStorage<Record<number, boolean>>("order", {}); | ||
|
||
function saveOrder(webtoonId: number, order: boolean): void{ | ||
orders.value[webtoonId] = order; | ||
} | ||
} | ||
|
||
export function getOrder(webtoonId: number): boolean{ | ||
if(import.meta.server) | ||
return; | ||
let orders = localStorage.getItem("order"); | ||
if(orders){ | ||
orders = JSON.parse(orders); | ||
if(orders[webtoonId] === undefined) | ||
return true; | ||
return orders[webtoonId]; | ||
function getOrder(webtoonId: number): boolean{ | ||
return orders.value[webtoonId] ?? true; | ||
} | ||
return true; | ||
|
||
return {saveOrder, getOrder}; | ||
} | ||
|
||
export function startEpisode(episodeId: number): void{ | ||
if(import.meta.server) | ||
return; | ||
let episodes = localStorage.getItem("episode"); | ||
if(episodes){ | ||
episodes = JSON.parse(episodes); | ||
if(!episodes.includes(episodeId)){ | ||
episodes.push(episodeId); | ||
localStorage.setItem("episode", JSON.stringify(episodes)); | ||
export function useEpisode(){ | ||
const episodes = useLocalStorage<number[]>("episode", []); | ||
const progressions = useLocalStorage<Record<number, number>>("progression", {}); | ||
|
||
function startEpisode(episodeId: number): void{ | ||
if (!episodes.value.includes(episodeId)){ | ||
episodes.value.push(episodeId); | ||
} | ||
} else { | ||
localStorage.setItem("episode", JSON.stringify([episodeId])); | ||
} | ||
} | ||
|
||
export function isEpisodeStarted(episodeId: number): boolean{ | ||
if(import.meta.server) | ||
return; | ||
let episodes = localStorage.getItem("episode"); | ||
if(episodes){ | ||
episodes = JSON.parse(episodes); | ||
return episodes.includes(episodeId.toString()); | ||
function isEpisodeStarted(episodeId: number): boolean{ | ||
return episodes.value.includes(episodeId.toString()); | ||
} | ||
return false; | ||
} | ||
|
||
export function setEpisodeProgression(episodeId: number, progression: number): void{ | ||
if(import.meta.server) | ||
return; | ||
let progressions = localStorage.getItem("progression"); | ||
if(progressions){ | ||
progressions = JSON.parse(progressions); | ||
progressions[episodeId] = progression; | ||
localStorage.setItem("progression", JSON.stringify(progressions)); | ||
} else { | ||
localStorage.setItem("progression", JSON.stringify({[episodeId]: progression})); | ||
function setEpisodeProgression(episodeId: number, progression: number): void{ | ||
progressions.value[episodeId] = progression; | ||
} | ||
} | ||
|
||
export function getEpisodeProgression(episodeId: number): number{ | ||
if(import.meta.server) | ||
return; | ||
let progressions = localStorage.getItem("progression"); | ||
if(progressions){ | ||
progressions = JSON.parse(progressions); | ||
return progressions[episodeId] || 0; | ||
function getEpisodeProgression(episodeId: number): number{ | ||
return progressions.value[episodeId] || 0; | ||
} | ||
return 0; | ||
|
||
return { | ||
startEpisode, | ||
isEpisodeStarted, | ||
setEpisodeProgression, | ||
getEpisodeProgression, | ||
}; | ||
} |