Skip to content

Commit

Permalink
feat: move examples to vite since create-react-app is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
darkbasic committed Nov 23, 2023
1 parent 5039b8d commit 7c05abf
Show file tree
Hide file tree
Showing 64 changed files with 1,016 additions and 4,773 deletions.
18 changes: 18 additions & 0 deletions examples/react-graphql-typescript/.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 examples/react-graphql-typescript/.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?
13 changes: 13 additions & 0 deletions examples/react-graphql-typescript/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>
50 changes: 20 additions & 30 deletions examples/react-graphql-typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
{
"name": "@examples/react-graphql-typescript",
"version": "0.32.0",
"private": true,
"version": "0.32.0",
"type": "module",
"scripts": {
"start": "SKIP_PREFLIGHT_CHECK=true react-scripts start",
"build": "SKIP_PREFLIGHT_CHECK=true react-scripts build",
"dev": "vite --force",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"test": "yarn run build",
"testonly": "yarn run build"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"dependencies": {
"@accounts/apollo-link": "^0.32.1",
"@accounts/client": "^0.33.1",
Expand All @@ -39,21 +24,26 @@
"graphql": "16.8.1",
"graphql-tag": "2.12.6",
"qrcode.react": "3.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router": "5.3.4",
"react-router-dom": "5.3.4",
"tslib": "2.6.2"
"react-router-dom": "5.3.4"
},
"devDependencies": {
"@levminer/speakeasy": "1.4.2",
"@types/qrcode.react": "1.0.5",
"@types/react": "18.2.38",
"@types/react-dom": "18.2.17",
"@types/react": "^18.2.38",
"@types/react-dom": "^18.2.17",
"@types/react-router": "5.1.20",
"@types/react-router-dom": "5.3.3",
"eslint": "8.54.0",
"eslint-config-react-app": "7.0.1",
"react-scripts": "5.0.1",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"@vitejs/plugin-react": "^4.2.0",
"eslint": "^8.54.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"typescript": "^5.3.2",
"vite": "^5.0.2",
"web-vitals": "3.5.0"
}
}
Binary file removed examples/react-graphql-typescript/public/favicon.ico
Binary file not shown.
40 changes: 0 additions & 40 deletions examples/react-graphql-typescript/public/index.html

This file was deleted.

Binary file removed examples/react-graphql-typescript/public/logo192.png
Binary file not shown.
Binary file removed examples/react-graphql-typescript/public/logo512.png
Binary file not shown.
25 changes: 0 additions & 25 deletions examples/react-graphql-typescript/public/manifest.json

This file was deleted.

3 changes: 0 additions & 3 deletions examples/react-graphql-typescript/public/robots.txt

This file was deleted.

1 change: 1 addition & 0 deletions examples/react-graphql-typescript/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.
13 changes: 13 additions & 0 deletions examples/react-graphql-typescript/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ApolloProvider } from '@apollo/client';
import { apolloClient } from './utils/accounts';
import Router from './Router';

function App() {
return (
<ApolloProvider client={apolloClient}>
<Router />
</ApolloProvider>
);
}

export default App;
3 changes: 1 addition & 2 deletions examples/react-graphql-typescript/src/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { RouteComponentProps, Link, Redirect } from 'react-router-dom';
import { Button, Typography } from '@mui/material';
import gql from 'graphql-tag';
Expand All @@ -21,7 +20,7 @@ const GET_USER_QUERY = gql`
}
`;

const Home = ({ history }: RouteComponentProps<{}>) => {
const Home = ({ history }: RouteComponentProps) => {
const { loading, error, data } = useQuery(GET_USER_QUERY);

const onResendEmail = async () => {
Expand Down
4 changes: 3 additions & 1 deletion examples/react-graphql-typescript/src/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ const useStyles = makeStyles({
},
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const SignUpLink = React.forwardRef<Link, any>((props, ref) => (
<Link to="/signup" {...props} ref={ref} />
));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const ResetPasswordLink = React.forwardRef<Link, any>((props, ref) => (
<Link to="/reset-password" {...props} ref={ref} />
));

const Login = ({ history }: RouteComponentProps<{}>) => {
const Login = ({ history }: RouteComponentProps) => {
const classes = useStyles();
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
Expand Down
2 changes: 1 addition & 1 deletion examples/react-graphql-typescript/src/ResetPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const useStyles = makeStyles({
},
});

const LogInLink = (props: any) => <Link to="/login" {...props} />;
const LogInLink = (props: object) => <Link to="/login" {...props} />;

interface RouteMatchProps {
token: string;
Expand Down
1 change: 0 additions & 1 deletion examples/react-graphql-typescript/src/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { BrowserRouter, Route } from 'react-router-dom';
import { CssBaseline, Grid, Paper } from '@mui/material';
import { makeStyles } from '@mui/styles';
Expand Down
3 changes: 2 additions & 1 deletion examples/react-graphql-typescript/src/Signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const useStyles = makeStyles({
},
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const LogInLink = React.forwardRef<Link, any>((props, ref) => (
<Link to="/login" {...props} ref={ref} />
));
Expand All @@ -24,7 +25,7 @@ interface UserForm {
password: string;
}

const Signup = ({ history }: RouteComponentProps<{}>) => {
const Signup = ({ history }: RouteComponentProps) => {
const classes = useStyles();
const [error, setError] = useState<string | null>(null);
const [user, setUser] = useState<UserForm>({
Expand Down
8 changes: 6 additions & 2 deletions examples/react-graphql-typescript/src/TwoFactor.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import React, { useState, useEffect } from 'react';
import { useState, useEffect } from 'react';
import { Button, Typography, FormControl, InputLabel, Input } from '@mui/material';
import QRCode from 'qrcode.react';
import { type GeneratedSecret } from '@levminer/speakeasy';

type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };

import { accountsGraphQL } from './utils/accounts';

const TwoFactor = () => {
const [secret, setSecret] = useState<any>();
const [secret, setSecret] = useState<WithRequired<GeneratedSecret, 'otpauth_url'>>();
const [oneTimeCode, setOneTimeCode] = useState('');

const fetchTwoFactorSecret = async () => {
const data = await accountsGraphQL.getTwoFactorSecret();
if (data) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { __typename, ...secretFields } = data;
setSecret(secretFields);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/react-graphql-typescript/src/VerifyEmail.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import { useState, useEffect } from 'react';
import { RouteComponentProps, Link } from 'react-router-dom';
import { Button, Typography } from '@mui/material';

Expand All @@ -9,7 +9,7 @@ interface RouteMatchProps {
token: string;
}

const HomeLink = (props: any) => <Link to="/" {...props} />;
const HomeLink = (props: object) => <Link to="/" {...props} />;

const VerifyEmail = ({ match }: RouteComponentProps<RouteMatchProps>) => {
const [success, setSuccess] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from 'react';
import { Typography } from '@mui/material';
import { makeStyles } from '@mui/styles';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { ApolloProvider } from '@apollo/client';
import { apolloClient } from './utils/accounts';
import Router from './Router';
import ReactDOM from 'react-dom/client';
import App from './App.tsx';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
<ApolloProvider client={apolloClient}>
<Router />
</ApolloProvider>,
document.getElementById('root') as HTMLElement
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
Expand Down
1 change: 1 addition & 0 deletions examples/react-graphql-typescript/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
Loading

0 comments on commit 7c05abf

Please sign in to comment.