Skip to content

Commit 1551131

Browse files
gmirzayevinfomihomartinovicdevMartinsos
authored
docs: remove mentions of logoUrl (#1473)
* Add streaming text example Signed-off-by: Mihovil Ilakovac <[email protected]> * Updated diagram to be visible on dark mode (#1456) Added white background so the diagram in docs is visible also in dark background. * Update .gitattributes to not look at haskell files * docs: remove mentions of logoUrl --------- Signed-off-by: Mihovil Ilakovac <[email protected]> Co-authored-by: Mihovil Ilakovac <[email protected]> Co-authored-by: Boris Martinovic <[email protected]> Co-authored-by: Martin Šošić <[email protected]>
1 parent 0db972d commit 1551131

File tree

15 files changed

+346
-5
lines changed

15 files changed

+346
-5
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
*.wasp linguist-language=JavaScript
22

3+
*.hs linguist-detectable=false
4+
35
/examples/* linguist-documentation

examples/streaming/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/.wasp/
2+
3+
# We ignore env files recognized and used by Wasp.
4+
.env.server
5+
.env.client
6+
7+
# To be extra safe, we by default ignore any files with `.env` extension in them.
8+
# If this is too agressive for you, consider allowing specific files with `!` operator,
9+
# or modify/delete these two lines.
10+
*.env
11+
*.env.*

examples/streaming/.wasproot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
File marking the root of Wasp project.

examples/streaming/main.wasp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
app streaming {
2+
wasp: {
3+
version: "^0.11.5"
4+
},
5+
title: "streaming"
6+
}
7+
8+
route RootRoute { path: "/", to: MainPage }
9+
page MainPage {
10+
component: import Main from "@client/MainPage.jsx"
11+
}
12+
13+
api streamingText {
14+
httpRoute: (GET, "/api/streaming-test"),
15+
fn: import { getText } from "@server/streaming.js",
16+
}
17+
18+
apiNamespace defaultMiddleware {
19+
path: "/api",
20+
middlewareConfigFn: import { getMiddlewareConfig } from "@server/streaming.js",
21+
}

examples/streaming/src/.waspignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ignore editor tmp files
2+
**/*~
3+
**/#*#
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
* {
2+
-webkit-font-smoothing: antialiased;
3+
-moz-osx-font-smoothing: grayscale;
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
margin: 0;
9+
padding: 0;
10+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
11+
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
12+
sans-serif;
13+
}
14+
15+
.container {
16+
min-height: 100vh;
17+
display: flex;
18+
flex-direction: column;
19+
justify-content: center;
20+
align-items: center;
21+
}
22+
23+
main {
24+
padding: 5rem 0;
25+
flex: 1;
26+
display: flex;
27+
flex-direction: column;
28+
justify-content: center;
29+
align-items: center;
30+
}
31+
32+
main p {
33+
font-size: 1.2rem;
34+
}
35+
36+
.logo {
37+
margin-bottom: 2rem;
38+
}
39+
40+
.logo img {
41+
max-height: 200px;
42+
}
43+
44+
.welcome-title {
45+
font-weight: 500;
46+
}
47+
48+
.welcome-subtitle {
49+
font-weight: 400;
50+
margin-bottom: 3rem;
51+
}
52+
53+
.buttons {
54+
display: flex;
55+
flex-direction: row;
56+
}
57+
58+
.buttons .button:not(:last-child) {
59+
margin-right: 0.5rem;
60+
}
61+
62+
.button {
63+
border-radius: 3px;
64+
font-size: 1.2rem;
65+
padding: 1rem 2rem;
66+
text-align: center;
67+
font-weight: 700;
68+
text-decoration: none;
69+
}
70+
71+
.button-filled {
72+
border: 2px solid #bf9900;
73+
background-color: #bf9900;
74+
color: #f4f4f4;
75+
}
76+
77+
.button-outline {
78+
border: 2px solid #8a9cff;
79+
color: #8a9cff;
80+
background-color: none;
81+
}
82+
83+
code {
84+
border-radius: 5px;
85+
padding: 0.2rem;
86+
background: #efefef;
87+
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
88+
Bitstream Vera Sans Mono, Courier New, monospace;
89+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { useState, useEffect } from "react";
2+
import config from "@wasp/config";
3+
import "./Main.css";
4+
5+
const MainPage = () => {
6+
const { response } = useTextStream("/api/streaming-test");
7+
return (
8+
<div className="container">
9+
<main>
10+
<h1>Streaming Demo</h1>
11+
<p
12+
style={{
13+
maxWidth: "600px",
14+
}}
15+
>
16+
{response}
17+
</p>
18+
</main>
19+
</div>
20+
);
21+
};
22+
export default MainPage;
23+
24+
function useTextStream(path) {
25+
const [response, setResponse] = useState("");
26+
useEffect(() => {
27+
const controller = new AbortController();
28+
fetchStream(
29+
path,
30+
(chunk) => {
31+
setResponse((prev) => prev + chunk);
32+
},
33+
controller
34+
);
35+
return () => {
36+
controller.abort();
37+
};
38+
}, []);
39+
40+
return {
41+
response,
42+
};
43+
}
44+
45+
async function fetchStream(path, onData, controller) {
46+
const response = await fetch(config.apiUrl + path, {
47+
signal: controller.signal,
48+
});
49+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
50+
while (true) {
51+
const { done, value } = await reader.read();
52+
if (done) {
53+
return;
54+
}
55+
onData(value.toString());
56+
}
57+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// =============================== IMPORTANT =================================
2+
//
3+
// This file is only used for Wasp IDE support. You can change it to configure
4+
// your IDE checks, but none of these options will affect the TypeScript
5+
// compiler. Proper TS compiler configuration in Wasp is coming soon :)
6+
{
7+
"compilerOptions": {
8+
// JSX support
9+
"jsx": "preserve",
10+
"strict": true,
11+
// Allow default imports.
12+
"esModuleInterop": true,
13+
"lib": [
14+
"dom",
15+
"dom.iterable",
16+
"esnext"
17+
],
18+
"allowJs": true,
19+
// Wasp needs the following settings enable IDE support in your source
20+
// files. Editing them might break features like import autocompletion and
21+
// definition lookup. Don't change them unless you know what you're doing.
22+
//
23+
// The relative path to the generated web app's root directory. This must be
24+
// set to define the "paths" option.
25+
"baseUrl": "../../.wasp/out/web-app/",
26+
"paths": {
27+
// Resolve all "@wasp" imports to the generated source code.
28+
"@wasp/*": [
29+
"src/*"
30+
],
31+
// Resolve all non-relative imports to the correct node module. Source:
32+
// https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping
33+
"*": [
34+
// Start by looking for the definiton inside the node modules root
35+
// directory...
36+
"node_modules/*",
37+
// ... If that fails, try to find it inside definitely-typed type
38+
// definitions.
39+
"node_modules/@types/*"
40+
]
41+
},
42+
// Correctly resolve types: https://www.typescriptlang.org/tsconfig#typeRoots
43+
"typeRoots": [
44+
"../../.wasp/out/web-app/node_modules/@types"
45+
],
46+
// Since this TS config is used only for IDE support and not for
47+
// compilation, the following directory doesn't exist. We need to specify
48+
// it to prevent this error:
49+
// https://stackoverflow.com/questions/42609768/typescript-error-cannot-write-file-because-it-would-overwrite-input-file
50+
"outDir": "phantom"
51+
},
52+
"exclude": [
53+
"phantom"
54+
],
55+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="../../.wasp/out/web-app/node_modules/vite/client" />
24.3 KB
Loading

0 commit comments

Comments
 (0)