Skip to content

Commit

Permalink
🐛 Fix episode order saving
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Oct 13, 2024
1 parent 6a3c9cf commit 69d984e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pages/episode/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as apiurlMiddleware from "~/middleware/apiurl.middleware";
import {getEpisodeImages, getEpisodeInfos} from "~/utils/api";
import VisibilityObserver from "~/components/utils/VisibilityObserver.vue";
import {getEpisodeProgression, startEpisode} from "~/utils/storage";
import {getEpisodeProgression, setEpisodeProgression, startEpisode} from "~/utils/storage";
definePageMeta({
middleware: [
Expand Down
22 changes: 14 additions & 8 deletions utils/storage.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@


export function saveOrder(webtoonId: number, order: boolean): void{
if(import.meta.server)
return;
localStorage.setItem("order", JSON.stringify({webtoonId, order}));
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}));
}
}

export function getOrder(webtoonId: number): boolean{
if(import.meta.server)
return;
const order = localStorage.getItem("order");
if(order){
const parsedOrder = JSON.parse(order);
if(parsedOrder.webtoonId === webtoonId)
return parsedOrder.order;
let orders = localStorage.getItem("order");
if(orders){
orders = JSON.parse(orders);
if(orders[webtoonId] === undefined)
return true;
return orders[webtoonId];
}
return true;
}
Expand Down

0 comments on commit 69d984e

Please sign in to comment.