web: add mark as spam buttons
This commit is contained in:
@@ -184,6 +184,52 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
Msg::Noop
|
||||
});
|
||||
}
|
||||
Msg::AddTag(query, tag) => {
|
||||
let search_url = urls::search(&model.query, 0).to_string();
|
||||
orders.skip().perform_cmd(async move {
|
||||
let res: Result<
|
||||
graphql_client::Response<graphql::add_tag_mutation::ResponseData>,
|
||||
gloo_net::Error,
|
||||
> = send_graphql(graphql::AddTagMutation::build_query(
|
||||
graphql::add_tag_mutation::Variables {
|
||||
query: query.clone(),
|
||||
tag: tag.clone(),
|
||||
},
|
||||
))
|
||||
.await;
|
||||
if let Err(e) = res {
|
||||
error!("Failed to add tag {tag} to {query}: {e}");
|
||||
}
|
||||
seed::window()
|
||||
.location()
|
||||
.set_href(&search_url)
|
||||
.expect("failed to change location");
|
||||
Msg::Noop
|
||||
});
|
||||
}
|
||||
Msg::RemoveTag(query, tag) => {
|
||||
let search_url = urls::search(&model.query, 0).to_string();
|
||||
orders.skip().perform_cmd(async move {
|
||||
let res: Result<
|
||||
graphql_client::Response<graphql::remove_tag_mutation::ResponseData>,
|
||||
gloo_net::Error,
|
||||
> = send_graphql(graphql::RemoveTagMutation::build_query(
|
||||
graphql::remove_tag_mutation::Variables {
|
||||
query: query.clone(),
|
||||
tag: tag.clone(),
|
||||
},
|
||||
))
|
||||
.await;
|
||||
if let Err(e) = res {
|
||||
error!("Failed to remove tag {tag} to {query}: {e}");
|
||||
}
|
||||
seed::window()
|
||||
.location()
|
||||
.set_href(&search_url)
|
||||
.expect("failed to change location");
|
||||
Msg::Noop
|
||||
});
|
||||
}
|
||||
|
||||
Msg::FrontPageRequest {
|
||||
query,
|
||||
@@ -311,6 +357,36 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
*selected_threads = results.iter().map(|node| node.thread.clone()).collect();
|
||||
}
|
||||
}
|
||||
Msg::SelectionAddTag(tag) => {
|
||||
if let Context::SearchResult {
|
||||
selected_threads, ..
|
||||
} = &mut model.context
|
||||
{
|
||||
let threads = selected_threads
|
||||
.iter()
|
||||
.map(|tid| format!("thread:{tid}"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ");
|
||||
orders
|
||||
.skip()
|
||||
.perform_cmd(async move { Msg::AddTag(threads, tag) });
|
||||
}
|
||||
}
|
||||
Msg::SelectionRemoveTag(tag) => {
|
||||
if let Context::SearchResult {
|
||||
selected_threads, ..
|
||||
} = &mut model.context
|
||||
{
|
||||
let threads = selected_threads
|
||||
.iter()
|
||||
.map(|tid| format!("thread:{tid}"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ");
|
||||
orders
|
||||
.skip()
|
||||
.perform_cmd(async move { Msg::RemoveTag(threads, tag) });
|
||||
}
|
||||
}
|
||||
Msg::SelectionMarkAsRead => {
|
||||
if let Context::SearchResult {
|
||||
selected_threads, ..
|
||||
@@ -435,6 +511,8 @@ pub enum Msg {
|
||||
SearchQuery(String),
|
||||
|
||||
SetUnread(String, bool),
|
||||
AddTag(String, String),
|
||||
RemoveTag(String, String),
|
||||
|
||||
FrontPageRequest {
|
||||
query: String,
|
||||
@@ -455,6 +533,8 @@ pub enum Msg {
|
||||
|
||||
SelectionSetNone,
|
||||
SelectionSetAll,
|
||||
SelectionAddTag(String),
|
||||
SelectionRemoveTag(String),
|
||||
SelectionMarkAsRead,
|
||||
SelectionMarkAsUnread,
|
||||
SelectionAddThread(String),
|
||||
|
||||
Reference in New Issue
Block a user