Treat email and news posts as distinct types on the frontend and backend

This commit is contained in:
2024-08-31 11:40:06 -07:00
parent 760cec01a8
commit a8d5617cf2
12 changed files with 324 additions and 72 deletions

View File

@@ -858,6 +858,129 @@
"name": "Mutation",
"possibleTypes": null
},
{
"description": null,
"enumValues": null,
"fields": [
{
"args": [],
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "threadId",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
},
{
"args": [],
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "slug",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
},
{
"args": [],
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "site",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
},
{
"args": [],
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "title",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
},
{
"args": [],
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "body",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
},
{
"args": [],
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "url",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
},
{
"args": [],
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "timestamp",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
}
}
}
],
"inputFields": null,
"interfaces": [],
"kind": "OBJECT",
"name": "NewsPost",
"possibleTypes": null
},
{
"description": "Information about pagination in a connection",
"enumValues": null,
@@ -1234,6 +1357,11 @@
"kind": "OBJECT",
"name": "EmailThread",
"ofType": null
},
{
"kind": "OBJECT",
"name": "NewsPost",
"ofType": null
}
]
},

View File

@@ -1,5 +1,15 @@
query ShowThreadQuery($threadId: String!) {
thread(threadId: $threadId) {
__typename ... on NewsPost{
threadId
slug
site
title
body
url
timestamp
# TODO: unread
}
__typename ... on EmailThread{
threadId,
subject

View File

@@ -22,6 +22,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@700&display=swap" rel="stylesheet">
<link data-trunk rel="css" href="static/site-specific.css" />
</head>
<body>

View File

@@ -362,6 +362,12 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
open_messages,
};
}
graphql::show_thread_query::ShowThreadQueryThread::NewsPost(..) => {
model.context = Context::ThreadResult {
thread: data.thread,
open_messages: HashSet::new(),
};
}
}
}
Msg::ShowThreadResult(bad) => {

View File

@@ -19,6 +19,10 @@ pub(super) fn view(model: &Model) -> Node<Msg> {
thread: ShowThreadQueryThread::EmailThread(thread),
open_messages,
} => view::thread(thread, open_messages, show_icon_text),
Context::ThreadResult {
thread: ShowThreadQueryThread::NewsPost(post),
..
} => view::news_post(post, show_icon_text),
Context::SearchResult {
query,
results,

View File

@@ -13,7 +13,7 @@ use crate::{
};
pub(super) fn view(model: &Model) -> Node<Msg> {
log::info!("tablet::view");
log::info!("mobile::view");
let show_icon_text = false;
let content = match &model.context {
Context::None => div![h1!["Loading"]],
@@ -21,6 +21,10 @@ pub(super) fn view(model: &Model) -> Node<Msg> {
thread: ShowThreadQueryThread::EmailThread(thread),
open_messages,
} => view::thread(thread, open_messages, show_icon_text),
Context::ThreadResult {
thread: ShowThreadQueryThread::NewsPost(post),
..
} => view::news_post(post, show_icon_text),
Context::SearchResult {
query,
results,

View File

@@ -1075,3 +1075,107 @@ pub fn view_tags(model: &Model) -> Node<Msg> {
]
]
}
fn news_post(post: &ShowThreadQueryThreadOnNewsPost, show_icon_text: bool) -> Node<Msg> {
// TODO(wathiede): show per-message subject if it changes significantly from top-level subject
let subject = &post.title;
set_title(subject);
let read_thread_id = post.thread_id.clone();
let unread_thread_id = post.thread_id.clone();
div![
C!["thread"],
h3![C!["is-size-5"], subject],
div![
C!["level", "is-mobile"],
div![
C!["level-item"],
div![
C!["buttons", "has-addons"],
button![
C!["button", "mark-read"],
attrs! {At::Title => "Mark as read"},
span![C!["icon", "is-small"], i![C!["far", "fa-envelope-open"]]],
IF!(show_icon_text=>span!["Read"]),
ev(Ev::Click, move |_| Msg::SetUnread(read_thread_id, false)),
],
button![
C!["button", "mark-unread"],
attrs! {At::Title => "Mark as unread"},
span![C!["icon", "is-small"], i![C!["far", "fa-envelope"]]],
IF!(show_icon_text=>span!["Unread"]),
ev(Ev::Click, move |_| Msg::SetUnread(unread_thread_id, true)),
],
],
],
// This would be the holder for spam buttons on emails
div![C!["level-item"], div![]]
],
div![
C!["message"],
div![C!["header"], render_news_post_header(&post)],
div![C!["body", format!("site-{}", post.slug)], raw![&post.body]]
] /* TODO(wathiede): plumb in orignal id
a![
attrs! {At::Href=>api::original(&thread_node.0.as_ref().expect("message missing").id)},
"Original"
],
*/
]
}
fn render_news_post_header(post: &ShowThreadQueryThreadOnNewsPost) -> Node<Msg> {
let from = &post.site;
let from_detail = post.url.clone();
let avatar: Option<String> = None;
//let avatar: Option<String> = Some(String::from("https://bulma.io/images/placeholders/64x64.png"));
let id = post.thread_id.clone();
// TODO: plumb this through
//let is_unread = has_unread(&msg.tags);
let is_unread = true;
let img = render_avatar(avatar, &from);
article![
C!["media"],
figure![C!["media-left"], p![C!["image", "is-64x64"], img]],
div![
C!["media-content"],
div![
C!["content"],
p![
strong![from],
br![],
small![
&from_detail,
" ",
span![
i![C!["far", "fa-clone"]],
ev(Ev::Click, move |e| {
e.stop_propagation();
Msg::CopyToClipboard(from_detail.to_string())
})
]
],
table![tr![td![
attrs! {At::ColSpan=>2},
span![C!["header"], human_age(post.timestamp)]
]]],
],
],
],
div![
C!["media-right"],
span![
C!["read-status"],
i![C![
"far",
if is_unread {
"fa-envelope"
} else {
"fa-envelope-open"
},
]]
],
ev(Ev::Click, move |e| {
e.stop_propagation();
Msg::SetUnread(id, !is_unread)
})
]
]
}

View File

@@ -1,3 +1,4 @@
use log::info;
use seed::{prelude::*, *};
use crate::{
@@ -16,6 +17,10 @@ pub(super) fn view(model: &Model) -> Node<Msg> {
thread: ShowThreadQueryThread::EmailThread(thread),
open_messages,
} => view::thread(thread, open_messages, show_icon_text),
Context::ThreadResult {
thread: ShowThreadQueryThread::NewsPost(post),
..
} => view::news_post(post, show_icon_text),
Context::SearchResult {
query,
results,

View File

@@ -0,0 +1,14 @@
.body.site-saturday-morning-breakfast-cereal {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.body.site-slashdot i {
display: block;
padding-left: 1em;
margin-top: 1em;
margin-bottom: 1em;
border-left: 2px solid #ddd;
}