web: add bulk read/unerad functionality
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use graphql_client::GraphQLQuery;
|
||||
use log::{error, info};
|
||||
use seed::{app::subs, prelude::*, *};
|
||||
@@ -224,6 +226,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
results: data.search.nodes,
|
||||
count: data.count as usize,
|
||||
pager: data.search.page_info,
|
||||
selected_threads: HashSet::new(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -256,6 +259,54 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
Msg::ShowThreadResult(bad) => {
|
||||
error!("show_thread_query error: {bad:#?}");
|
||||
}
|
||||
Msg::SelectionMarkAsRead => {
|
||||
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::SetUnread(threads, false) });
|
||||
}
|
||||
}
|
||||
Msg::SelectionMarkAsUnread => {
|
||||
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::SetUnread(threads, true) });
|
||||
}
|
||||
}
|
||||
Msg::SelectionAddThread(tid) => {
|
||||
if let Context::SearchResult {
|
||||
selected_threads, ..
|
||||
} = &mut model.context
|
||||
{
|
||||
selected_threads.insert(tid);
|
||||
info!("selected threads {selected_threads:?}");
|
||||
}
|
||||
}
|
||||
Msg::SelectionRemoveThread(tid) => {
|
||||
if let Context::SearchResult {
|
||||
selected_threads, ..
|
||||
} = &mut model.context
|
||||
{
|
||||
selected_threads.remove(&tid);
|
||||
info!("selected threads {selected_threads:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// `Model` describes our app state.
|
||||
@@ -287,6 +338,7 @@ pub enum Context {
|
||||
results: Vec<FrontPageQuerySearchNodes>,
|
||||
count: usize,
|
||||
pager: FrontPageQuerySearchPageInfo,
|
||||
selected_threads: HashSet<String>,
|
||||
},
|
||||
ThreadResult(ShowThreadQueryThread),
|
||||
}
|
||||
@@ -337,4 +389,9 @@ pub enum Msg {
|
||||
ShowThreadResult(
|
||||
Result<graphql_client::Response<graphql::show_thread_query::ResponseData>, gloo_net::Error>,
|
||||
),
|
||||
|
||||
SelectionMarkAsRead,
|
||||
SelectionMarkAsUnread,
|
||||
SelectionAddThread(String),
|
||||
SelectionRemoveThread(String),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user