random quote for the dashboard
This commit is contained in:
@@ -127,6 +127,18 @@ impl Quote {
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
pub fn get_random(conn: &Connection) -> Result<Option<Quote>, QuoteError> {
|
||||
let id: Option<Uuid> = conn
|
||||
.query_row("SELECT id FROM quotes ORDER BY RANDOM() LIMIT 1", (), |r| {
|
||||
r.get(0)
|
||||
})
|
||||
.optional()?;
|
||||
|
||||
match id {
|
||||
Some(id) => Ok(Some(Self::get_by_id(conn, id)?)),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
pub fn get_chronological_offset(
|
||||
conn: &Connection,
|
||||
offset: i64,
|
||||
|
||||
@@ -29,6 +29,10 @@ pub async fn page(req: Request) -> Result<Markup, CompositeError> {
|
||||
Some(_) => Quote::get_newest(&conn)?,
|
||||
None => Quote::get_newest_public(&conn)?,
|
||||
};
|
||||
let random_quote = match u {
|
||||
Some(_) => Quote::get_random(&conn)?,
|
||||
None => None,
|
||||
};
|
||||
|
||||
Ok(base(
|
||||
"Dashboard | Mnemosyne",
|
||||
@@ -38,21 +42,26 @@ pub async fn page(req: Request) -> Result<Markup, CompositeError> {
|
||||
div class="mx-auto max-w-4xl px-2 mt-4 grid grid-cols-1 --sm:grid-cols-2 gap-4" {
|
||||
div class="flex flex-col" {
|
||||
p {"Newest Quote"}
|
||||
@if let Some(q) = newest_quote {
|
||||
@if let Some(q) = &newest_quote {
|
||||
p class="text-neutral-500 font-light mb-4" {
|
||||
"This just in! This quote was added "
|
||||
(format_time_ago(q.get_creation_timestamp())) " ago."
|
||||
}
|
||||
div class="flex-1 [&>div]:h-full" {(quote(&q))}
|
||||
div class="flex-1 [&>div]:h-full" {(quote(q))}
|
||||
} @else {
|
||||
p class="text-neutral-500 font-light mb-4" {"No quotes yet."}
|
||||
}
|
||||
}
|
||||
// div class="flex flex-col" {
|
||||
// p {"Quote of the Day"} // maybe "Quote of the Moment" instead? idk, this algorithm needs to be crazy
|
||||
// p class="text-neutral-500 font-light mb-4" {"This quote was voiced a year ago today."}
|
||||
// div class="flex-1 [&>div]:h-full" {(quote(&sample_quote_2()))}
|
||||
// }
|
||||
@if let Some(q) = random_quote {
|
||||
div class="flex flex-col" {
|
||||
p {"Random Quote"}
|
||||
p class="text-neutral-500 font-light mb-4" {
|
||||
"This quote was added "
|
||||
(format_time_ago(q.get_creation_timestamp())) " ago."
|
||||
}
|
||||
div class="flex-1 [&>div]:h-full" {(quote(&q))}
|
||||
}
|
||||
}
|
||||
}
|
||||
div class="mx-auto max-w-4xl px-2 mt-4" {
|
||||
p class="mb-2" {"Quick access"}
|
||||
|
||||
Reference in New Issue
Block a user