Skip to content

Commit

Permalink
test app too
Browse files Browse the repository at this point in the history
  • Loading branch information
PuruVJ committed Jul 16, 2024
1 parent 76bf8d2 commit c29a189
Show file tree
Hide file tree
Showing 24 changed files with 339 additions and 241 deletions.
18 changes: 18 additions & 0 deletions packages/sdk/test-app/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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 },
],
},
}
41 changes: 21 additions & 20 deletions packages/sdk/test-app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

# 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?
31 changes: 30 additions & 1 deletion packages/sdk/test-app/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
# Testing the typescript SDK in React
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: __dirname,
},
}
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
13 changes: 13 additions & 0 deletions packages/sdk/test-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
54 changes: 17 additions & 37 deletions packages/sdk/test-app/package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,24 @@
{
"name": "test-app",
"version": "0.1.0",
"name": "test-app-vite",
"private": true,
"dependencies": {
"@clockworklabs/spacetimedb-sdk": "workspace:*",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.23",
"@types/react": "^18.0.31",
"@types/react-dom": "^18.0.11",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
},
"version": "0.0.0",
"type": "module",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1",
"@clockworklabs/spacetimedb-sdk": "workspace:*"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
"devDependencies": {
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"typescript": "^5.2.2",
"vite": "^5.3.4"
}
}
Binary file removed packages/sdk/test-app/public/favicon.ico
Binary file not shown.
43 changes: 0 additions & 43 deletions packages/sdk/test-app/public/index.html

This file was deleted.

Binary file removed packages/sdk/test-app/public/logo192.png
Binary file not shown.
Binary file removed packages/sdk/test-app/public/logo512.png
Binary file not shown.
25 changes: 0 additions & 25 deletions packages/sdk/test-app/public/manifest.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/sdk/test-app/public/robots.txt

This file was deleted.

52 changes: 28 additions & 24 deletions packages/sdk/test-app/src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
.App {
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}

.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;
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}
20 changes: 13 additions & 7 deletions packages/sdk/test-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import React, { useEffect, useState } from "react";
import { SpacetimeDBClient } from "@clockworklabs/spacetimedb-sdk";
import { useEffect, useState } from "react";
import "./App.css";

function App() {
const [client] = useState<SpacetimeDBClient>(
new SpacetimeDBClient("localhost:3000", "goldbreezycanid", {
identity:
"49f2d472cabfbc7ded52ac1f93316750dc8ea162aac97cc52a340aed221b7ff3",
token:
"eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJoZXhfaWRlbnRpdHkiOiI0OWYyZDQ3MmNhYmZiYzdkZWQ1MmFjMWY5MzMxNjc1MGRjOGVhMTYyYWFjOTdjYzUyYTM0MGFlZDIyMWI3ZmYzIiwiaWF0IjoxNjgwMTkwNDc5fQ.KPz0DjrWb6I5c51wa71FGTgWz0Nh6CiNycM0ynmDDNkGjRxsci5cmiEjHQdYKyIeaG9MizSVPGlaDJ2Z7uctcg",
})
new SpacetimeDBClient(
"localhost:3000",
"goldbreezycanid",
// @ts-ignore
// TODO: WHy are these not according to the types?
{
identity:
"49f2d472cabfbc7ded52ac1f93316750dc8ea162aac97cc52a340aed221b7ff3",
token:
"eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJoZXhfaWRlbnRpdHkiOiI0OWYyZDQ3MmNhYmZiYzdkZWQ1MmFjMWY5MzMxNjc1MGRjOGVhMTYyYWFjOTdjYzUyYTM0MGFlZDIyMWI3ZmYzIiwiaWF0IjoxNjgwMTkwNDc5fQ.KPz0DjrWb6I5c51wa71FGTgWz0Nh6CiNycM0ynmDDNkGjRxsci5cmiEjHQdYKyIeaG9MizSVPGlaDJ2Z7uctcg",
}
)
);

useEffect(() => {
Expand Down
Loading

0 comments on commit c29a189

Please sign in to comment.