improve display
This commit is contained in:
parent
b56e5a24f1
commit
d0d64cf018
5 changed files with 52 additions and 8 deletions
|
@ -1,9 +1,18 @@
|
||||||
.container {
|
.container {
|
||||||
max-width: 400px;
|
width: 400px;
|
||||||
overflow-wrap: break-word;
|
overflow-wrap: break-word;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
|
||||||
border: 1px solid lightgray;
|
border: 1px solid lightgray;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
padding: 2px 12px;
|
||||||
|
background-color: lightgray;
|
||||||
|
color: gray;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body {
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
}
|
}
|
|
@ -10,15 +10,33 @@ export default function NodeDisplay({ id }: NodeDisplayProps) {
|
||||||
queryKey: ["fetchNode", id],
|
queryKey: ["fetchNode", id],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const resp = await fetch(`http://localhost:5195/node/${id}`);
|
const resp = await fetch(`http://localhost:5195/node/${id}`);
|
||||||
console.log("id", resp);
|
const json = await resp.json();
|
||||||
return "helloge";
|
return json;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const { isSuccess, status, data } = query;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
Node {id}
|
<div className={styles.header}>
|
||||||
<p>{JSON.stringify(query)}</p>
|
<small>ID {id}</small>
|
||||||
|
</div>
|
||||||
|
<div className={styles.body}>
|
||||||
|
{isSuccess ? (
|
||||||
|
<NodeDisplayLoaded id={id} data={data} />
|
||||||
|
) : (
|
||||||
|
<>Status: {status}</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function NodeDisplayLoaded({ id, data }) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
Node {id}
|
||||||
|
<p>{JSON.stringify(data)}</p>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ pub struct AppError(miette::Report);
|
||||||
// Tell axum how to convert `AppError` into a response.
|
// Tell axum how to convert `AppError` into a response.
|
||||||
impl IntoResponse for AppError {
|
impl IntoResponse for AppError {
|
||||||
fn into_response(self) -> Response {
|
fn into_response(self) -> Response {
|
||||||
|
eprintln!("Encountered error: {}", self.0);
|
||||||
(
|
(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
format!("Something went wrong: {}", self.0),
|
format!("Something went wrong: {}", self.0),
|
||||||
|
|
|
@ -56,7 +56,7 @@ async fn main() -> Result<()> {
|
||||||
// build our application with a single route
|
// build our application with a single route
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/", get(|| async { "Hello, World!" }))
|
.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))
|
.route("/journal/get_todays_journal_id", get(get_todays_journal_id))
|
||||||
.layer(ServiceBuilder::new().layer(cors))
|
.layer(ServiceBuilder::new().layer(cors))
|
||||||
.with_state(state);
|
.with_state(state);
|
||||||
|
|
|
@ -13,15 +13,31 @@ pub async fn get_node(
|
||||||
) -> AppResult<Json<Value>> {
|
) -> AppResult<Json<Value>> {
|
||||||
let result = state.db.run_script(
|
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()},
|
btmap! {"node_id".to_owned() => node_id.clone().into()},
|
||||||
ScriptMutability::Immutable,
|
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!({
|
Ok(Json(json!({
|
||||||
"node": node_id,
|
"node": node_id,
|
||||||
|
"extra_data": extra_data,
|
||||||
|
"plaintext": plaintext,
|
||||||
|
"day": day,
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue