improve display

This commit is contained in:
Michael Zhang 2024-05-25 05:37:25 -05:00
parent b56e5a24f1
commit d0d64cf018
5 changed files with 52 additions and 8 deletions

View file

@ -1,9 +1,18 @@
.container {
max-width: 400px;
width: 400px;
overflow-wrap: break-word;
overflow-y: auto;
border: 1px solid lightgray;
border-radius: 4px;
}
.header {
padding: 2px 12px;
background-color: lightgray;
color: gray;
}
.body {
padding: 12px;
}

View file

@ -10,15 +10,33 @@ export default function NodeDisplay({ id }: NodeDisplayProps) {
queryKey: ["fetchNode", id],
queryFn: async () => {
const resp = await fetch(`http://localhost:5195/node/${id}`);
console.log("id", resp);
return "helloge";
const json = await resp.json();
return json;
},
});
const { isSuccess, status, data } = query;
return (
<div className={styles.container}>
Node {id}
<p>{JSON.stringify(query)}</p>
<div className={styles.header}>
<small>ID {id}</small>
</div>
<div className={styles.body}>
{isSuccess ? (
<NodeDisplayLoaded id={id} data={data} />
) : (
<>Status: {status}</>
)}
</div>
</div>
);
}
function NodeDisplayLoaded({ id, data }) {
return (
<>
Node {id}
<p>{JSON.stringify(data)}</p>
</>
);
}

View file

@ -12,6 +12,7 @@ pub struct AppError(miette::Report);
// Tell axum how to convert `AppError` into a response.
impl IntoResponse for AppError {
fn into_response(self) -> Response {
eprintln!("Encountered error: {}", self.0);
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("Something went wrong: {}", self.0),

View file

@ -56,7 +56,7 @@ async fn main() -> Result<()> {
// build our application with a single route
let app = Router::new()
.route("/", get(|| async { "Hello, World!" }))
.route("/node/{id}", get(get_node))
.route("/node/:id", get(get_node))
.route("/journal/get_todays_journal_id", get(get_todays_journal_id))
.layer(ServiceBuilder::new().layer(cors))
.with_state(state);

View file

@ -13,15 +13,31 @@ pub async fn get_node(
) -> AppResult<Json<Value>> {
let result = state.db.run_script(
"
?[extra_data] := *node{ id, extra_data }, id = $node_id
j[plaintext] := *journal{ node_id, plaintext }, node_id = $node_id
j[plaintext] := not *journal{ node_id }, node_id = $node_id, plaintext = null
jd[day] := *journal_days{ node_id, day }, node_id = $node_id
jd[day] := not *journal_days{ node_id }, node_id = $node_id, day = null
?[extra_data, plaintext, day] := *node{ id, extra_data },
j[plaintext],
jd[day],
id = $node_id
:limit 1
",
btmap! {"node_id".to_owned() => node_id.clone().into()},
ScriptMutability::Immutable,
)?;
println!("REUSLT {:?}", result);
let row = &result.rows[0];
let extra_data = row[0].get_str();
let plaintext = row[1].get_str();
let day = row[2].get_str();
Ok(Json(json!({
"node": node_id,
"extra_data": extra_data,
"plaintext": plaintext,
"day": day,
})))
}