Skip to content

Commit

Permalink
Merge pull request #57 from golemfactory/feature/JST-456/react-templates
Browse files Browse the repository at this point in the history
Add react js and ts templates
  • Loading branch information
SewerynKras authored Oct 16, 2023
2 parents 7986746 + 4c86284 commit b08adf6
Show file tree
Hide file tree
Showing 32 changed files with 595 additions and 5 deletions.
17 changes: 17 additions & 0 deletions data/project-templates/react-js/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parserOptions: { ecmaVersion: "latest", sourceType: "module" },
settings: { react: { version: "18.2" } },
plugins: ["react-refresh"],
rules: {
"react-refresh/only-export-components": ["warn", { allowConstantExport: true }],
},
};
24 changes: 24 additions & 0 deletions data/project-templates/react-js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
5 changes: 5 additions & 0 deletions data/project-templates/react-js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Golem + React + Vite

This is a modified version of the [React + Vite](https://vite.new/react) template provided by Vite with the `@golem-sdk/react` package added and some basic instructions on how to connect to yagna.

It's important that you set the `VITE_YAGNA_APPKEY` environment variable to your yagna appkey before running the project. You can find your appkey by running `yagna app-key list` in your terminal.
12 changes: 12 additions & 0 deletions data/project-templates/react-js/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Golem + Vite + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions data/project-templates/react-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "react-template",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@golem-sdk/react": "^1.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.18",
"@types/react-dom": "^18.2.7",
"@vitejs/plugin-react": "^4.0.4",
"eslint": "^8.46.0",
"eslint-plugin-react": "^7.33.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"vite": "^4.4.8"
}
}
32 changes: 32 additions & 0 deletions data/project-templates/react-js/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}

.installation-instructions {
max-width: 32em;
text-align: left;
}
51 changes: 51 additions & 0 deletions data/project-templates/react-js/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import golemLogo from "./assets/golem.svg";
import reactLogo from "./assets/react.svg";
import viteLogo from "./assets/vite.svg";
import "./App.css";
import { useYagna } from "@golem-sdk/react";

function App() {
const { isConnected } = useYagna();

return (
<>
<div>
<a href="https://docs.golem.network" target="_blank">
<img src={golemLogo} className="logo" alt="Golem logo" />
</a>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Golem + Vite + React</h1>
<h2>Yagna is {isConnected ? "connected" : "not connected"}</h2>
{!isConnected && (
<p className="installation-instructions">
Looks like yagna is not running on your local machine. Please follow the instructions in the{" "}
<a
className="link"
target="_blank"
href="https://docs.golem.network/docs/creators/javascript/examples/tools/yagna-installation-for-requestors"
>
quickstart
</a>
. Make sure to start the process with the <code>--api-allow-origin</code> flag:
<br />
<code>{`yagna service run --api-allow-origin='${window.location.origin}'`}</code>
</p>
)}
<div className="card">
<p>
Edit <code>src/App.jsx</code> and save to test HMR
</p>
</div>

<p className="read-the-docs">Click on the Golem, Vite or React logos to learn more</p>
</>
);
}

export default App;
15 changes: 15 additions & 0 deletions data/project-templates/react-js/src/assets/golem.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/project-templates/react-js/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/project-templates/react-js/src/assets/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions data/project-templates/react-js/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: #213547;
background-color: #ffffff;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #747bff;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

h1 {
font-size: 3.2em;
line-height: 1.1;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
21 changes: 21 additions & 0 deletions data/project-templates/react-js/src/main.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.jsx";
import "./index.css";
import { YagnaProvider } from "@golem-sdk/react";

if (!import.meta.env.VITE_YAGNA_APPKEY) {
throw new Error("VITE_YAGNA_APPKEY env variable is not set. Please add it to the .env file.");
}

ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>
<YagnaProvider
config={{
yagnaAppKey: import.meta.env.VITE_YAGNA_APPKEY,
}}
>
<App />
</YagnaProvider>
</React.StrictMode>,
);
7 changes: 7 additions & 0 deletions data/project-templates/react-js/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
});
11 changes: 11 additions & 0 deletions data/project-templates/react-ts/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:react-hooks/recommended"],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
plugins: ["react-refresh"],
rules: {
"react-refresh/only-export-components": ["warn", { allowConstantExport: true }],
},
};
24 changes: 24 additions & 0 deletions data/project-templates/react-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
5 changes: 5 additions & 0 deletions data/project-templates/react-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Golem + React + TypeScript + Vite

This is a modified version of the [React + TypeScript + Vite](https://vite.new/react-ts) template provided by Vite with the `@golem-sdk/react` package added and some basic instructions on how to connect to yagna.

It's important that you set the `VITE_YAGNA_APPKEY` environment variable to your yagna appkey before running the project. You can find your appkey by running `yagna app-key list` in your terminal.
12 changes: 12 additions & 0 deletions data/project-templates/react-ts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Golem + Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
29 changes: 29 additions & 0 deletions data/project-templates/react-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "react-template",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@golem-sdk/react": "^1.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-react": "^4.0.3",
"eslint": "^8.45.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"typescript": "^5.0.2",
"vite": "^4.4.5"
}
}
Loading

0 comments on commit b08adf6

Please sign in to comment.