have drop-down for public/private in add-watch from search.
This commit is contained in:
parent
5e998dfe86
commit
dab2dc4081
5 changed files with 18 additions and 31 deletions
|
@ -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_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 =
|
const GET_QUEST_QUERY: &str = "select * from watch_quests where user = ? and watch = ?";
|
||||||
"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_WATCH_QUERY: &str = "select * from watches where id = $1";
|
const GET_WATCH_QUERY: &str = "select * from watches where id = $1";
|
||||||
|
|
||||||
|
@ -82,11 +79,6 @@ pub struct SearchQuery {
|
||||||
pub year: Option<i64>,
|
pub year: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Deserialize, PartialEq, Eq)]
|
|
||||||
pub struct StatusQuery {
|
|
||||||
pub public: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
// kinda the main form?
|
// kinda the main form?
|
||||||
#[derive(Debug, Default, Deserialize, PartialEq, Eq)]
|
#[derive(Debug, Default, Deserialize, PartialEq, Eq)]
|
||||||
pub struct PostAddNewWatch {
|
pub struct PostAddNewWatch {
|
||||||
|
@ -106,7 +98,6 @@ pub struct PostAddNewWatch {
|
||||||
pub struct PostAddExistingWatch {
|
pub struct PostAddExistingWatch {
|
||||||
pub watch: String,
|
pub watch: String,
|
||||||
pub public: bool,
|
pub public: bool,
|
||||||
pub watched_already: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-************************************************************************
|
//-************************************************************************
|
||||||
|
@ -139,7 +130,7 @@ pub async fn post_add_new_watch(
|
||||||
let quest = WatchQuest {
|
let quest = WatchQuest {
|
||||||
user: user.id,
|
user: user.id,
|
||||||
public: !form.private,
|
public: !form.private,
|
||||||
watched: form.watched_already,
|
watched: false,
|
||||||
watch: watch_id,
|
watch: watch_id,
|
||||||
};
|
};
|
||||||
add_watch_quest_impl(&pool, &quest)
|
add_watch_quest_impl(&pool, &quest)
|
||||||
|
@ -182,7 +173,7 @@ pub async fn post_add_watch_quest(
|
||||||
user: user.id,
|
user: user.id,
|
||||||
watch: Julid::from_string(&form.watch).unwrap(),
|
watch: Julid::from_string(&form.watch).unwrap(),
|
||||||
public: form.public,
|
public: form.public,
|
||||||
watched: form.watched_already,
|
watched: false,
|
||||||
};
|
};
|
||||||
add_watch_quest_impl(&pool, &quest)
|
add_watch_quest_impl(&pool, &quest)
|
||||||
.await
|
.await
|
||||||
|
@ -288,29 +279,26 @@ pub async fn get_search_watch(
|
||||||
pub async fn get_watch_status(
|
pub async fn get_watch_status(
|
||||||
auth: AuthSession,
|
auth: AuthSession,
|
||||||
State(pool): State<SqlitePool>,
|
State(pool): State<SqlitePool>,
|
||||||
query: Query<StatusQuery>,
|
|
||||||
Path(watch): Path<String>,
|
Path(watch): Path<String>,
|
||||||
) -> Result<impl IntoResponse, ()> {
|
) -> Result<impl IntoResponse, ()> {
|
||||||
if let Some(user) = auth.user {
|
if let Some(user) = auth.user {
|
||||||
let watch = Julid::from_string(&watch).unwrap();
|
let watch = Julid::from_string(&watch).unwrap();
|
||||||
let public = query.public;
|
let quest: Option<WatchQuest> = query_as(GET_QUEST_QUERY)
|
||||||
let quest: Option<WatchQuest> = query_as(GET_QUEST_WITH_PUBLICITY_QUERY)
|
|
||||||
.bind(user.id)
|
.bind(user.id)
|
||||||
.bind(watch)
|
.bind(watch)
|
||||||
.bind(public)
|
|
||||||
.fetch_optional(&pool)
|
.fetch_optional(&pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
tracing::error!("Got error from checking watch status: {e:?}");
|
tracing::error!("Got error from checking watch status: {e:?}");
|
||||||
})?;
|
})?;
|
||||||
|
let checkmark = "✓";
|
||||||
match quest {
|
match quest {
|
||||||
Some(_) => Ok("✓".into_response()),
|
Some(quest) if quest.watched => Ok(format!("{checkmark} watched").into_response()),
|
||||||
None => Ok(AddWatchButton {
|
Some(quest) => {
|
||||||
watch,
|
let public = if quest.public { "public" } else { "private" };
|
||||||
public,
|
Ok(format!("{checkmark} ({public})").into_response())
|
||||||
watched_already: false,
|
|
||||||
}
|
}
|
||||||
.into_response()),
|
None => Ok(AddWatchButton { watch }.into_response()),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok("<a href='/login'>Login to add</a>".into_response())
|
Ok("<a href='/login'>Login to add</a>".into_response())
|
||||||
|
|
|
@ -36,6 +36,4 @@ pub struct AddNewWatchPage {
|
||||||
#[template(path = "elements/add_watch_button.html")]
|
#[template(path = "elements/add_watch_button.html")]
|
||||||
pub struct AddWatchButton {
|
pub struct AddWatchButton {
|
||||||
pub watch: Julid,
|
pub watch: Julid,
|
||||||
pub public: bool,
|
|
||||||
pub watched_already: bool,
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<form id="add-watch-{{self.watch}}">
|
<form id="add-watch-{{self.watch}}">
|
||||||
|
<button hx-post="/add/watch" hx-target="#add-watch-{{watch}}" hx-trigger="click" hx-swap="outerHTML">add</button>
|
||||||
|
<select name="public" id="add-public-watch">
|
||||||
|
<option value="true">public</option>
|
||||||
|
<option value="false">private</option>
|
||||||
|
</select>
|
||||||
<input type="hidden" name="watch" value="{{self.watch}}">
|
<input type="hidden" name="watch" value="{{self.watch}}">
|
||||||
<input type="hidden" name="public" value="{{self.public}}">
|
|
||||||
<input type="hidden" name="watched_already" value="{{self.watched_already}}">
|
|
||||||
<button hx-post="/add/watch" hx-target="#add-watch-{{watch}}" hx-trigger="click" hx-swap="outerHTML">wanna
|
|
||||||
watch?</button>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<th>Title</th>
|
<th>Title</th>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
<th>Year</th>
|
<th>Year</th>
|
||||||
<th>Public watchlist?</th>
|
<th>Watching?</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
<td> {% call m::get_or_default(watch.year(), "when??") -%}</td>
|
<td> {% call m::get_or_default(watch.year(), "when??") -%}</td>
|
||||||
<td>
|
<td>
|
||||||
<span id="add-watch-{{watch.id}}">
|
<span id="add-watch-{{watch.id}}">
|
||||||
<span hx-get="/watch/status/{{watch.id}}?public=true" hx-target="this" hx-trigger="load, reveal"
|
<span hx-get="/watch/status/{{watch.id}}" hx-target="this" hx-trigger="load, reveal"
|
||||||
hx-swap="outerHTML">wanna watch?</span>
|
hx-swap="outerHTML">???</span>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
Loading…
Reference in a new issue