diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..688a29e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "[javascript]": { + "editor.tabSize": 4, + "editor.detectIndentation": false, + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + } +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..db45470 --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +Copyright Ruthenic + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/css/index.scss b/css/index.scss index daac019..340b780 100644 --- a/css/index.scss +++ b/css/index.scss @@ -151,6 +151,13 @@ a:hover { } } +.search-buttons { + column-gap: 0.5em; + input { + width: 100%; + } +} + .story-list { margin-top: 0.5em; display: flex; @@ -185,14 +192,53 @@ a:hover { } .favorites-container { + margin-top: 1em; + display: flex; flex-direction: row; - row-gap: 5em; + column-gap: 5em; justify-content: space-evenly; @media (max-width: 900px) { flex-direction: column; - column-gap: 1em; + row-gap: 1em; justify-content: center; } } + +.favorite-searches, +.favorite-stories { + display: flex; + flex-direction: column; + row-gap: 0.5em; + align-items: center; +} + +.favorite-search { + text-decoration: none; + color: black !important; + background-color: darkgrey; + border-radius: 0.375em; + border-style: solid; + border-width: 1px; + border-color: #0f0f0f; + padding: 0.2em; + margin-bottom: 0.5em; + text-align: center; +} + +.favorite-story { + display: flex; + flex-direction: column; + align-items: center; + text-decoration: none; + row-gap: 0.25em; + text-align: center; + margin-bottom: 0.5em; + img { + min-width: 227px; + width: 227px; + min-height: 355px; + height: 355px; + } +} diff --git a/scripts/History.js b/scripts/History.js index 01e4d53..5c8f424 100644 --- a/scripts/History.js +++ b/scripts/History.js @@ -1,5 +1,3 @@ -const oldOnloadHandler = window.onload ?? (() => {}); - async function historyLoad() { const historyDiv = document.getElementById("story-list"); historyDiv.textContent = ""; @@ -37,17 +35,5 @@ async function historyLoad() { } window.onload = async () => { - oldOnloadHandler(); - - // render history await historyLoad(); - - /* // clear history button - const button = document.getElementById("clear-button"); - - button.onclick = async () => { - localStorage.removeItem("readingHistory"); - // rerender history - await historyLoad(); - }; */ }; diff --git a/scripts/Index.js b/scripts/Index.js new file mode 100644 index 0000000..179b02a --- /dev/null +++ b/scripts/Index.js @@ -0,0 +1,28 @@ +window.onload = () => { + let favoriteSearches = document.getElementById("favorite-searches"); + let favoriteStories = document.getElementById("favorite-stories"); + + let savedSearches = JSON.parse( + localStorage.getItem("savedSearches") ?? "[]" + ); + let savedStories = JSON.parse(localStorage.getItem("savedStories") ?? "[]"); + + // Broke: JSX + // Woke: + for (const search of savedSearches) { + favoriteSearches.innerHTML += `${search.query} (${search.type} search, sorted by ${ + search.sort + })`; + } + + for (const story of savedStories) { + // prettier-ignore + favoriteStories.innerHTML += +` + +

${story.name}

+
` + } +}; diff --git a/scripts/Search.js b/scripts/Search.js new file mode 100644 index 0000000..327ff37 --- /dev/null +++ b/scripts/Search.js @@ -0,0 +1,49 @@ +window.onload = () => { + console.log("haiiiiiiiii :3"); + const button = document.getElementById("favorite"); + + if (!button) throw "how did your button not init what"; + + let savedSearches = JSON.parse( + localStorage.getItem("savedSearches") ?? "[]" + ); + if ( + savedSearches.filter( + (search) => + search.query === + new URL(document.URL).searchParams.get("query") && + search.type === + new URL(document.URL).searchParams.get("type") && + search.sort === new URL(document.URL).searchParams.get("sort") + ).length > 0 + ) { + button.value = "Unfavorite"; + } + + function handler() { + console.log("haiiiiiiiii :3"); + console.log(button); + if (button?.value === "Favorite") { + savedSearches.push({ + query: new URL(document.URL).searchParams.get("query"), + type: new URL(document.URL).searchParams.get("type") ?? "text", + sort: new URL(document.URL).searchParams.get("sort") ?? "hot" + }); + button.value = "Unfavorite"; + } else if (button?.value === "Unfavorite") { + savedSearches = savedSearches.filter( + (search) => + search.query !== + new URL(document.URL).searchParams.get("query") && + search.type !== + new URL(document.URL).searchParams.get("type") && + search.type !== + new URL(document.URL).searchParams.get("sort") + ); + button.value = "Favorite"; + } + localStorage.setItem("savedSearches", JSON.stringify(savedSearches)); + } + + button.onclick = handler; +}; diff --git a/scripts/StoryContent.js b/scripts/StoryContent.js index d329429..86d2c23 100644 --- a/scripts/StoryContent.js +++ b/scripts/StoryContent.js @@ -1,8 +1,4 @@ -const oldOnloadHandler = window.onload ?? (() => {}); - window.onload = () => { - oldOnloadHandler(); - // Scroll header to current entry document.getElementById("selected-header")?.scrollIntoView({ block: "center", diff --git a/scripts/StoryDetails.js b/scripts/StoryDetails.js index 7cbc5b9..0619f44 100644 --- a/scripts/StoryDetails.js +++ b/scripts/StoryDetails.js @@ -1,7 +1,4 @@ -const oldOnloadHandler = window.onload ?? (() => {}); - window.onload = () => { - oldOnloadHandler(); // Sync to position button const position = localStorage.getItem( new URL(document.URL).searchParams.get("id") + "_progress" diff --git a/src/cached_wattpad.rs b/src/cached_wattpad.rs index 8c167fa..b831ea4 100644 --- a/src/cached_wattpad.rs +++ b/src/cached_wattpad.rs @@ -3,7 +3,7 @@ use anyhow::{Context, Result}; use chrono::{DateTime, Local}; use lazy_static::lazy_static; use std::{collections::HashMap, sync::Mutex}; -use wattpad::{Story}; +use wattpad::Story; lazy_static! { static ref STORY_CACHE: Mutex)>> = diff --git a/src/routes/index.rs b/src/routes/index.rs index ea65df7..22a5923 100644 --- a/src/routes/index.rs +++ b/src/routes/index.rs @@ -11,6 +11,9 @@ pub async fn render() -> Markup { style {(PreEscaped( grass::include!("./css/index.scss") ))} + script {(PreEscaped( + include_str!("../../scripts/Index.js") + ))} ( Header(vec![ HeaderLink { @@ -60,8 +63,12 @@ pub async fn render() -> Markup { } } div .favorites-container { - div .favorite-searches #favorite-searches; - div .favorite-stories #favorite-stories; + div .favorite-searches #favorite-searches { + h2 { "Saved Searches" } + }; + div .favorite-stories #favorite-stories { + h2 { "Saved Stories" } + }; } } } diff --git a/src/routes/search.rs b/src/routes/search.rs index c0a53eb..3522e20 100644 --- a/src/routes/search.rs +++ b/src/routes/search.rs @@ -37,6 +37,9 @@ pub async fn render(Query(params): Query) -> Markup { style {(PreEscaped( grass::include!("./css/index.scss") ))} + script {(PreEscaped( + include_str!("../../scripts/Search.js") + ))} ( Header(vec![ HeaderLink { @@ -107,7 +110,10 @@ pub async fn render(Query(params): Query) -> Markup { } } } - input class="submit-search" type="submit" value="Submit"; + div .search-buttons { + input .submit-search type="submit" value="Submit"; + input #favorite type="button" value="Favorite"; + } } @if let Some(query) = params.query.clone() {