Skip to content

Commit

Permalink
Merge pull request #3 from ChrisUser/feature/patch-1
Browse files Browse the repository at this point in the history
Add React project layout
  • Loading branch information
ChrisUser authored Feb 11, 2023
2 parents 431fcd1 + d832e72 commit 7ba8065
Show file tree
Hide file tree
Showing 35 changed files with 9,937 additions and 31 deletions.
41 changes: 41 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:react/recommended', 'plugin:@typescript-eslint/recommended'],
plugins: ['@typescript-eslint', 'react-hooks', 'prettier'],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true
}
},
env: {
browser: true,
node: true,
es6: true,
jest: true
},
rules: {
"no-control-regex": 0,
'no-undef': 0,
'no-unused-vars': 'off',
'react/prop-types': 0,
'@typescript-eslint/camelcase': 0,
'@typescript-eslint/no-unused-vars': 1,
'@typescript-eslint/no-use-before-define': 0,
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/ban-ts-ignore': 0,
'@typescript-eslint/explicit-member-accessibility': 0,
'@typescript-eslint/member-delimiter-style': 0,
'@typescript-eslint/no-empty-function': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-non-null-assertion': 'off',
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn'
},
settings: {
react: {
version: 'detect'
}
}
}
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies

/node_modules
/.pnp
.pnp.js

# testing

/coverage

# production

/build

# misc

.eslintcache
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log\*
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 160,
"tabWidth": 4,
"singleQuote": true,
"semi": false,
"trailingComma": "none",
"bracketSpacing": true
}
7 changes: 0 additions & 7 deletions gitignore

This file was deleted.

16 changes: 0 additions & 16 deletions index.html

This file was deleted.

46 changes: 46 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "gpt-recommender",
"version": "1.0.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.3",
"axios": "^1.3.2",
"eslint-plugin-prettier": "^4.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.8.0",
"react-scripts": "5.0.1",
"sass": "^1.58.0",
"sass-loader": "^13.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "eslint --cache .",
"format": "prettier --check ."
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
"defaults",
"not IE 11"
],
"devDependencies": {
"@types/jest": "^29.4.0",
"@types/node": "^18.11.19",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"typescript": "^4.9.5"
},
"homepage": ".",
"postcss": {
"plugins": {
"autoprefixer": {}
}
}
}
8 changes: 8 additions & 0 deletions public/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<IfModule mod_rewrite.c>
Options -MultiViews

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
</IfModule>
Binary file added public/favicon.ico
Binary file not shown.
19 changes: 19 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
Binary file added public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
1 change: 0 additions & 1 deletion scripts/main.js

This file was deleted.

17 changes: 17 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import { Provider } from 'react-redux'
import { PersistGate } from 'redux-persist/integration/react'
import RootComponent from './RootComponent'
import { persistor, store } from './store/reducers/store'

const App: React.FC = () => {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<RootComponent />
</PersistGate>
</Provider>
)
}

export default App
19 changes: 19 additions & 0 deletions src/RootComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'
import HomePage from './pages/HomePage'
import NotFoundPage from './pages/NotFoundPage'
import { ROUTES } from './resources/routes-constants'
import './styles/main.sass'

const RootComponent: React.FC = () => {
return (
<Router>
<Routes>
<Route path="*" element={<NotFoundPage />} />
<Route path={ROUTES.HOMEPAGE_ROUTE} element={<HomePage />} />
</Routes>
</Router>
)
}

export default RootComponent
16 changes: 16 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import { createRoot } from 'react-dom/client'
import App from './App'
import * as serviceWorker from './serviceWorker'

const root = createRoot(document.getElementById('root')!) // createRoot(container!) if you use TypeScript
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
)

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister()
11 changes: 11 additions & 0 deletions src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'

const HomePage: React.FC = () => {
return (
<div style={{ position: 'relative', width: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', flexDirection: 'column' }}>
<h1 style={{ fontSize: '4em' }}>GPT Recommender</h1>
</div>
)
}

export default HomePage
25 changes: 25 additions & 0 deletions src/pages/NotFoundPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react'
import { useNavigate } from 'react-router-dom'
import { ROUTES } from '../resources/routes-constants'

const NotFoundPage: React.FC = () => {
const navigate = useNavigate()

/**
* Call this function to redirect the user to the homepage.
*/
const redirectToHomePage = () => {
navigate(ROUTES.HOMEPAGE_ROUTE)
}

return (
<div style={{ position: 'relative', width: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', flexDirection: 'column' }}>
<h1 style={{ fontSize: '4em' }}>Oops 404!</h1>
<span style={{ cursor: 'pointer' }} onClick={() => redirectToHomePage()}>
Homepage
</span>
</div>
)
}

export default NotFoundPage
1 change: 1 addition & 0 deletions src/react-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="react-scripts" />
5 changes: 5 additions & 0 deletions src/resources/api-constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const baseUrl = 'https://exampleurl'

export const getData = (userId: number): string => {
return baseUrl + '/data/' + userId
}
3 changes: 3 additions & 0 deletions src/resources/routes-constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const ROUTES = {
HOMEPAGE_ROUTE: '/'
}
Loading

0 comments on commit 7ba8065

Please sign in to comment.