snooze: add UI elements and DB for snooze functionality
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
use chrono::Utc;
|
||||
use gloo_net::{http::Request, Error};
|
||||
use graphql_client::GraphQLQuery;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
type DateTime = chrono::DateTime<Utc>;
|
||||
// The paths are relative to the directory where your `Cargo.toml` is located.
|
||||
// Both json and the GraphQL schema language are supported as sources for the schema
|
||||
#[derive(GraphQLQuery)]
|
||||
@@ -52,6 +54,14 @@ pub struct AddTagMutation;
|
||||
)]
|
||||
pub struct RemoveTagMutation;
|
||||
|
||||
#[derive(GraphQLQuery)]
|
||||
#[graphql(
|
||||
schema_path = "graphql/schema.json",
|
||||
query_path = "graphql/snooze.graphql",
|
||||
response_derives = "Debug"
|
||||
)]
|
||||
pub struct SnoozeMutation;
|
||||
|
||||
#[derive(GraphQLQuery)]
|
||||
#[graphql(
|
||||
schema_path = "graphql/schema.json",
|
||||
|
||||
@@ -260,8 +260,28 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
Msg::GoToSearchResults
|
||||
});
|
||||
}
|
||||
Msg::Snooze(message_id, snooze_time) => {
|
||||
info!("TODO: Snoozing {message_id} until {snooze_time}");
|
||||
Msg::Snooze(query, wake_time) => {
|
||||
let is_catchup = model.catchup.is_some();
|
||||
orders.skip().perform_cmd(async move {
|
||||
let res: Result<
|
||||
graphql_client::Response<graphql::snooze_mutation::ResponseData>,
|
||||
gloo_net::Error,
|
||||
> = send_graphql(graphql::SnoozeMutation::build_query(
|
||||
graphql::snooze_mutation::Variables {
|
||||
query: query.clone(),
|
||||
wake_time,
|
||||
},
|
||||
))
|
||||
.await;
|
||||
if let Err(e) = res {
|
||||
error!("Failed to snooze {query} until {wake_time}: {e}");
|
||||
}
|
||||
if is_catchup {
|
||||
Msg::CatchupMarkAsRead
|
||||
} else {
|
||||
Msg::GoToSearchResults
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Msg::FrontPageRequest {
|
||||
|
||||
@@ -727,15 +727,19 @@ fn render_open_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Node<
|
||||
C!["flex", "p-4", "bg-neutral-800"],
|
||||
div![avatar],
|
||||
div![
|
||||
C!["px-4", "mr-auto"],
|
||||
span![
|
||||
C!["font-semibold", "text-sm"],
|
||||
from_detail.as_ref().map(|addr| attrs! {
|
||||
At::Title => addr
|
||||
}),
|
||||
&from,
|
||||
" ",
|
||||
from_detail.as_ref().map(|text| copy_text_widget(&text))
|
||||
C!["px-4", "flex-1"],
|
||||
div![
|
||||
C!["flex"],
|
||||
div![
|
||||
C!["font-semibold", "text-sm", "flex-1"],
|
||||
from_detail.as_ref().map(|addr| attrs! {
|
||||
At::Title => addr
|
||||
}),
|
||||
&from,
|
||||
" ",
|
||||
from_detail.as_ref().map(|text| copy_text_widget(&text))
|
||||
],
|
||||
snooze_buttons(&id),
|
||||
],
|
||||
IF!(!msg.to.is_empty() =>div![
|
||||
C!["text-xs"],
|
||||
@@ -799,43 +803,6 @@ fn render_open_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Node<
|
||||
})
|
||||
]
|
||||
]),
|
||||
div![
|
||||
C!["text-xs"],
|
||||
span!["Snooze:"],
|
||||
" ",
|
||||
a![
|
||||
"1d",
|
||||
ev(Ev::Click, {
|
||||
let id = id.clone();
|
||||
move |e| {
|
||||
e.stop_propagation();
|
||||
Msg::Snooze(id, Utc::now() + chrono::Days::new(1))
|
||||
}
|
||||
})
|
||||
],
|
||||
" ",
|
||||
a![
|
||||
"7d",
|
||||
ev(Ev::Click, {
|
||||
let id = id.clone();
|
||||
move |e| {
|
||||
e.stop_propagation();
|
||||
Msg::Snooze(id, Utc::now() + chrono::Days::new(7))
|
||||
}
|
||||
})
|
||||
],
|
||||
" ",
|
||||
a![
|
||||
"6m",
|
||||
ev(Ev::Click, {
|
||||
let id = id.clone();
|
||||
move |e| {
|
||||
e.stop_propagation();
|
||||
Msg::Snooze(id, Utc::now() + chrono::Days::new(180))
|
||||
}
|
||||
})
|
||||
],
|
||||
]
|
||||
],
|
||||
span![
|
||||
C!["text-right"],
|
||||
@@ -1203,6 +1170,7 @@ fn thread(
|
||||
let open = open_messages.contains(&msg.id);
|
||||
message_render(&msg, open)
|
||||
});
|
||||
let id = &thread.thread_id;
|
||||
let read_thread_id = thread.thread_id.clone();
|
||||
let unread_thread_id = thread.thread_id.clone();
|
||||
let spam_add_thread_id = thread.thread_id.clone();
|
||||
@@ -1631,9 +1599,13 @@ fn render_news_post_header(post: &ShowThreadQueryThreadOnNewsPost) -> Node<Msg>
|
||||
C!["flex", "p-4", "bg-neutral-800"],
|
||||
div![favicon],
|
||||
div![
|
||||
C!["px-4", "mr-auto"],
|
||||
C!["px-4", "mr-auto", "flex-1"],
|
||||
div![
|
||||
div![C!["font-semibold", "text-sm"], from],
|
||||
div![
|
||||
C!["flex"],
|
||||
div![C!["font-semibold", "text-sm", "flex-1"], from],
|
||||
snooze_buttons(&id),
|
||||
],
|
||||
div![
|
||||
C!["flex", "gap-2", "pt-2", "text-sm"],
|
||||
a![
|
||||
@@ -1728,3 +1700,45 @@ fn click_to_top() -> Node<Msg> {
|
||||
ev(Ev::Click, |_| Msg::ScrollToTop)
|
||||
]
|
||||
}
|
||||
|
||||
fn snooze_buttons(id: &str) -> Node<Msg> {
|
||||
div![
|
||||
span![C!["px-2"], "⏰"],
|
||||
button![
|
||||
tw_classes::button(),
|
||||
C!["rounded-r-none"],
|
||||
"1d",
|
||||
ev(Ev::Click, {
|
||||
let id = id.to_string();
|
||||
move |e| {
|
||||
e.stop_propagation();
|
||||
Msg::Snooze(id, Utc::now() + chrono::Days::new(1))
|
||||
}
|
||||
})
|
||||
],
|
||||
button![
|
||||
tw_classes::button(),
|
||||
C!["rounded-none"],
|
||||
"7d",
|
||||
ev(Ev::Click, {
|
||||
let id = id.to_string();
|
||||
move |e| {
|
||||
e.stop_propagation();
|
||||
Msg::Snooze(id, Utc::now() + chrono::Days::new(7))
|
||||
}
|
||||
})
|
||||
],
|
||||
button![
|
||||
tw_classes::button(),
|
||||
C!["rounded-l-none"],
|
||||
"6m",
|
||||
ev(Ev::Click, {
|
||||
let id = id.to_string();
|
||||
move |e| {
|
||||
e.stop_propagation();
|
||||
Msg::Snooze(id, Utc::now() + chrono::Days::new(180))
|
||||
}
|
||||
})
|
||||
],
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user