Add history page, probably more stuff
parent
269990a156
commit
635f9a9634
@ -0,0 +1,24 @@
|
||||
import { h } from "../jsx.ts";
|
||||
import watt, { watt as originalWatt } from "../wattpad.ts";
|
||||
import Base from "../templates/Base.tsx";
|
||||
|
||||
import Script from "../components/Script.tsx";
|
||||
import HistoryScript from "../scripts/History.ts";
|
||||
|
||||
function search() {
|
||||
console.log(document.getElementById("query"));
|
||||
}
|
||||
|
||||
export default (params: URLSearchParams) => {
|
||||
return (
|
||||
<Base
|
||||
title="History"
|
||||
description="Previously read works."
|
||||
stylepath="css/index.scss"
|
||||
>
|
||||
<h1>Previously-read works</h1>
|
||||
<Script function={HistoryScript} />
|
||||
<div id="stories" class="stories" />
|
||||
</Base>
|
||||
);
|
||||
};
|
@ -0,0 +1,48 @@
|
||||
/* <a href={"/story?id=" + rizz.id} class="story">
|
||||
<img src={rizz.storyJSON.cover} />
|
||||
<div>
|
||||
<h3>{rizz.name}</h3>
|
||||
<p>{rizz.storyJSON.description}</p>
|
||||
</div>
|
||||
</a> */
|
||||
|
||||
export default () => {
|
||||
const oldOnloadHandler: Function = window.onload ?? (() => {});
|
||||
|
||||
window.onload = async () => {
|
||||
oldOnloadHandler();
|
||||
|
||||
const historyDiv = document.getElementById("stories");
|
||||
|
||||
const readingHistory: string[] = JSON.parse(
|
||||
localStorage.getItem("readingHistory") ?? "[]",
|
||||
);
|
||||
|
||||
for (let i = 0; i < readingHistory.length; i++) {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
const story: Record<string, any> = await (await fetch(
|
||||
document.location.origin +
|
||||
`/api/getStory?id=${readingHistory[i]}`,
|
||||
)).json();
|
||||
|
||||
const searchEle = document.createElement("a");
|
||||
searchEle.className = "story";
|
||||
searchEle.href = "/story?id=" + story.id +
|
||||
(localStorage.getItem(`${story.id}_progress`)
|
||||
? `&chapter=${localStorage.getItem(`${story.id}_progress`)}`
|
||||
: "");
|
||||
const coverEle = document.createElement("img");
|
||||
coverEle.src = story.storyJSON.cover;
|
||||
const div = document.createElement("div");
|
||||
const titleEle = document.createElement("h3");
|
||||
titleEle.textContent = story.name;
|
||||
div.appendChild(titleEle);
|
||||
const descEle = document.createElement("o");
|
||||
descEle.textContent = story.storyJSON.description;
|
||||
div.appendChild(descEle);
|
||||
searchEle.appendChild(coverEle);
|
||||
searchEle.appendChild(div);
|
||||
historyDiv?.appendChild(searchEle);
|
||||
}
|
||||
};
|
||||
};
|
@ -1,9 +1,34 @@
|
||||
export default () => {
|
||||
let oldOnloadHandler: Function;
|
||||
oldOnloadHandler = window.onload ?? (() => {});
|
||||
|
||||
window.onload = () => {
|
||||
oldOnloadHandler();
|
||||
const params = new URL(document.location.href).searchParams;
|
||||
localStorage.setItem(
|
||||
`${params.get("id")}_progress`,
|
||||
params.get("chapter") as string,
|
||||
if (params.get("chapter")) {
|
||||
localStorage.setItem(
|
||||
`${params.get("id")}_progress`,
|
||||
params.get("chapter") as string,
|
||||
);
|
||||
}
|
||||
|
||||
const readingHistory: string[] = JSON.parse(
|
||||
localStorage.getItem("readingHistory") ?? "[]",
|
||||
);
|
||||
|
||||
readingHistory.forEach((id, idx) => {
|
||||
if (id === params.get("id")) {
|
||||
readingHistory.splice(idx, 1);
|
||||
}
|
||||
});
|
||||
|
||||
readingHistory.unshift(params.get("id") as string);
|
||||
|
||||
//TODO: do pagination on the history page to make this un-necessary
|
||||
if (readingHistory.length > 50) {
|
||||
readingHistory.pop();
|
||||
}
|
||||
|
||||
localStorage.setItem("readingHistory", JSON.stringify(readingHistory));
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in new issue