add favorite stories and searches + probably other things
so much shit was changed idek what did lmaomaster
parent
bf0d511282
commit
dd311ef468
@ -0,0 +1,16 @@
|
||||
import { Props } from "../types.d.ts";
|
||||
import { h } from "../jsx.ts";
|
||||
|
||||
interface BaseScriptProps extends Props {
|
||||
// deno-lint-ignore ban-types
|
||||
function?: Function;
|
||||
// deno-lint-ignore no-explicit-any
|
||||
children?: any;
|
||||
}
|
||||
|
||||
export default (props: BaseScriptProps) => (
|
||||
<script>
|
||||
{props.function ? `(${props.function.toString()})();` : undefined}
|
||||
{props.children ?? undefined}
|
||||
</script>
|
||||
);
|
@ -0,0 +1,3 @@
|
||||
import { h } from "../jsx.ts";
|
||||
|
||||
export default () => <div class="vertical-line" />;
|
@ -0,0 +1,55 @@
|
||||
interface SavedSearch {
|
||||
query: string;
|
||||
type: "text" | "title" | "tag";
|
||||
}
|
||||
|
||||
export default () => {
|
||||
window.onload = () => {
|
||||
const button = document.getElementById("favorite");
|
||||
|
||||
if (!button) throw "how did your button not init what";
|
||||
|
||||
let savedSearches: SavedSearch[] = JSON.parse(
|
||||
localStorage.getItem("savedSearches") ?? "[]",
|
||||
);
|
||||
|
||||
function handler() {
|
||||
if (button?.textContent === "Favorite") {
|
||||
savedSearches.push({
|
||||
query: (new URL(document.URL)).searchParams.get(
|
||||
"query",
|
||||
) as string,
|
||||
type: (new URL(document.URL)).searchParams.get(
|
||||
"type",
|
||||
) as "text" | "title" | "tag",
|
||||
});
|
||||
button.textContent = "Unfavorite";
|
||||
} else if (button?.textContent === "Unfavorite") {
|
||||
savedSearches = savedSearches.filter((search) =>
|
||||
search.query !==
|
||||
(new URL(document.URL)).searchParams.get("query") &&
|
||||
search.type !==
|
||||
(new URL(document.URL)).searchParams.get("type")
|
||||
);
|
||||
button.textContent = "Favorite";
|
||||
}
|
||||
localStorage.setItem(
|
||||
"savedSearches",
|
||||
JSON.stringify(savedSearches),
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
savedSearches.filter((search) =>
|
||||
search.query ===
|
||||
(new URL(document.URL)).searchParams.get("query") &&
|
||||
search.type ===
|
||||
(new URL(document.URL)).searchParams.get("type")
|
||||
).length > 0
|
||||
) {
|
||||
button.textContent = "Unfavorite";
|
||||
}
|
||||
|
||||
button.onclick = handler;
|
||||
};
|
||||
};
|
@ -0,0 +1,51 @@
|
||||
interface SavedStory {
|
||||
id: string;
|
||||
// in *theory* we could fetch these from the cache, but if it's not there you'd have to wait years to open the homepage lol
|
||||
name: string;
|
||||
coverURL: string;
|
||||
}
|
||||
|
||||
export default () => {
|
||||
window.onload = () => {
|
||||
const button = document.getElementById("favorite");
|
||||
|
||||
if (!button) throw "how did your button not init what";
|
||||
|
||||
let savedStories: SavedStory[] = JSON.parse(
|
||||
localStorage.getItem("savedStories") ?? "[]",
|
||||
);
|
||||
|
||||
function handler() {
|
||||
if (button?.textContent === "Favorite") {
|
||||
savedStories.push({
|
||||
id: (new URL(document.URL)).searchParams.get(
|
||||
"id",
|
||||
) as string,
|
||||
name: document.getElementById("storyname")
|
||||
?.textContent as string,
|
||||
coverURL: (document.getElementById(
|
||||
"storycover",
|
||||
) as HTMLImageElement)
|
||||
.src,
|
||||
});
|
||||
button.textContent = "Unfavorite";
|
||||
} else if (button?.textContent === "Unfavorite") {
|
||||
savedStories = savedStories.filter((story) =>
|
||||
story.id !== (new URL(document.URL)).searchParams.get("id")
|
||||
);
|
||||
button.textContent = "Favorite";
|
||||
}
|
||||
localStorage.setItem("savedStories", JSON.stringify(savedStories));
|
||||
}
|
||||
|
||||
if (
|
||||
savedStories.filter((story) =>
|
||||
story.id === (new URL(document.URL)).searchParams.get("id")
|
||||
).length > 0
|
||||
) {
|
||||
button.textContent = "Unfavorite";
|
||||
}
|
||||
|
||||
button.onclick = handler;
|
||||
};
|
||||
};
|
@ -0,0 +1,49 @@
|
||||
interface SavedSearch {
|
||||
query: string;
|
||||
type: "text" | "title" | "tag";
|
||||
}
|
||||
|
||||
interface SavedStory {
|
||||
id: string;
|
||||
// in *theory* we could fetch these from the cache, but if it's not there you'd have to wait years to open the homepage lol
|
||||
name: string;
|
||||
coverURL: string;
|
||||
}
|
||||
|
||||
export default () => {
|
||||
window.onload = () => {
|
||||
const savedSearchesDiv = document.getElementById("saved-searches");
|
||||
const savedStoriesDiv = document.getElementById("saved-stories");
|
||||
const savedSearches: SavedSearch[] = JSON.parse(
|
||||
localStorage.getItem("savedSearches") ?? "[]",
|
||||
);
|
||||
const savedStories: SavedStory[] = JSON.parse(
|
||||
localStorage.getItem("savedStories") ?? "[]",
|
||||
);
|
||||
|
||||
savedSearches.forEach((search) => {
|
||||
const searchEle = document.createElement("a");
|
||||
searchEle.href =
|
||||
`/search?query=${search.query}&type=${search.type}`;
|
||||
searchEle.textContent = `${search.query} (${search.type} search)`;
|
||||
searchEle.className = "saved-search";
|
||||
savedSearchesDiv?.appendChild(searchEle);
|
||||
});
|
||||
|
||||
savedStories.forEach((story) => {
|
||||
const searchEle = document.createElement("a");
|
||||
searchEle.className = "story";
|
||||
/* TODO: perhaps save story progress as well? */
|
||||
searchEle.href = "/story?id=" + story.id;
|
||||
const coverEle = document.createElement("img");
|
||||
coverEle.src = story.coverURL;
|
||||
const div = document.createElement("div");
|
||||
const titleEle = document.createElement("h3");
|
||||
titleEle.textContent = story.name;
|
||||
div.appendChild(titleEle);
|
||||
searchEle.appendChild(coverEle);
|
||||
searchEle.appendChild(div);
|
||||
savedStoriesDiv?.appendChild(searchEle);
|
||||
});
|
||||
};
|
||||
};
|
Loading…
Reference in new issue