├── .gitignore ├── README.md ├── React_README.md ├── babel.config.js ├── jest.config.js ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.tsx ├── components │ ├── BreedGridDialog.tsx │ ├── BreedsTable.tsx │ ├── Header.test.tsx │ └── Header.tsx ├── context │ └── app-state-context.ts ├── index.scss ├── index.tsx ├── layouts │ └── MainLayout.tsx ├── logo.svg ├── mock │ └── db.json ├── pages │ ├── Home.tsx │ └── hoc │ │ └── MainLayoutWrapHOC.tsx ├── redux │ ├── redux-slice.ts │ └── store.ts ├── reportWebVitals.ts ├── routes │ └── MainRoute.tsx ├── service │ ├── api-service.ts │ └── http-client.ts ├── setupTests.ts ├── theme │ └── theme.config.ts └── types │ └── index.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dog Poster Generator Description 2 | 3 | > - Created a React project and setup TypeScript engine. 4 | > - Installed Mui node module and set the theme configuration. 5 | > - Structured the whole project with layouts, pages, components, types and so on. 6 | > - Used Dog apis with this link: https://dog.ceo/dog-api/documentation/ 7 | > - Setup redux flow to the project for managing application states. 8 | > - Display dog data from the server in to the MUI table. Created a Table component made it as a re-usable component. Using it on Home page. 9 | > - Created Breed images dialog and displaying breed images with Grid view. 10 | > - Used React.suspense for lazy loading component 11 | > - Created a mainLayoutWrapHOC 12 | > - Setup jest testing environment and add an unit test case for Header component 13 | 14 | ## Launch Script 15 | 16 | #### Start up the project 17 | This script will launch the project with 3001 port 18 | > npm run start
19 | 20 | #### Other scripts 21 | > npm run preinstall
22 | > npm run build
23 | > npm run test
24 | > npm run eject
25 | > npm run unit-test
26 | 27 | #### Mock server start script 28 | json-server --watch src/mock/db.json -------------------------------------------------------------------------------- /React_README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@babel/preset-react', 4 | [ 5 | '@babel/preset-env', 6 | { 7 | targets: { 8 | node: 'current', 9 | }, 10 | }, 11 | ], 12 | ], 13 | }; -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('jest').Config} */ 2 | const config = { 3 | verbose: true, 4 | }; 5 | 6 | module.exports = config; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dog-poster-generator", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "@emotion/react": "^11.9.0", 7 | "@emotion/styled": "^11.8.1", 8 | "@mui/icons-material": "^5.8.0", 9 | "@mui/material": "^5.8.1", 10 | "@reduxjs/toolkit": "^1.8.2", 11 | "@testing-library/jest-dom": "^5.16.4", 12 | "@testing-library/react": "^13.2.0", 13 | "@testing-library/user-event": "^13.5.0", 14 | "@types/jest": "^27.5.1", 15 | "@types/node": "^17.0.35", 16 | "@types/react": "^18.0.9", 17 | "@types/react-dom": "^18.0.5", 18 | "axios": "^0.27.2", 19 | "node-sass": "^7.0.1", 20 | "react": "^18.1.0", 21 | "react-dom": "^18.1.0", 22 | "react-redux": "^8.0.2", 23 | "react-router-dom": "^6.3.0", 24 | "react-scripts": "5.0.1", 25 | "styled-components": "^5.3.5", 26 | "typescript": "^4.7.2", 27 | "web-vitals": "^2.1.4" 28 | }, 29 | "resolutions": { 30 | "@types/react": "^18.0.9", 31 | "@types/react-dom": "^18.0.5" 32 | }, 33 | "scripts": { 34 | "start": "react-scripts start", 35 | "build": "react-scripts build", 36 | "test": "react-scripts test", 37 | "unit-test": "jest --env=jsdom", 38 | "eject": "react-scripts eject", 39 | "preinstall": "npm install --package-lock-only --ignore-scripts && npx npm-force-resolutions" 40 | }, 41 | "eslintConfig": { 42 | "extends": [ 43 | "react-app", 44 | "react-app/jest" 45 | ] 46 | }, 47 | "browserslist": { 48 | "production": [ 49 | ">0.2%", 50 | "not dead", 51 | "not op_mini all" 52 | ], 53 | "development": [ 54 | "last 1 chrome version", 55 | "last 1 firefox version", 56 | "last 1 safari version" 57 | ] 58 | }, 59 | "devDependencies": { 60 | "@babel/preset-env": "^7.20.2", 61 | "@babel/preset-react": "^7.18.6", 62 | "@types/react-test-renderer": "^18.0.0", 63 | "babel-jest": "^29.3.1", 64 | "jest": "^27.5.1", 65 | "react-test-renderer": "^18.2.0" 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DarkHorseCorder/React-Redux-ReactRoute-MUI-API-Lasyloading-TS-DogPoster/553beffe987938f9536467743be8bd15bb68b14a/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | Dog Poster Generator 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DarkHorseCorder/React-Redux-ReactRoute-MUI-API-Lasyloading-TS-DogPoster/553beffe987938f9536467743be8bd15bb68b14a/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DarkHorseCorder/React-Redux-ReactRoute-MUI-API-Lasyloading-TS-DogPoster/553beffe987938f9536467743be8bd15bb68b14a/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import MainRoute from './routes/MainRoute'; 3 | import { ThemeProvider } from '@mui/material'; 4 | import { BrowserRouter } from 'react-router-dom'; 5 | import { theme } from './theme/theme.config'; 6 | import store from './redux/store' 7 | import './App.css'; 8 | import { Provider } from 'react-redux'; 9 | 10 | function App() { 11 | return ( 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | ); 20 | } 21 | 22 | export default App; 23 | -------------------------------------------------------------------------------- /src/components/BreedGridDialog.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Dialog from '@mui/material/Dialog'; 3 | import DialogContent from '@mui/material/DialogContent'; 4 | import DialogTitle from '@mui/material/DialogTitle'; 5 | import Grid from '@mui/material/Grid'; 6 | 7 | interface IBreedGridDialogProps { 8 | handleClose: () => void 9 | open: boolean 10 | dlgImages: { 11 | message: Array 12 | } 13 | } 14 | const BreedGridDialog = ({handleClose, open, dlgImages}: IBreedGridDialogProps) => { 15 | return ( 16 | 22 | 23 | {"Dog Poster Generate"} 24 | 25 | 26 | 27 | {dlgImages.message && dlgImages.message.map(item => ( 28 | 29 | {'dog 37 | 38 | ))} 39 | 40 | 41 | 42 | ); 43 | }; 44 | 45 | export default BreedGridDialog; -------------------------------------------------------------------------------- /src/components/BreedsTable.tsx: -------------------------------------------------------------------------------- 1 | import { Delete, FilterList } from '@mui/icons-material'; 2 | import { alpha, Box, Checkbox, IconButton, MenuItem, Paper, Select, Table, TableBody, TableCell, TableContainer, TableHead, TablePagination, TableRow, TableSortLabel, Toolbar, Tooltip, Typography } from '@mui/material'; 3 | import { visuallyHidden } from '@mui/utils'; 4 | import React, { Suspense } from 'react'; 5 | import { StoreValue, IBreedItemType } from 'types'; 6 | import { useSelector } from 'react-redux'; 7 | import { DogApis } from 'service/api-service'; 8 | // import BreedGridDialog from './BreedGridDialog'; 9 | const BreedGridDialog = React.lazy(() => import('./BreedGridDialog')) 10 | 11 | function descendingComparator(a: T, b: T, orderBy: keyof T) { 12 | if (b[orderBy] < a[orderBy]) { 13 | return -1; 14 | } 15 | if (b[orderBy] > a[orderBy]) { 16 | return 1; 17 | } 18 | return 0; 19 | } 20 | 21 | type Order = 'asc' | 'desc'; 22 | 23 | function getComparator( 24 | order: Order, 25 | orderBy: Key, 26 | ): ( 27 | a: { [key in Key]: any }, 28 | b: { [key in Key]: any }, 29 | ) => number { 30 | return order === 'desc' 31 | ? (a, b) => descendingComparator(a, b, orderBy) 32 | : (a, b) => -descendingComparator(a, b, orderBy); 33 | } 34 | 35 | interface HeadCell { 36 | disablePadding: boolean; 37 | id?: string; 38 | label: String; 39 | numeric: boolean; 40 | } 41 | 42 | const headCells: HeadCell[] = [ 43 | { 44 | id: 'name', 45 | numeric: false, 46 | disablePadding: true, 47 | label: 'Name', 48 | }, 49 | { 50 | id: 'subBreed', 51 | numeric: false, 52 | disablePadding: false, 53 | label: 'Sub Breed', 54 | }, 55 | { 56 | id: 'subcount', 57 | numeric: true, 58 | disablePadding: false, 59 | label: 'Sub Breeds Count', 60 | }, 61 | { 62 | numeric: false, 63 | disablePadding: false, 64 | label: 'Action', 65 | } 66 | ]; 67 | 68 | interface EnhancedTableProps { 69 | numSelected: number; 70 | onRequestSort: (event: React.MouseEvent, property: string) => void; 71 | onSelectAllClick: (event: React.ChangeEvent) => void; 72 | order: Order; 73 | orderBy: String; 74 | rowCount: number; 75 | } 76 | 77 | const EnhancedTableHead = (props: EnhancedTableProps) => { 78 | const { onSelectAllClick, order, orderBy, numSelected, rowCount, onRequestSort } = 79 | props; 80 | const createSortHandler = 81 | (property: string) => (event: React.MouseEvent) => { 82 | onRequestSort(event, property); 83 | }; 84 | 85 | return ( 86 | 87 | 88 | 89 | 0 && numSelected < rowCount} 92 | checked={rowCount > 0 && numSelected === rowCount} 93 | onChange={onSelectAllClick} 94 | inputProps={{ 95 | 'aria-label': 'select all desserts', 96 | }} 97 | /> 98 | 99 | {headCells.map(({ id, numeric, disablePadding, label }, index) => ( 100 | id ? 106 | 111 | {label} 112 | {orderBy === id ? ( 113 | 114 | {order === 'desc' ? 'sorted descending' : 'sorted ascending'} 115 | 116 | ) : null} 117 | 118 | : 123 | {label} 124 | 125 | ))} 126 | 127 | 128 | ); 129 | }; 130 | 131 | interface EnhancedTableToolbarProps { 132 | numSelected: number; 133 | } 134 | 135 | const EnhancedTableToolbar = (props: EnhancedTableToolbarProps) => { 136 | const { numSelected } = props; 137 | 138 | return ( 139 | 0 && { 144 | bgcolor: (theme) => 145 | alpha(theme.palette.primary.main, theme.palette.action.activatedOpacity), 146 | }), 147 | }} 148 | > 149 | {numSelected > 0 ? ( 150 | 156 | {numSelected} selected 157 | 158 | ) : ( 159 | 165 | Recipe List 166 | 167 | )} 168 | {numSelected > 0 ? ( 169 | 170 | 171 | 172 | 173 | 174 | ) : ( 175 | 176 | 177 | 178 | 179 | 180 | )} 181 | 182 | ); 183 | }; 184 | 185 | const BreedsTable = () => { 186 | const breeds = useSelector((state: StoreValue) => state.breedReducer.breeds) 187 | const breedList: Array = Object.keys(breeds).map((item: string) => ({ 188 | breedName: item, 189 | subBreeds: breeds[item as keyof object] 190 | })) 191 | const [order, setOrder] = React.useState('asc'); 192 | const [orderBy, setOrderBy] = React.useState('name'); 193 | const [selected, setSelected] = React.useState([]); 194 | const [page, setPage] = React.useState(0); 195 | const [rowsPerPage, setRowsPerPage] = React.useState(5); 196 | const [open, setOpen] = React.useState(false); 197 | const [dlgImages, setDlgUmg] = React.useState({ 198 | message: [] 199 | }) 200 | 201 | const handleClose = () => { 202 | setOpen(false); 203 | }; 204 | 205 | const handleRequestSort = ( 206 | event: React.MouseEvent, 207 | property: string, 208 | ) => { 209 | const isAsc = orderBy === property && order === 'asc'; 210 | setOrder(isAsc ? 'desc' : 'asc'); 211 | setOrderBy(property); 212 | }; 213 | 214 | const handleSelectAllClick = (event: React.ChangeEvent) => { 215 | if (event.target.checked) { 216 | const newSelecteds = breedList.map((n) => n.breedName); 217 | setSelected(newSelecteds); 218 | return; 219 | } 220 | setSelected([]); 221 | }; 222 | 223 | const handleClick = (event: React.MouseEvent, name: string) => { 224 | const selectedIndex = selected.indexOf(name); 225 | let newSelected: string[] = []; 226 | 227 | if (selectedIndex === -1) { 228 | newSelected = newSelected.concat(selected, name); 229 | } else if (selectedIndex === 0) { 230 | newSelected = newSelected.concat(selected.slice(1)); 231 | } else if (selectedIndex === selected.length - 1) { 232 | newSelected = newSelected.concat(selected.slice(0, -1)); 233 | } else if (selectedIndex > 0) { 234 | newSelected = newSelected.concat( 235 | selected.slice(0, selectedIndex), 236 | selected.slice(selectedIndex + 1), 237 | ); 238 | } 239 | 240 | setSelected(newSelected); 241 | }; 242 | 243 | const handleChangePage = (event: unknown, newPage: number) => { 244 | setPage(newPage); 245 | }; 246 | 247 | const handleChangeRowsPerPage = (event: React.ChangeEvent) => { 248 | setRowsPerPage(parseInt(event.target.value, 10)); 249 | setPage(0); 250 | }; 251 | 252 | const isSelected = (name: string) => selected.indexOf(name) !== -1; 253 | 254 | const onGenerateClick = async (clickedBreedName: string) => { 255 | setOpen(true) 256 | const breedImages = await DogApis.getBreedImages(clickedBreedName) 257 | setDlgUmg(breedImages) 258 | } 259 | 260 | // Avoid a layout jump when reaching the last page with empty recipes. 261 | const emptyRows = 262 | page > 0 ? Math.max(0, (1 + page) * rowsPerPage - breedList.length) : 0; 263 | 264 | return ( 265 | 266 | 267 | 268 | 269 | 274 | 282 | 283 | {breedList.slice().sort(getComparator(order, orderBy)) 284 | .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) 285 | .map((breedItem: IBreedItemType) => { 286 | const { breedName, subBreeds } = breedItem 287 | const isItemSelected = isSelected(breedName); 288 | const labelId = `enhanced-table-checkbox-${breedName}`; 289 | 290 | return ( 291 | ) => handleClick(event, breedName)} 294 | role="checkbox" 295 | aria-checked={isItemSelected} 296 | tabIndex={-1} 297 | key={breedName} 298 | selected={isItemSelected} 299 | > 300 | 301 | 308 | 309 | 315 | {breedName} 316 | 317 | 323 | 324 | 331 | 332 | 333 | {subBreeds.length} 334 | 335 | onGenerateClick(breedName)} 338 | > 339 | Generate 340 | 341 | 342 | 343 | ); 344 | })} 345 | {emptyRows > 0 && ( 346 | 351 | 352 | 353 | )} 354 | 355 |
356 |
357 | 366 |
367 | Loading posts...}> 368 | 373 | 374 |
375 | ); 376 | } 377 | 378 | export default BreedsTable; -------------------------------------------------------------------------------- /src/components/Header.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {render} from '@testing-library/react'; 3 | import Header from './Header'; 4 | 5 | it('header component', () => { 6 | const {getByText} = render(
); 7 | 8 | expect(getByText(/Dog Poster Generator/i)).toBeTruthy(); 9 | }) -------------------------------------------------------------------------------- /src/components/Header.tsx: -------------------------------------------------------------------------------- 1 | import { AppBar, Box, Link, Toolbar, Typography } from '@mui/material'; 2 | import React from 'react'; 3 | 4 | /** 5 | * Header component. 6 | */ 7 | const Header = () => { 8 | return ( 9 | 10 | 11 | 12 | 13 | Dog Poster Generator 14 | 15 | 16 | 17 | 18 | ); 19 | }; 20 | 21 | export default Header; -------------------------------------------------------------------------------- /src/context/app-state-context.ts: -------------------------------------------------------------------------------- 1 | import { createContext } from "react"; 2 | 3 | export interface AppState { 4 | breeds: object 5 | } 6 | 7 | export const initialState: AppState = { 8 | breeds: {} 9 | } 10 | 11 | const AppStateContext = createContext(initialState) 12 | 13 | export default AppStateContext -------------------------------------------------------------------------------- /src/index.scss: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.scss'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root'), 12 | ); 13 | // If you want to start measuring performance in your app, pass a function 14 | // to log results (for example: reportWebVitals(console.log)) 15 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 16 | reportWebVitals(undefined); 17 | -------------------------------------------------------------------------------- /src/layouts/MainLayout.tsx: -------------------------------------------------------------------------------- 1 | import Box from '@mui/material/Box'; 2 | import React, { PropsWithChildren } from 'react'; 3 | import Header from '../components/Header'; 4 | 5 | /** 6 | * MainLayout is using on the all pages 7 | */ 8 | const MainLayout = ({children}: PropsWithChildren<{}>) => { 9 | return ( 10 | 11 |
12 | 13 | {children} 14 | 15 | 16 | ); 17 | }; 18 | 19 | export default MainLayout; -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/mock/db.json: -------------------------------------------------------------------------------- 1 | { 2 | "recipes": [ 3 | { 4 | "id": 1, 5 | "name": "Beef Enchiladas", 6 | "createdAt": "2022-05-15T13:45:30", 7 | "creatorName": "Bailey King", 8 | "cookingTime": 0.5, 9 | "ingredients": [ 10 | "Black Pepper", 11 | "Cumin", 12 | "Coriander", 13 | "Bay Leaves", 14 | "Paprika" 15 | ], 16 | "instructions": [ 17 | "Broiling", 18 | "Baking", 19 | "Pot roasting" 20 | ] 21 | }, 22 | { 23 | "id": 2, 24 | "name": "Frito Pie", 25 | "createdAt": "2022-05-21T15:24:31", 26 | "creatorName": "Kelsey Powers", 27 | "cookingTime": 1, 28 | "ingredients": [ 29 | "Paprika", 30 | "Cayenne", 31 | "Fennel", 32 | "Turmeric", 33 | "Paprika" 34 | ], 35 | "instructions": [ 36 | "Tandoor roasting", 37 | "Grilling", 38 | "Deep frying" 39 | ] 40 | }, 41 | { 42 | "id": 3, 43 | "name": "Favorite Meatloaf", 44 | "createdAt": "2022-05-12T21:45:30", 45 | "creatorName": "Brady Mayo", 46 | "cookingTime": 0.3, 47 | "ingredients": [ 48 | "Fennel", 49 | "Turmeric", 50 | "Cinnamon", 51 | "Nutmeg", 52 | "Thyme", 53 | "Paprika" 54 | ], 55 | "instructions": [ 56 | "Boiling", 57 | "Poaching", 58 | "Direct steaming" 59 | ] 60 | }, 61 | { 62 | "id": 4, 63 | "name": "General Tso’s Chicken", 64 | "createdAt": "2022-05-11T22:15:30", 65 | "creatorName": "Sawyer Jarvis", 66 | "cookingTime": 0.2, 67 | "ingredients": [ 68 | "Nutmeg", 69 | "Thyme", 70 | "Oregano", 71 | "Chile Flakes", 72 | "Paprika" 73 | ], 74 | "instructions": [ 75 | "Tandoor roasting", 76 | "Grilling", 77 | "Deep frying" 78 | ] 79 | }, 80 | { 81 | "id": 5, 82 | "name": "Slow Cooker BBQ Ribs", 83 | "createdAt": "2022-05-22T05:25:10", 84 | "creatorName": "Toby Macdonald", 85 | "cookingTime": 0.4, 86 | "ingredients": [ 87 | "Black Pepper", 88 | "Cumin", 89 | "Coriander", 90 | "Bay Leaves", 91 | "Paprika" 92 | ], 93 | "instructions": [ 94 | "Tandoor roasting", 95 | "Grilling", 96 | "Deep frying" 97 | ] 98 | }, 99 | { 100 | "id": 6, 101 | "name": "Turkey Tetrazzini", 102 | "createdAt": "2009-06-15T13:45:30", 103 | "creatorName": "Ramiro Wilkinson", 104 | "cookingTime": 1.2, 105 | "ingredients": [ 106 | "Black Pepper", 107 | "Cumin", 108 | "Coriander", 109 | "Bay Leaves", 110 | "Paprika" 111 | ], 112 | "instructions": [ 113 | "Tandoor roasting", 114 | "Grilling", 115 | "Deep frying" 116 | ] 117 | }, 118 | { 119 | "id": 7, 120 | "name": "Frito Pie", 121 | "createdAt": "2022-02-22T22:22:22", 122 | "creatorName": "Alena Aguilar", 123 | "cookingTime": 1.5, 124 | "ingredients": [ 125 | "Nutmeg", 126 | "Thyme", 127 | "Oregano", 128 | "Chile Flakes", 129 | "Chile Powder" 130 | ], 131 | "instructions": [ 132 | "Tandoor roasting", 133 | "Grilling", 134 | "Deep frying" 135 | ] 136 | } 137 | ] 138 | } -------------------------------------------------------------------------------- /src/pages/Home.tsx: -------------------------------------------------------------------------------- 1 | import BreedsTable from 'components/BreedsTable'; 2 | import React, { useEffect } from 'react'; 3 | import { useDispatch, useSelector } from 'react-redux'; 4 | import { DogApis } from 'service/api-service'; 5 | import { setBreeds } from 'redux/redux-slice'; 6 | import { StoreValue } from 'types'; 7 | import mainLayoutWrapHOC from 'pages/hoc/MainLayoutWrapHOC'; 8 | 9 | /** 10 | * Pulling data from the dog server and dispatch data into the store 11 | */ 12 | const Home = () => { 13 | 14 | const breeds = useSelector((state: StoreValue) => state.breedReducer.breeds) 15 | const dispatch = useDispatch() 16 | 17 | useEffect(() => { 18 | const getBreeds = async (): Promise => { 19 | try { 20 | const allBreeds: object = await DogApis.getAllBreeds() 21 | dispatch(setBreeds(allBreeds)) 22 | } catch (e: any) { 23 | console.log('Get Recipes Error : ', e.response?.data?.message) 24 | } 25 | } 26 | if (breeds && Object.keys(breeds).length === 0 ) { 27 | getBreeds() 28 | } 29 | }, [dispatch, breeds]) 30 | 31 | return ( 32 | 33 | ); 34 | }; 35 | 36 | export default mainLayoutWrapHOC(Home); -------------------------------------------------------------------------------- /src/pages/hoc/MainLayoutWrapHOC.tsx: -------------------------------------------------------------------------------- 1 | import MainLayout from 'layouts/MainLayout'; 2 | import React from 'react'; 3 | 4 | const mainLayoutWrapHOC = (Component: any) => ({...props})=> { 5 | return ( 6 | 7 | 8 | 9 | ); 10 | }; 11 | 12 | export default mainLayoutWrapHOC; -------------------------------------------------------------------------------- /src/redux/redux-slice.ts: -------------------------------------------------------------------------------- 1 | import { createSlice } from "@reduxjs/toolkit"; 2 | import { StoreType } from "types"; 3 | 4 | export interface ReducerSetBreedsActionType { 5 | payload: { 6 | message: object 7 | status: string 8 | } 9 | } 10 | 11 | let initBreedsValueFromLocalStorage: object = {}; 12 | // const localStorageData = window.localStorage.getItem('MY_APP_STATE') 13 | // if (localStorageData) { 14 | // initBreedsValueFromLocalStorage = JSON.parse(localStorageData) 15 | // } 16 | 17 | export const reduxSlice: any = createSlice({ 18 | name: 'reduxSlice', 19 | initialState: { 20 | breeds: initBreedsValueFromLocalStorage 21 | }, 22 | reducers: { 23 | setBreeds: (state: StoreType, action: ReducerSetBreedsActionType) => { 24 | state.breeds = action.payload.message 25 | window.localStorage.setItem('MY_APP_STATE', JSON.stringify(state.breeds)); 26 | } 27 | } 28 | }) 29 | 30 | export const { setBreeds } = reduxSlice.actions 31 | 32 | export default reduxSlice.reducer -------------------------------------------------------------------------------- /src/redux/store.ts: -------------------------------------------------------------------------------- 1 | import { configureStore } from "@reduxjs/toolkit"; 2 | import breedReducer from './redux-slice' 3 | 4 | export default configureStore({ 5 | reducer: { 6 | breedReducer: breedReducer 7 | } 8 | }) -------------------------------------------------------------------------------- /src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry: ReportHandler | undefined) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /src/routes/MainRoute.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Route, Routes } from 'react-router-dom'; 3 | import Home from '../pages/Home'; 4 | 5 | /** 6 | * Main Route for the application 7 | */ 8 | const MainRoute = () => { 9 | return ( 10 | 11 | } /> 12 | 13 | ); 14 | }; 15 | 16 | export default MainRoute; -------------------------------------------------------------------------------- /src/service/api-service.ts: -------------------------------------------------------------------------------- 1 | import { BASE_URL, httpClient } from "./http-client" 2 | 3 | export const DogApis = { 4 | getAllBreeds: async () => await httpClient.get(`${BASE_URL}breeds/list/all`), 5 | getBreedImages: async (breed: string) => await httpClient.get(`${BASE_URL}breed/${breed}/images`), 6 | getSubBreeds: async (breed: string) => await httpClient.get(`${BASE_URL}breed/${breed}/list`), 7 | } -------------------------------------------------------------------------------- /src/service/http-client.ts: -------------------------------------------------------------------------------- 1 | import Axios, { AxiosRequestHeaders } from "axios" 2 | 3 | class HttpClient { 4 | static instance: HttpClient | null = null 5 | public static getInstance(): HttpClient { 6 | if (!HttpClient.instance) { 7 | HttpClient.instance = new HttpClient() 8 | } 9 | 10 | return HttpClient.instance 11 | } 12 | 13 | private constructor() { } 14 | 15 | get = async ( 16 | url: string, 17 | params: object = {}, 18 | headers: AxiosRequestHeaders = {} 19 | ): Promise => { 20 | const { data } = await Axios.get(url, { params, headers }) 21 | return data 22 | } 23 | 24 | post = async ( 25 | url: string, 26 | body: object, 27 | params: object = {}, 28 | headers: AxiosRequestHeaders = {} 29 | ): Promise => { 30 | const { data } = await Axios.post(url, body, { params, headers }) 31 | return data 32 | } 33 | 34 | put = async ( 35 | url: string, 36 | body: object, 37 | params: object = {}, 38 | headers: AxiosRequestHeaders = {} 39 | ): Promise => { 40 | const { data } = await Axios.put(url, body, { params, headers }) 41 | return data 42 | } 43 | 44 | delete = async ( 45 | url: string, 46 | params: object = {}, 47 | headers: AxiosRequestHeaders = {} 48 | ): Promise => { 49 | const { data } = await Axios.delete(url, { params, headers }) 50 | return data 51 | } 52 | 53 | } 54 | 55 | export const httpClient = HttpClient.getInstance() 56 | export const BASE_URL = 'https://dog.ceo/api/' -------------------------------------------------------------------------------- /src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /src/theme/theme.config.ts: -------------------------------------------------------------------------------- 1 | import { createTheme } from "@mui/material"; 2 | 3 | export const theme = createTheme({ 4 | // palette: { 5 | // text:{ 6 | // primary: "#000000", 7 | // secondary: '#222222' 8 | // } 9 | // }, 10 | breakpoints: { 11 | values: { 12 | xs: 0, 13 | sm: 600, 14 | md: 900, 15 | lg: 1200, 16 | xl: 1536, 17 | } 18 | }, 19 | typography: { 20 | fontSize: 16 21 | } 22 | }) -------------------------------------------------------------------------------- /src/types/index.ts: -------------------------------------------------------------------------------- 1 | export interface StoreType { 2 | breeds: object 3 | } 4 | export interface StoreValue { 5 | breedReducer: StoreType 6 | } 7 | 8 | export interface IBreedItemType { 9 | breedName: string 10 | subBreeds: Array 11 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "jsx": "react-jsx", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 10 | "module": "esnext", /* Specify what module code is generated. */ 11 | "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ 12 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 13 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 14 | "strict": true, /* Enable all strict type-checking options. */ 15 | "skipLibCheck": true, /* Skip type checking all .d.ts files. */ 16 | "allowJs": true, 17 | "allowSyntheticDefaultImports": true, 18 | "noFallthroughCasesInSwitch": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true, 22 | "baseUrl": "src" 23 | }, 24 | "include": [ 25 | "src" 26 | ] 27 | } 28 | --------------------------------------------------------------------------------