tidy watches handler, fix quest trigger.

This commit is contained in:
Joe Ardent 2024-01-02 22:31:38 -08:00
parent dab2dc4081
commit 1e0a71f275
3 changed files with 12 additions and 9 deletions

View File

@ -28,7 +28,7 @@ create trigger if not exists update_last_updated_watch_quests
after update on watch_quests after update on watch_quests
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
BEGIN BEGIN
update watch_quests set last_updated = (select unixepoch()) where id=NEW.id; update watch_quests set last_updated = (select unixepoch()) where watch=NEW.watch and user=NEW.user;
END; END;
create trigger if not exists update_last_updated_follows create trigger if not exists update_last_updated_follows

View File

@ -34,6 +34,8 @@ const EMPTY_SEARCH_QUERY_STRUCT: SearchQuery = SearchQuery {
search: None, search: None,
}; };
const CHECKMARK: &str = "✓";
//-************************************************************************ //-************************************************************************
// Error types for Watch creation // Error types for Watch creation
//-************************************************************************ //-************************************************************************
@ -178,7 +180,7 @@ pub async fn post_add_watch_quest(
add_watch_quest_impl(&pool, &quest) add_watch_quest_impl(&pool, &quest)
.await .await
.map_err(|_| AddErrorKind::UnknownDBError)?; .map_err(|_| AddErrorKind::UnknownDBError)?;
let resp = "<style=\"background-color:green\">&#10003;</style>"; let resp = checkmark(form.public);
Ok(resp.into_response()) Ok(resp.into_response())
} else { } else {
let resp = Redirect::to("/login"); let resp = Redirect::to("/login");
@ -291,16 +293,17 @@ pub async fn get_watch_status(
.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 = "&#10003;";
match quest { match quest {
Some(quest) if quest.watched => Ok(format!("{checkmark} watched").into_response()), Some(quest) if quest.watched => Ok(format!("{CHECKMARK} watched").into_response()),
Some(quest) => { Some(quest) => Ok(checkmark(quest.public).into_response()),
let public = if quest.public { "public" } else { "private" };
Ok(format!("{checkmark} ({public})").into_response())
}
None => Ok(AddWatchButton { watch }.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())
} }
} }
fn checkmark(public: bool) -> String {
let public = if public { "public" } else { "private" };
format!("{CHECKMARK} ({public})")
}

View File

@ -1,5 +1,5 @@
<tr id="watchlist-item-{{watch.id}}"> <tr id="watchlist-item-{{watch.id}}">
<td><span class="watchtitle">{{watch.title}}</span></td> <td><span class="watchtitle"><a href="/watch/{{watch.id}}">{{watch.title}}</a></span></td>
<td>{{watch.kind}}</td> <td>{{watch.kind}}</td>
<td> {% call m::get_or_default(watch.year(), "when??") -%}</td> <td> {% call m::get_or_default(watch.year(), "when??") -%}</td>
<td> <td>