aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-02-05 15:18:48 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2022-02-05 15:18:48 +0200
commit7d78bf4d2111af87636069ee2d35d6323ffc96be (patch)
treec0d8d88e68c8d6dd92bcb2ba7e39f0ce21bc11eb /src
parent232c1e536d22dbb46b7d11fc389695d440343495 (diff)
Get stuff running
Diffstat (limited to 'src')
-rw-r--r--src/App.css42
-rw-r--r--src/App.module.css35
-rw-r--r--src/App.tsx69
-rw-r--r--src/api.ts50
-rw-r--r--src/favicon.pngbin0 -> 6482 bytes
-rw-r--r--src/favicon.svg15
-rw-r--r--src/index.css33
-rw-r--r--src/main.tsx10
8 files changed, 148 insertions, 106 deletions
diff --git a/src/App.css b/src/App.css
deleted file mode 100644
index 8da3fde..0000000
--- a/src/App.css
+++ /dev/null
@@ -1,42 +0,0 @@
-.App {
- text-align: center;
-}
-
-.App-logo {
- height: 40vmin;
- pointer-events: none;
-}
-
-@media (prefers-reduced-motion: no-preference) {
- .App-logo {
- animation: App-logo-spin infinite 20s linear;
- }
-}
-
-.App-header {
- background-color: #282c34;
- min-height: 100vh;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- font-size: calc(10px + 2vmin);
- color: white;
-}
-
-.App-link {
- color: #61dafb;
-}
-
-@keyframes App-logo-spin {
- from {
- transform: rotate(0deg);
- }
- to {
- transform: rotate(360deg);
- }
-}
-
-button {
- font-size: calc(10px + 2vmin);
-}
diff --git a/src/App.module.css b/src/App.module.css
new file mode 100644
index 0000000..0bf5f42
--- /dev/null
+++ b/src/App.module.css
@@ -0,0 +1,35 @@
+.app {
+}
+
+.header {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ justify-content: center;
+ font-size: var(--font-xxl);
+ width: auto;
+ margin: auto;
+}
+
+.iconRow {
+ display: flex;
+ flex-flow: row nowrap;
+ align-items: center;
+ margin-bottom: -10px;
+}
+
+.iconRow img {
+ width: auto;
+ height: 40px;
+ margin-right: 10px;
+}
+
+.header small {
+ font-style: italic;
+ font-size: var(--font-s);
+ font-weight: 400;
+}
+
+.error {
+ color: var(--red)
+} \ No newline at end of file
diff --git a/src/App.tsx b/src/App.tsx
index 3d9bd71..5645dcc 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,43 +1,40 @@
-import { useState } from 'react'
-import logo from './logo.svg'
-import './App.css'
+import { useSnippets } from "./api"
+import styles from "./App.module.css"
+import icon from "./favicon.png"
-function App() {
- const [count, setCount] = useState(0)
+const App = () => {
+ const snippets = useSnippets()
+
+ const renderSnippets = () => {
+ if (snippets.type === "failed") {
+ return <div className={styles.error}>
+ Unexpected error loading snippets. See console for details.
+ </div>
+ }
+
+ if (snippets.type === "loading") {
+ return <div>Loading snippets...</div>
+ }
+
+ return snippets.data.map((snippet) =>
+ <div key={snippet.id}>{snippet.title}</div>,
+ )
+ }
return (
- <div className="App">
- <header className="App-header">
- <img src={logo} className="App-logo" alt="logo" />
- <p>Hello Vite + React!</p>
- <p>
- <button type="button" onClick={() => setCount((count) => count + 1)}>
- count is: {count}
- </button>
- </p>
- <p>
- Edit <code>App.tsx</code> and save to test HMR updates.
- </p>
- <p>
- <a
- className="App-link"
- href="https://reactjs.org"
- target="_blank"
- rel="noopener noreferrer"
- >
- Learn React
- </a>
- {' | '}
- <a
- className="App-link"
- href="https://vitejs.dev/guide/features.html"
- target="_blank"
- rel="noopener noreferrer"
- >
- Vite Docs
- </a>
- </p>
+ <div className={styles.app}>
+ <header className={styles.header}>
+ <div className={styles.iconRow}>
+ <img src={icon} />
+ <strong>SLAM</strong>
+ </div>
+ <div className={styles.sloganRow}>
+ <small>A Mere Stack Language</small>
+ </div>
</header>
+ <div>
+ {renderSnippets()}
+ </div>
</div>
)
}
diff --git a/src/api.ts b/src/api.ts
new file mode 100644
index 0000000..7fd9e64
--- /dev/null
+++ b/src/api.ts
@@ -0,0 +1,50 @@
+import useSWR, { SWRResponse } from "swr"
+
+const API_URL = import.meta.env.VITE_API_URL
+
+const fetcher = (path: string) => fetch(`${API_URL}${path}`)
+ .then(res => res.json())
+ .catch((err) => {
+ console.error(`An error occurred when fetching API path ${path}`)
+ console.error(err)
+ throw err
+ })
+
+interface Snippet {
+ id: string
+ title: string
+ content: string
+}
+
+interface APISuccess<D> {
+ readonly type: "success"
+ data: D
+}
+
+interface APILoading {
+ readonly type: "loading"
+}
+
+interface APIFailed<E> {
+ readonly type: "failed"
+ error: E
+}
+
+type APIResult<D, E> = APISuccess<D> | APILoading | APIFailed<E>
+
+const mapSWRResult = <D, E>({ data, error }: SWRResponse<D, E>): APIResult<D, E> => {
+ if (error !== undefined) {
+ return { type: "failed", error }
+ }
+
+ const isLoading = data === undefined
+ if (isLoading) {
+ return { type: "loading" }
+ }
+
+ return { type: "success", data }
+}
+
+export const useSnippets = () => mapSWRResult<Snippet[], Error>(
+ useSWR("/snippets", fetcher),
+)
diff --git a/src/favicon.png b/src/favicon.png
new file mode 100644
index 0000000..5527fb4
--- /dev/null
+++ b/src/favicon.png
Binary files differ
diff --git a/src/favicon.svg b/src/favicon.svg
deleted file mode 100644
index de4aedd..0000000
--- a/src/favicon.svg
+++ /dev/null
@@ -1,15 +0,0 @@
-<svg width="410" height="404" viewBox="0 0 410 404" fill="none" xmlns="http://www.w3.org/2000/svg">
-<path d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z" fill="url(#paint0_linear)"/>
-<path d="M292.965 1.5744L156.801 28.2552C154.563 28.6937 152.906 30.5903 152.771 32.8664L144.395 174.33C144.198 177.662 147.258 180.248 150.51 179.498L188.42 170.749C191.967 169.931 195.172 173.055 194.443 176.622L183.18 231.775C182.422 235.487 185.907 238.661 189.532 237.56L212.947 230.446C216.577 229.344 220.065 232.527 219.297 236.242L201.398 322.875C200.278 328.294 207.486 331.249 210.492 326.603L212.5 323.5L323.454 102.072C325.312 98.3645 322.108 94.137 318.036 94.9228L279.014 102.454C275.347 103.161 272.227 99.746 273.262 96.1583L298.731 7.86689C299.767 4.27314 296.636 0.855181 292.965 1.5744Z" fill="url(#paint1_linear)"/>
-<defs>
-<linearGradient id="paint0_linear" x1="6.00017" y1="32.9999" x2="235" y2="344" gradientUnits="userSpaceOnUse">
-<stop stop-color="#41D1FF"/>
-<stop offset="1" stop-color="#BD34FE"/>
-</linearGradient>
-<linearGradient id="paint1_linear" x1="194.651" y1="8.81818" x2="236.076" y2="292.989" gradientUnits="userSpaceOnUse">
-<stop stop-color="#FFEA83"/>
-<stop offset="0.0833333" stop-color="#FFDD35"/>
-<stop offset="1" stop-color="#FFA800"/>
-</linearGradient>
-</defs>
-</svg>
diff --git a/src/index.css b/src/index.css
index ec2585e..910f8af 100644
--- a/src/index.css
+++ b/src/index.css
@@ -1,13 +1,30 @@
-body {
- margin: 0;
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
- 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
- sans-serif;
+:root {
+ --dark-grey: #282c34;
+ --white: #fff;
+ --red: #ff7e7e;
+
+ --font-xxl: 44px;
+ --font-xl: 38px;
+ --font-l: 32px;
+ --font-m: 26px;
+ --font-s: 20px;
+}
+
+html {
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
+ background-color: var(--dark-grey);
+ color: var(--white);
}
-code {
- font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
- monospace;
+body {
+ margin: 60px auto;
+ padding: 0 10px;
+ max-width: 900px;
+ text-align: left;
}
+
+code {
+ font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
+} \ No newline at end of file
diff --git a/src/main.tsx b/src/main.tsx
index 606a3cf..9a11046 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -1,11 +1,11 @@
-import React from 'react'
-import ReactDOM from 'react-dom'
-import './index.css'
-import App from './App'
+import React from "react"
+import ReactDOM from "react-dom"
+import "./index.css"
+import App from "./App"
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
- document.getElementById('root')
+ document.getElementById("root"),
)