Skip to content

Commit

Permalink
display dummy public key from server
Browse files Browse the repository at this point in the history
  • Loading branch information
jadehopepunk committed Jan 2, 2025
1 parent df67aef commit 5b67155
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 4 deletions.
Binary file added backend/main.sqlite-shm
Binary file not shown.
Empty file added backend/main.sqlite-wal
Empty file.
1 change: 1 addition & 0 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ async fn rocket() -> _ {
.mount("/hello", routes![hello])
.mount("/api/this_site", routes::this_site::routes())
.mount("/api/this_region", routes::this_region::routes())
.mount("/api/this_node", routes::this_node::routes())
.mount("/api/apps", routes::apps::routes())
}
1 change: 1 addition & 0 deletions backend/src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod apps;
pub mod this_node;
pub mod this_region;
pub mod this_site;
26 changes: 26 additions & 0 deletions backend/src/routes/this_node.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use rocket::serde::json::Json;
use rocket::serde::{Deserialize, Serialize};
use rocket::Route;
use thiserror::Error;

#[derive(sqlx::FromRow, Serialize, Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct NodeDetails {
pub public_key: String,
}

#[derive(Debug, Error, Responder)]
pub enum ThisNodeError {}

#[get("/", format = "json")]
async fn show() -> Result<Json<NodeDetails>, ThisNodeError> {
let dummy_details = NodeDetails {
public_key: "xxx".to_string(),
};

Ok(Json(dummy_details))
}

pub fn routes() -> Vec<Route> {
routes![show]
}
4 changes: 4 additions & 0 deletions frontend/src/contexts/this_site/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ export default class ThisSiteApi extends BaseApi {
description,
})
}

showNode(): Promise<ApiResult<any, any>> {
return this.apiCall("this_node")
}
}
49 changes: 45 additions & 4 deletions frontend/src/contexts/this_site/pages/ThisNode.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
import { Box, Text } from "@chakra-ui/react"
import { VStack, Text, Table } from "@chakra-ui/react"
import { useEffect, useState } from "react"
import ThisSiteApi from "../api"
import { NodeDetails } from "../types"

const api = new ThisSiteApi()

const getNode = async (): Promise<NodeDetails | null> => {
const result = await api.showNode()
if ("Ok" in result) return result.Ok
return null
}

export default function ThisNode() {
const [node, setNode] = useState<NodeDetails | null>(null)

const fetchNode = async () => {
const node = await getNode()
console.log("fetched node", node)
setNode(node)
}

useEffect(() => {
fetchNode()
}, [])

if (!node) {
return <></>
}

return (
<Box>
<Text>This node</Text>
</Box>
<VStack alignItems={"stretch"}>
<Text textStyle="xl">This P2Panda Node</Text>
<Table.Root variant="line">
<Table.Header>
<Table.Row>
<Table.ColumnHeader>Key</Table.ColumnHeader>
<Table.ColumnHeader>Value</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>Public key</Table.Cell>
<Table.Cell>{node.public_key}</Table.Cell>
</Table.Row>
</Table.Body>
</Table.Root>
</VStack>
)
}
4 changes: 4 additions & 0 deletions frontend/src/contexts/this_site/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ export type RegionDetails = {
name: string
description: string
}

export type NodeDetails = {
public_key: string
}

0 comments on commit 5b67155

Please sign in to comment.