Revize 846f4f3c
Přidáno uživatelem Václav Honzík před asi 3 roky(ů)
frontend/package.json | ||
---|---|---|
6 | 6 |
"dependencies": { |
7 | 7 |
"@emotion/react": "^11.8.2", |
8 | 8 |
"@emotion/styled": "^11.8.1", |
9 |
"@mui/material": "^5.5.1",
|
|
9 |
"@mui/material": "^5.5.2",
|
|
10 | 10 |
"@testing-library/jest-dom": "^5.14.1", |
11 | 11 |
"@testing-library/react": "^12.0.0", |
12 | 12 |
"@testing-library/user-event": "^13.2.1", |
... | ... | |
19 | 19 |
"formik": "^2.2.9", |
20 | 20 |
"react": "^17.0.2", |
21 | 21 |
"react-dom": "^17.0.2", |
22 |
"react-redux": "^7.2.6", |
|
22 | 23 |
"react-router-dom": "^6.2.2", |
23 | 24 |
"react-scripts": "5.0.0", |
25 |
"redux": "^4.1.2", |
|
24 | 26 |
"swagger-typescript-api": "^9.3.1", |
25 | 27 |
"ts-node": "^10.7.0", |
26 | 28 |
"typescript": "^4.4.2", |
frontend/requests/login.http | ||
---|---|---|
1 |
POST /login |
|
2 |
Host: localhost:8080 |
|
3 |
Content-Type: application/json |
|
4 | ||
5 |
{ |
|
6 |
"username": "ultrabanger", |
|
7 |
"email": "ultra@banger.com", |
|
8 |
"password": "thereisnone" |
|
9 |
} |
frontend/requests/register.http | ||
---|---|---|
1 |
POST /register |
|
2 |
Host: localhost:8080 |
|
3 |
Content-Type: application/json |
|
4 | ||
5 | ||
6 |
{ |
|
7 |
"name": "ultrabanger3000", |
|
8 |
"email": "ultra@banger.com", |
|
9 |
"canRead": true, |
|
10 |
"canWrite": true, |
|
11 |
"canDelete": true |
|
12 |
} |
frontend/src/App.tsx | ||
---|---|---|
1 |
import React from 'react' |
|
1 |
import React, { CSSProperties } from 'react'
|
|
2 | 2 |
import './App.css' |
3 | 3 |
import { Routes, Route, Link } from 'react-router-dom' |
4 | 4 |
import Home from './features/Home/Home' |
5 | 5 |
import Catalog from './features/Catalog/Catalog' |
6 | 6 |
import NotFound from './features/NotFound/NotFound' |
7 |
import { Paper, Theme } from '@mui/material' |
|
8 |
import { ThemeProvider } from '@emotion/react' |
|
9 |
import { useSelector } from 'react-redux' |
|
10 |
import { RootState } from './features/redux/store' |
|
11 |
import { createTheme } from '@mui/material/styles' |
|
7 | 12 | |
8 |
const App = () => ( |
|
9 |
<div className="App"> |
|
10 |
<nav> |
|
11 |
<Link to="/">Home</Link> |
|
12 |
<Link to="/catalog">Catalog</Link> |
|
13 |
</nav> |
|
14 |
<Routes> |
|
15 |
<Route path="/" element={ <Home /> } /> |
|
16 |
<Route path="/catalog" element={ <Catalog /> } /> |
|
17 |
<Route path="*" element={ <NotFound /> } /> |
|
18 |
</Routes> |
|
19 |
</div> |
|
20 |
) |
|
13 |
const App = () => { |
|
14 |
const theme: Theme = useSelector((state: RootState) => state.theme.theme) |
|
15 | ||
16 |
return ( |
|
17 |
<ThemeProvider theme={theme}> |
|
18 |
<Paper style={{ minHeight: '100vh', borderRadius: 0 }}> |
|
19 |
<nav> |
|
20 |
<Link to="/">Home</Link> |
|
21 |
<Link to="/catalog">Catalog</Link> |
|
22 |
</nav> |
|
23 |
<Routes> |
|
24 |
<Route path="/" element={<Home />} /> |
|
25 |
<Route path="/catalog" element={<Catalog />} /> |
|
26 |
<Route path="*" element={<NotFound />} /> |
|
27 |
</Routes> |
|
28 |
</Paper> |
|
29 |
</ThemeProvider> |
|
30 |
) |
|
31 |
} |
|
21 | 32 | |
22 | 33 |
export default App |
frontend/src/features/Catalog/CatalogItemDetail.tsx | ||
---|---|---|
1 | ||
2 |
export default {} |
frontend/src/features/Catalog/CatalogService.ts | ||
---|---|---|
1 |
import axios from "../../api/axios" |
|
1 |
import axios from "../../api/axiosInstance"
|
|
2 | 2 |
import { CatalogDto } from "../../swagger/data-contracts" |
3 | 3 | |
4 | 4 |
export const getCatalogItems = async (componentMounted: boolean, setCatalog: (catalogItems: CatalogDto[]) => void, ) => { |
frontend/src/features/Theme/ThemeChanger.tsx | ||
---|---|---|
1 |
export default {} |
frontend/src/features/Theme/themeReducer.ts | ||
---|---|---|
1 |
import { createTheme, Theme } from '@mui/material/styles' |
|
2 |
import { AnyAction } from 'redux' |
|
3 |
import { persist } from '../../utils/statePersistence' |
|
4 | ||
5 |
export interface ThemeState { |
|
6 |
theme: Theme |
|
7 |
themeType: 'Light' | 'Dark' |
|
8 |
} |
|
9 | ||
10 |
const statePersistName = 'theme' |
|
11 | ||
12 |
const initialTheme = createTheme({ |
|
13 |
palette: { |
|
14 |
mode: 'light' |
|
15 |
} |
|
16 |
}) |
|
17 |
const initialState: ThemeState = { |
|
18 |
theme: initialTheme, |
|
19 |
themeType: 'Light', |
|
20 |
} |
|
21 | ||
22 |
export enum ThemeStateActions { |
|
23 |
TOGGLE_THEME = 'TOGGLE_THEME', |
|
24 |
SET_LIGHT_MODE = 'SET_LIGHT_MODE', |
|
25 |
SET_DARK_MODE = 'SET_DARK_MODE', |
|
26 |
} |
|
27 | ||
28 |
const themeReducer = (state: ThemeState = initialState, action: AnyAction) => { |
|
29 |
// TODO add all the actions |
|
30 |
switch (action.type) { |
|
31 |
case ThemeStateActions.TOGGLE_THEME: |
|
32 |
return persist(statePersistName, state) |
|
33 | ||
34 |
default: |
|
35 |
return state |
|
36 |
} |
|
37 |
} |
|
38 | ||
39 |
export default themeReducer |
frontend/src/index.tsx | ||
---|---|---|
4 | 4 |
import App from './App' |
5 | 5 |
import reportWebVitals from './reportWebVitals' |
6 | 6 |
import { BrowserRouter } from 'react-router-dom' |
7 |
import store from './features/redux/store' |
|
8 |
import { Provider } from 'react-redux' |
|
9 |
import { injectStore } from './api/axiosInstance' |
|
10 | ||
11 |
// Injects store to the axios instance in ./api/axiosInstance |
|
12 |
injectStore(store) |
|
7 | 13 | |
8 | 14 |
ReactDOM.render( |
9 |
<React.StrictMode> |
|
10 |
<BrowserRouter> |
|
11 |
<App /> |
|
12 |
</BrowserRouter> |
|
13 |
</React.StrictMode>, |
|
15 |
<Provider store={store}> |
|
16 |
<React.StrictMode> |
|
17 |
<BrowserRouter> |
|
18 |
<App /> |
|
19 |
</BrowserRouter> |
|
20 |
</React.StrictMode> |
|
21 |
</Provider>, |
|
14 | 22 |
document.getElementById('root') |
15 | 23 |
) |
16 | 24 |
Také k dispozici: Unified diff
re #9130 catalog start