web: add non-functional graphql.
This commit is contained in:
@@ -28,6 +28,7 @@ serde_json = { version = "1.0.93", features = ["unbounded_depth"] }
|
||||
wasm-timer = "0.2.5"
|
||||
css-inline = "0.8.5"
|
||||
chrono = "0.4.31"
|
||||
graphql_client = "0.13.0"
|
||||
|
||||
[package.metadata.wasm-pack.profile.release]
|
||||
wasm-opt = ['-Os']
|
||||
|
||||
23
web/graphql/front_page.graphql
Normal file
23
web/graphql/front_page.graphql
Normal file
@@ -0,0 +1,23 @@
|
||||
query FrontPageQuery($query: [String!], $first: [Int], $after: [String]) {
|
||||
count(query: $query)
|
||||
search(query: $query, first: $first, after: $after) {
|
||||
pageInfo {
|
||||
hasPreviousPage
|
||||
hasNextPage
|
||||
startCursor
|
||||
endCursor
|
||||
}
|
||||
nodes {
|
||||
thread
|
||||
timestamp
|
||||
subject
|
||||
authors
|
||||
tags
|
||||
}
|
||||
}
|
||||
tags {
|
||||
name
|
||||
bgColor
|
||||
fgColor
|
||||
}
|
||||
}
|
||||
35
web/src/graphql.rs
Normal file
35
web/src/graphql.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use graphql_client::GraphQLQuery;
|
||||
use seed::{
|
||||
fetch,
|
||||
fetch::{Header, Method, Request},
|
||||
};
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
|
||||
// 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)]
|
||||
#[graphql(
|
||||
schema_path = "graphql/schema.json",
|
||||
query_path = "graphql/front_page.graphql",
|
||||
response_derives = "Debug"
|
||||
)]
|
||||
pub struct FrontPageQuery;
|
||||
|
||||
async fn send_graphql<Body, Resp>(body: Body) -> fetch::Result<graphql_client::Response<Resp>>
|
||||
where
|
||||
Body: Serialize,
|
||||
Resp: DeserializeOwned + 'static,
|
||||
{
|
||||
use web_sys::RequestMode;
|
||||
|
||||
Request::new("/graphql")
|
||||
.method(Method::Post)
|
||||
.header(Header::content_type("application/json"))
|
||||
.mode(RequestMode::Cors)
|
||||
.json(&body)?
|
||||
.fetch()
|
||||
.await?
|
||||
.check_status()?
|
||||
.json()
|
||||
.await
|
||||
}
|
||||
@@ -7,7 +7,7 @@ use std::{
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
use chrono::{DateTime, Datelike, Duration, Local, Utc};
|
||||
use chrono::{DateTime, Duration, Local, Utc};
|
||||
use itertools::Itertools;
|
||||
use log::{debug, error, info, Level};
|
||||
use notmuch::{Content, Part, Thread, ThreadNode, ThreadSet};
|
||||
@@ -15,6 +15,8 @@ use seed::{prelude::*, *};
|
||||
use serde::de::Deserialize;
|
||||
use wasm_timer::Instant;
|
||||
|
||||
mod graphql;
|
||||
|
||||
const SEARCH_RESULTS_PER_PAGE: usize = 20;
|
||||
|
||||
// ------ ------
|
||||
@@ -760,6 +762,8 @@ fn view_footer(render_time_ms: u128) -> Node<Msg> {
|
||||
}
|
||||
|
||||
fn view_desktop(model: &Model) -> Node<Msg> {
|
||||
// TODO(wathiede): add sidebar showing tags, use https://bulma.io/documentation/components/menu/#docsNav
|
||||
// Do two queries, one without `unread` so it loads fast, then a second with unread.
|
||||
let content = match &model.context {
|
||||
Context::None => div![h1!["Loading"]],
|
||||
Context::Thread(thread_set) => view_thread(thread_set),
|
||||
|
||||
Reference in New Issue
Block a user