diff --git a/apps/journal/.gitignore b/apps/journal/.gitignore new file mode 100644 index 0000000..945ce43 --- /dev/null +++ b/apps/journal/.gitignore @@ -0,0 +1 @@ +index.js \ No newline at end of file diff --git a/apps/journal/bun.lockb b/apps/journal/bun.lockb new file mode 100755 index 0000000..4db7ec5 Binary files /dev/null and b/apps/journal/bun.lockb differ diff --git a/apps/journal/index.ts b/apps/journal/index.ts new file mode 100644 index 0000000..08766d5 --- /dev/null +++ b/apps/journal/index.ts @@ -0,0 +1,41 @@ +import type { Context } from "koa"; +import { formatDate } from "date-fns"; +import { uuidv7 } from "uuidv7"; + +export async function today(ctx: Context) { + const date = new Date(); + const day = formatDate(date, "P"); + + const resp = await fetch("http://localhost:3000/node/sql", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + query: ` + select * from node_has_attribute as na + join attribute as a on na.attrName = a.name + where a.name = 'day' and na.string = '${day}'; + `, + parameters: [], + }), + }); + + const { rows } = await resp.json(); + if (rows.length === 0) { + const id = uuidv7(); + const resp = await fetch("http://localhost:3000/node/sql", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + query: ` + begin transaction; + insert into node (id) values (?); + end transaction; + `, + parameters: [id], + }), + }); + const data = await resp.json(); + console.log("Result", data); + } + ctx.body = {}; +} diff --git a/apps/journal/manifest.yml b/apps/journal/manifest.yml new file mode 100644 index 0000000..e4d483f --- /dev/null +++ b/apps/journal/manifest.yml @@ -0,0 +1,10 @@ +name: panorama/journal +code: index.js + +attributes: +- name: day + type: Option + +endpoints: +- route: /today + handler: today \ No newline at end of file diff --git a/apps/journal/package.json b/apps/journal/package.json new file mode 100644 index 0000000..420e379 --- /dev/null +++ b/apps/journal/package.json @@ -0,0 +1,9 @@ +{ + "dependencies": { + "date-fns": "^3.6.0", + "koa": "^2.15.3" + }, + "devDependencies": { + "@types/koa": "^2.15.0" + } +} diff --git a/packages/panorama-daemon/bun.lockb b/packages/panorama-daemon/bun.lockb index d27c17f..a731329 100755 Binary files a/packages/panorama-daemon/bun.lockb and b/packages/panorama-daemon/bun.lockb differ diff --git a/packages/panorama-daemon/src/routes/node.ts b/packages/panorama-daemon/src/routes/node.ts index fae71af..8764b43 100644 --- a/packages/panorama-daemon/src/routes/node.ts +++ b/packages/panorama-daemon/src/routes/node.ts @@ -75,7 +75,13 @@ nodeRouter.put("/", async (ctx) => { ctx.body = { id }; }); -nodeRouter.post("/query", async (ctx) => {}); +// TODO: WILL BE REMOVED BEFORE ALPHA RELEASE +nodeRouter.post("/sql", async (ctx) => { + const body = ctx.request.body; + const { query, parameters } = body; + const rows = await dataSource.query(query, parameters ?? []); + ctx.body = { rows }; +}); nodeRouter.get("/recent", async (ctx) => { const result = await dataSource.query(` diff --git a/ui/src/App.tsx b/ui/src/App.tsx index c1523b3..7925387 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -19,8 +19,6 @@ const queryClient = new QueryClient(); TimeAgo.addDefaultLocale(en); -// export const nodesOpenedAtom = atom>(OrderedSet()); - function App() { const panelsOpened = useAtomValue(panelsOpenedAtom); const { openNode } = usePanelControls(); @@ -31,7 +29,7 @@ function App() { if (panelsOpened.size === 0) { console.log("Opening today's entry."); const resp = await fetch( - `${PANORAMA_DAEMON_URL}/journal/get_todays_journal_id`, + `${PANORAMA_DAEMON_URL}/apps/panorama__journal/today`, ); const data = await resp.json(); console.log("resp", data); diff --git a/ui/src/components/SearchBar.tsx b/ui/src/components/SearchBar.tsx index c746fcd..6abb271 100644 --- a/ui/src/components/SearchBar.tsx +++ b/ui/src/components/SearchBar.tsx @@ -11,7 +11,6 @@ import { } from "@floating-ui/react"; import { useCallback, useEffect, useState } from "react"; import { atom, useAtom, useSetAtom } from "jotai"; -import { useDebounce, useDebouncedCallback } from "use-debounce"; import { usePanelControls } from "../lib/panelManagement"; const searchQueryAtom = atom("");