Skip to content

Commit

Permalink
feat: Initial (barebone) frontend setup
Browse files Browse the repository at this point in the history
  • Loading branch information
kajyr committed Nov 4, 2021
1 parent c1da95e commit c34afd6
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 203 deletions.
1 change: 1 addition & 0 deletions backend/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async function build(opts = {}) {
app.register(require("fastify-log"));
app.register(require("fastify-routes"));

await app.register(require("./config"));
await app.register(require("./journal"));

// Block other api
Expand Down
19 changes: 19 additions & 0 deletions backend/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { filename } from '../dal';

export default function (fastify, opts, done) {
const routes = [
{
method: "GET",
url: `/api/bootstrap`,
handler: async function () {
return { file: filename };
},
},
];

for (const route of routes) {
fastify.route(route);
}

done();
}
4 changes: 4 additions & 0 deletions backend/dal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const path = require("path");
const fullFile = process.env.LEDGER_FILE;

export const filename = path.basename(fullFile);
2 changes: 1 addition & 1 deletion backend/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require("dotenv").config({ path: "../" });
require("dotenv");

import colors from 'colors/safe';

Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"luxon": "^2.0.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-query": "^3.31.0",
"react-router-dom": "^6.0.0",
"stream-browserify": "^3.0.0",
"styled-components": "^5.2.0",
Expand Down
32 changes: 32 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { FC } from 'react';
import { useQuery } from 'react-query';
import { Route, Routes } from 'react-router-dom';

import Loader from 'atoms/Loader';

import Page from 'templates/Page';

import Dashboard from 'pages/dashboard';

const App: FC = () => {
const { isLoading, error, data } = useQuery("bootstrap", () =>
fetch("/api/bootstrap").then((res) => res.json())
);

console.log(isLoading, data);
if (isLoading) {
return <Loader />;
}

return (
<>
<Page filename={data.file}>
<Routes>
<Route path="/" element={<Dashboard />} />
</Routes>
</Page>
</>
);
};

export default App;
20 changes: 20 additions & 0 deletions frontend/src/atoms/Loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { FC } from 'react';

import { createStyles, Loader as MLoader } from '@mantine/core';

const useStyles = createStyles(() => {
return {
wrapper: { textAlign: "center", margin: "1em 0" },
};
});

const Loader: FC = () => {
const { classes } = useStyles();
return (
<div className={classes.wrapper}>
<MLoader />
</div>
);
};

export default Loader;
5 changes: 5 additions & 0 deletions frontend/src/globalstyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ const GlobalStyle = createGlobalStyle`
-webkit-font-smoothing: antialiased;
}
body {
background: #ecf0f5;
padding: 1em;
}
* {
box-sizing: border-box;
}
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<html>
<head>
<title>Logbook</title>
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro" rel="stylesheet" />
<title>kLedger UI</title>
<link
href="https://fonts.googleapis.com/css?family=Source+Sans+Pro"
rel="stylesheet"
/>
</head>

<body>
Expand Down
18 changes: 13 additions & 5 deletions frontend/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import React from 'react';
import { render } from 'react-dom';
import { QueryClient, QueryClientProvider } from 'react-query';
import { BrowserRouter, Route, Routes } from 'react-router-dom';

import Page from 'templates/Page';

import Dashboard from 'pages/dashboard';

import App from './App';
import GlobalStyle from './globalstyle';
import FourOhFour from './pages/four-oh-four';

const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
},
},
});

render(
<>
<GlobalStyle />
<Page>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<Routes>
<Route path="/404" element={<FourOhFour />} />
<Route path="/" element={<Dashboard />} />
<Route path="/*" element={<App />} />
</Routes>
</BrowserRouter>
</Page>
</QueryClientProvider>
</>,
document.getElementById("rroot")
);
26 changes: 19 additions & 7 deletions frontend/src/templates/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import React, { FC } from 'react';
import styled from 'styled-components';

const Main = styled.main`
const Wrapper = styled.div`
display: flex;
flex-direction: column;
min-height: 100vh;
header {
margin-bottom: 15px;
h1 {
margin-bottom: 5px;
}
}
`;

const Body = styled.div`
padding: 1em;
const Body = styled.main`
flex: 1;
background: #ecf0f5;
`;

const Page: FC = ({ children }) => (
<Main>
const Page: FC<{ filename: string }> = ({ filename, children }) => (
<Wrapper>
<header>
<h1>kLedger UI</h1>
<div>File in use: {filename}</div>
</header>
<Body>{children}</Body>
</Main>
<footer>github</footer>
</Wrapper>
);

export default Page;
Loading

0 comments on commit c34afd6

Please sign in to comment.