diff options
| author | real-zephex <[email protected]> | 2024-05-11 19:14:29 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-05-11 19:14:29 +0530 |
| commit | e8875b008268c5873454b120bfb358cb4180093f (patch) | |
| tree | 2a0f8a15fb42f093e1d35f52eb3f7e14f1b0fbe5 /src/app/anime/components/storeHistory.js | |
| parent | Merge pull request #24 from zephex-alt/master (diff) | |
| parent | added anime history section (diff) | |
| download | dramalama-e8875b008268c5873454b120bfb358cb4180093f.tar.xz dramalama-e8875b008268c5873454b120bfb358cb4180093f.zip | |
Merge pull request #25 from real-zephex/improvement-2
Improvement 2
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); +} |