diff --git a/src/watches/handlers.rs b/src/watches/handlers.rs index 80e53e0..0798c94 100644 --- a/src/watches/handlers.rs +++ b/src/watches/handlers.rs @@ -19,10 +19,7 @@ use crate::{ //-************************************************************************ const GET_SAVED_WATCHES_QUERY: &str = "select * from watches inner join watch_quests quests on quests.user = $1 and quests.watch = watches.id"; -const GET_QUEST_WITH_PUBLICITY_QUERY: &str = - "select * from watch_quests where user = ? and watch = ? and public = ?"; -const GET_QUEST_WITH_WATCHED_QUERY: &str = - "select * from watch_quests where user = ? and watch = ? and watched = ?"; +const GET_QUEST_QUERY: &str = "select * from watch_quests where user = ? and watch = ?"; const GET_WATCH_QUERY: &str = "select * from watches where id = $1"; @@ -82,11 +79,6 @@ pub struct SearchQuery { pub year: Option, } -#[derive(Debug, Default, Clone, Deserialize, PartialEq, Eq)] -pub struct StatusQuery { - pub public: bool, -} - // kinda the main form? #[derive(Debug, Default, Deserialize, PartialEq, Eq)] pub struct PostAddNewWatch { @@ -106,7 +98,6 @@ pub struct PostAddNewWatch { pub struct PostAddExistingWatch { pub watch: String, pub public: bool, - pub watched_already: bool, } //-************************************************************************ @@ -139,7 +130,7 @@ pub async fn post_add_new_watch( let quest = WatchQuest { user: user.id, public: !form.private, - watched: form.watched_already, + watched: false, watch: watch_id, }; add_watch_quest_impl(&pool, &quest) @@ -182,7 +173,7 @@ pub async fn post_add_watch_quest( user: user.id, watch: Julid::from_string(&form.watch).unwrap(), public: form.public, - watched: form.watched_already, + watched: false, }; add_watch_quest_impl(&pool, &quest) .await @@ -288,29 +279,26 @@ pub async fn get_search_watch( pub async fn get_watch_status( auth: AuthSession, State(pool): State, - query: Query, Path(watch): Path, ) -> Result { if let Some(user) = auth.user { let watch = Julid::from_string(&watch).unwrap(); - let public = query.public; - let quest: Option = query_as(GET_QUEST_WITH_PUBLICITY_QUERY) + let quest: Option = query_as(GET_QUEST_QUERY) .bind(user.id) .bind(watch) - .bind(public) .fetch_optional(&pool) .await .map_err(|e| { tracing::error!("Got error from checking watch status: {e:?}"); })?; + let checkmark = "✓"; match quest { - Some(_) => Ok("✓".into_response()), - None => Ok(AddWatchButton { - watch, - public, - watched_already: false, + Some(quest) if quest.watched => Ok(format!("{checkmark} watched").into_response()), + Some(quest) => { + let public = if quest.public { "public" } else { "private" }; + Ok(format!("{checkmark} ({public})").into_response()) } - .into_response()), + None => Ok(AddWatchButton { watch }.into_response()), } } else { Ok("Login to add".into_response()) diff --git a/src/watches/templates.rs b/src/watches/templates.rs index 7e11b17..15529ce 100644 --- a/src/watches/templates.rs +++ b/src/watches/templates.rs @@ -36,6 +36,4 @@ pub struct AddNewWatchPage { #[template(path = "elements/add_watch_button.html")] pub struct AddWatchButton { pub watch: Julid, - pub public: bool, - pub watched_already: bool, } diff --git a/templates/elements/add_watch_button.html b/templates/elements/add_watch_button.html index abf012b..fbd05b3 100644 --- a/templates/elements/add_watch_button.html +++ b/templates/elements/add_watch_button.html @@ -1,7 +1,8 @@
+ + - - -
diff --git a/templates/search_watches_page.html b/templates/search_watches_page.html index 6493fcf..c082c4c 100644 --- a/templates/search_watches_page.html +++ b/templates/search_watches_page.html @@ -13,7 +13,7 @@ Title Type Year - Public watchlist? + Watching? diff --git a/templates/watch-search-result.html b/templates/watch-search-result.html index 1ffeca4..37022b0 100644 --- a/templates/watch-search-result.html +++ b/templates/watch-search-result.html @@ -4,8 +4,8 @@ {% call m::get_or_default(watch.year(), "when??") -%} - wanna watch? + ???