diff options
| author | real-zephex <[email protected]> | 2024-05-14 01:02:50 +0530 |
|---|---|---|
| committer | real-zephex <[email protected]> | 2024-05-14 01:02:50 +0530 |
| commit | c0e1e1a5ab734d254392e8bfcc7ace0e0ff3b6fa (patch) | |
| tree | 271228b9cf8ba5bd80a79145216c84ee1144457d /src/app/anime/components/storeHistory.js | |
| parent | minor changes to the kdrama page (diff) | |
| parent | Merge pull request #27 from real-zephex/improvement-2 (diff) | |
| download | dramalama-c0e1e1a5ab734d254392e8bfcc7ace0e0ff3b6fa.tar.xz dramalama-c0e1e1a5ab734d254392e8bfcc7ace0e0ff3b6fa.zip | |
Merge branch 'master' of https://github.com/real-zephex/Dramalama-Next
Diffstat (limited to 'src/app/anime/components/storeHistory.js')
| -rw-r--r-- | src/app/anime/components/storeHistory.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/app/anime/components/storeHistory.js b/src/app/anime/components/storeHistory.js new file mode 100644 index 0000000..bd41815 --- /dev/null +++ b/src/app/anime/components/storeHistory.js @@ -0,0 +1,35 @@ +"use client"; + +export function storeLocal(watchData) { + const currentDate = new Date(); + const jsonData = localStorage.getItem("data"); + const dataObject = jsonData ? JSON.parse(jsonData) : {}; + + if (!dataObject.watchHis) { + dataObject.watchHis = []; + } + + let found = false; + dataObject.watchHis.forEach((element) => { + if (element.name === watchData.name) { + let episode = watchData.episode; + let date = `${currentDate.getDate()}-${String( + currentDate.getMonth() + 1 + ).padStart(2, "0")}`; + let time = `${currentDate.getHours()}:${String( + currentDate.getMinutes() + ).padStart(2, "0")}`; + element.episode = episode; + element.date = date; + element.time = time; + found = true; + } + }); + + if (!found) { + dataObject.watchHis.push(watchData); + } + + let updatedData = JSON.stringify(dataObject); + localStorage.setItem("data", updatedData); +} |