Skip to content

Commit

Permalink
use vite
Browse files Browse the repository at this point in the history
  • Loading branch information
gotti committed Nov 24, 2023
1 parent 9ad1fff commit f371aea
Show file tree
Hide file tree
Showing 32 changed files with 1,423 additions and 2,563 deletions.
4 changes: 2 additions & 2 deletions backend/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
frontendURL, _ := url.Parse("http://localhost:3000")
frontendURL, _ := url.Parse("http://localhost:5173")
backendURL, _ := url.Parse("http://localhost:8080")

mux := http.NewServeMux()
Expand All @@ -24,5 +24,5 @@ func main() {
}
mux.Handle("/api/", &rev)

fmt.Println(http.ListenAndServe(":3030", mux))
fmt.Println(http.ListenAndServe(":3031", mux))
}
18 changes: 18 additions & 0 deletions frontend/dashboard/.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 },
],
},
}
58 changes: 21 additions & 37 deletions frontend/dashboard/.gitignore
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# prettier / Eslint
.eslintrc.json
.prettierrc.json
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?
50 changes: 22 additions & 28 deletions frontend/dashboard/README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
# React + TypeScript + Vite

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

First, run the development server:
Currently, two official plugins are available:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
- [@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

## Learn More
## Expanding the ESLint configuration

To learn more about Next.js, take a look at the following resources:
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
- Configure the top-level `parserOptions` property like this:

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
- 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 frontend/dashboard/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" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>工学研究部 プラレール展示</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
22 changes: 0 additions & 22 deletions frontend/dashboard/next.config.js

This file was deleted.

87 changes: 45 additions & 42 deletions frontend/dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
{
"name": "dashboard",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@bufbuild/connect-web": "^0.13.0",
"@bufbuild/protobuf": "^1.4.2",
"@connectrpc/connect": "^1.1.3",
"@connectrpc/connect-query": "^0.6.0",
"@connectrpc/connect-web": "^1.1.3",
"@tanstack/react-query": "^5.8.4",
"clsx": "^2.0.0",
"next": "14.0.3",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@bufbuild/buf": "^1.28.1",
"@bufbuild/protoc-gen-connect-web": "^0.11.0",
"@bufbuild/protoc-gen-es": "^1.4.2",
"@connectrpc/protoc-gen-connect-es": "^1.1.3",
"@connectrpc/protoc-gen-connect-query": "^0.6.0",
"@svgr/webpack": "^8.1.0",
"@types/node": "20.9.2",
"@types/react": "18.2.37",
"@types/react-dom": "18.2.15",
"eslint-config-prettier": "^9.0.0",
"prettier": "3.1.0",
"sass": "^1.69.5",
"typescript": "5.2.2"
},
"files": [
".next/standalone",
".next/static",
"public"
]
}
"name": "dashboard2",
"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": {
"@bufbuild/connect-web": "^0.13.0",
"@bufbuild/protobuf": "^1.4.2",
"@connectrpc/connect": "^1.1.3",
"@connectrpc/connect-query": "^0.6.0",
"@connectrpc/connect-web": "^1.1.3",
"@tanstack/react-query": "^5.8.4",
"clsx": "^2.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.11",
"sass": "^1.69.5"
},
"devDependencies": {
"@bufbuild/buf": "^1.28.1",
"@bufbuild/protoc-gen-connect-web": "^0.11.0",
"@bufbuild/protoc-gen-es": "^1.4.2",
"@connectrpc/protoc-gen-connect-es": "^1.1.3",
"@connectrpc/protoc-gen-connect-query": "^0.6.0",
"@types/node": "20.9.2",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"prettier": "3.1.0",
"typescript": "^5.2.2",
"vite": "^5.0.0",
"vite-plugin-svgr": "^4.2.0"
}
}
File renamed without changes.
1 change: 1 addition & 0 deletions frontend/dashboard/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions frontend/dashboard/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#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);
}

@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;
}
58 changes: 58 additions & 0 deletions frontend/dashboard/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import MapView from "./components/mapview/mapview"
import {TransportProvider} from "@connectrpc/connect-query";
import {createConnectTransport} from "@bufbuild/connect-web";
import {QueryClient, QueryClientProvider} from "@tanstack/react-query";
import React, {Suspense} from "react";
class ErrorBoundary extends React.Component {
state: { hasError: boolean; };
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(props: { children: React.ReactNode; }) {
super(props);
this.state = { hasError: false };
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
static getDerivedStateFromError(error: any) { // Update state so the next render will show the fallback UI.
console.log(error);
return { hasError: true };
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
componentDidCatch(error: any, errorInfo: any) { // You can also log the error to an error reporting service
console.log(error, errorInfo);
}
render() {
if (this.state.hasError) { // You can render any custom fallback UI
return <h1>Something went wrong.</h1>;
}
return this.props.children;
}
}

function App() {
const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchInterval: 500,
},
}});

const transport = createConnectTransport(
{
baseUrl: "http://quince:3031/api/",
});
return (
<>
<ErrorBoundary>
<Suspense>
<QueryClientProvider client={queryClient}>
<TransportProvider transport={transport}>
<MapView/>
</TransportProvider>
</QueryClientProvider>
</Suspense>
</ErrorBoundary>
</>
);
}

export default App
File renamed without changes.
Loading

0 comments on commit f371aea

Please sign in to comment.