├── src ├── react-app-env.d.ts ├── services │ └── api.ts ├── index.tsx ├── store │ ├── ducks │ │ ├── rootReducer.ts │ │ ├── rootSaga.ts │ │ └── repositories │ │ │ ├── actions.ts │ │ │ ├── sagas.ts │ │ │ ├── types.ts │ │ │ └── index.ts │ └── index.ts ├── App.tsx └── components │ ├── RepositoryItem │ └── index.tsx │ └── RepositoryList │ └── index.tsx ├── public ├── favicon.ico ├── manifest.json └── index.html ├── .gitignore ├── tsconfig.json ├── .eslintrc.js ├── package.json └── README.md /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rocketseat-content/youtube-typescript-reactjs/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /src/services/api.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | const api = axios.create({ 4 | baseURL: 'https://api.github.com', 5 | }); 6 | 7 | export default api; 8 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | ReactDOM.render(, document.getElementById('root')); 6 | -------------------------------------------------------------------------------- /src/store/ducks/rootReducer.ts: -------------------------------------------------------------------------------- 1 | import { combineReducers } from 'redux'; 2 | 3 | import repositories from './repositories'; 4 | 5 | export default combineReducers({ 6 | repositories, 7 | }); 8 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Provider } from 'react-redux'; 3 | 4 | import RepositoryList from './components/RepositoryList'; 5 | 6 | import store from './store'; 7 | 8 | const App = () => ; 9 | 10 | export default App; 11 | -------------------------------------------------------------------------------- /src/components/RepositoryItem/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import { Repository } from '../../store/ducks/repositories/types'; 4 | 5 | interface OwnProps { 6 | repository: Repository 7 | } 8 | 9 | export default function RepositoryItem({ repository }: OwnProps) { 10 | return
  • {repository.name}
  • ; 11 | } 12 | -------------------------------------------------------------------------------- /src/store/ducks/rootSaga.ts: -------------------------------------------------------------------------------- 1 | import { all, takeLatest } from 'redux-saga/effects'; 2 | 3 | import { RepositoriesTypes } from './repositories/types'; 4 | import { load } from './repositories/sagas'; 5 | 6 | export default function* rootSaga() { 7 | return yield all([ 8 | takeLatest(RepositoriesTypes.LOAD_REQUEST, load), 9 | ]); 10 | } 11 | -------------------------------------------------------------------------------- /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 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /src/store/ducks/repositories/actions.ts: -------------------------------------------------------------------------------- 1 | import { action } from 'typesafe-actions'; 2 | import { RepositoriesTypes, Repository } from './types'; 3 | 4 | export const loadRequest = () => action(RepositoriesTypes.LOAD_REQUEST); 5 | 6 | export const loadSuccess = (data: Repository[]) => action(RepositoriesTypes.LOAD_SUCCCES, { data }); 7 | 8 | export const loadFailure = () => action(RepositoriesTypes.LOAD_FAILURE); 9 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /src/store/ducks/repositories/sagas.ts: -------------------------------------------------------------------------------- 1 | import { call, put } from 'redux-saga/effects'; 2 | import api from '../../../services/api'; 3 | 4 | import { loadSuccess, loadFailure } from './actions'; 5 | 6 | export function* load() { 7 | try { 8 | const response = yield call(api.get, 'users/diego3g/repos'); 9 | 10 | yield put(loadSuccess(response.data)); 11 | } catch (err) { 12 | yield put(loadFailure()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/store/ducks/repositories/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Action types 3 | */ 4 | export enum RepositoriesTypes { 5 | LOAD_REQUEST = '@repositories/LOAD_REQUEST', 6 | LOAD_SUCCCES = '@repositories/LOAD_SUCCCES', 7 | LOAD_FAILURE = '@repositories/LOAD_FAILURE' 8 | } 9 | 10 | /** 11 | * Data types 12 | */ 13 | export interface Repository { 14 | id: number 15 | name: string 16 | } 17 | 18 | /** 19 | * State type 20 | */ 21 | export interface RepositoriesState { 22 | readonly data: Repository[] 23 | readonly loading: boolean 24 | readonly error: boolean 25 | } 26 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "module": "esnext", 16 | "moduleResolution": "node", 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "noEmit": true, 20 | "jsx": "preserve" 21 | }, 22 | "include": [ 23 | "src" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /src/store/index.ts: -------------------------------------------------------------------------------- 1 | import { createStore, applyMiddleware, Store } from 'redux'; 2 | import createSagaMiddleware from 'redux-saga'; 3 | import { RepositoriesState } from './ducks/repositories/types'; 4 | 5 | import rootReducer from './ducks/rootReducer'; 6 | import rootSaga from './ducks/rootSaga'; 7 | 8 | export interface ApplicationState { 9 | repositories: RepositoriesState 10 | } 11 | 12 | const sagaMiddleware = createSagaMiddleware(); 13 | 14 | const store: Store = createStore(rootReducer, applyMiddleware(sagaMiddleware)); 15 | 16 | sagaMiddleware.run(rootSaga); 17 | 18 | export default store; 19 | -------------------------------------------------------------------------------- /src/store/ducks/repositories/index.ts: -------------------------------------------------------------------------------- 1 | import { Reducer } from 'redux'; 2 | import { RepositoriesState, RepositoriesTypes } from './types'; 3 | 4 | const INITIAL_STATE: RepositoriesState = { 5 | data: [], 6 | error: false, 7 | loading: false, 8 | }; 9 | 10 | const reducer: Reducer = (state = INITIAL_STATE, action) => { 11 | switch (action.type) { 12 | case RepositoriesTypes.LOAD_REQUEST: 13 | return { ...state, loading: true }; 14 | case RepositoriesTypes.LOAD_SUCCCES: 15 | return { 16 | ...state, loading: false, error: false, data: action.payload.data, 17 | }; 18 | case RepositoriesTypes.LOAD_FAILURE: 19 | return { 20 | ...state, loading: false, error: true, data: [], 21 | }; 22 | default: 23 | return state; 24 | } 25 | }; 26 | 27 | export default reducer; 28 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | browser: true, 4 | es6: true, 5 | jest: true, 6 | }, 7 | extends: [ 8 | 'react-app', 9 | 'airbnb', 10 | 'plugin:@typescript-eslint/recommended', 11 | 'prettier/@typescript-eslint', 12 | ], 13 | globals: { 14 | Atomics: 'readonly', 15 | SharedArrayBuffer: 'readonly', 16 | }, 17 | parserOptions: { 18 | ecmaFeatures: { 19 | jsx: true, 20 | }, 21 | ecmaVersion: 2018, 22 | sourceType: 'module', 23 | }, 24 | plugins: ['react', 'import', 'jsx-a11y'], 25 | rules: { 26 | 'react/jsx-filename-extension': [ 27 | 'error', 28 | { 29 | extensions: ['.tsx'], 30 | }, 31 | ], 32 | 'import/prefer-default-export': 'off', 33 | '@typescript-eslint/explicit-function-return-type': 'off', 34 | '@typescript-eslint/explicit-member-accessibility': 'off' 35 | }, 36 | settings: { 37 | 'import/parsers': { 38 | '@typescript-eslint/parser': ['.ts', '.tsx'], 39 | }, 40 | 'import/resolver': { 41 | typescript: {}, 42 | }, 43 | }, 44 | }; 45 | -------------------------------------------------------------------------------- /src/components/RepositoryList/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { connect } from 'react-redux'; 3 | import { bindActionCreators, Dispatch } from 'redux'; 4 | 5 | import { Repository } from '../../store/ducks/repositories/types'; 6 | import { ApplicationState } from '../../store'; 7 | 8 | import * as RepositoriesActions from '../../store/ducks/repositories/actions'; 9 | 10 | import RepositoryItem from '../RepositoryItem'; 11 | 12 | interface StateProps { 13 | repositories: Repository[] 14 | } 15 | 16 | interface DispatchProps { 17 | loadRequest(): void 18 | } 19 | 20 | type Props = StateProps & DispatchProps 21 | 22 | class RepositoryList extends Component { 23 | componentDidMount() { 24 | const { loadRequest } = this.props; 25 | 26 | loadRequest(); 27 | } 28 | 29 | render() { 30 | const { repositories } = this.props; 31 | 32 | return ( 33 |
      34 | {repositories.map(repository => ( 35 | 36 | ))} 37 |
    38 | ); 39 | } 40 | } 41 | 42 | const mapStateToProps = (state: ApplicationState) => ({ 43 | repositories: state.repositories.data, 44 | }); 45 | 46 | const mapDispatchToProps = (dispatch: Dispatch) => bindActionCreators(RepositoriesActions, dispatch); 47 | 48 | export default connect(mapStateToProps, mapDispatchToProps)(RepositoryList); 49 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tsreact", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@types/jest": "24.0.11", 7 | "@types/node": "11.11.7", 8 | "@types/react": "16.8.8", 9 | "@types/react-dom": "16.8.3", 10 | "axios": "^0.18.0", 11 | "react": "^16.8.5", 12 | "react-dom": "^16.8.5", 13 | "react-redux": "^6.0.1", 14 | "react-scripts": "2.1.8", 15 | "redux": "^4.0.1", 16 | "redux-saga": "^1.0.2", 17 | "typesafe-actions": "^3.2.1", 18 | "typescript": "3.3.4000" 19 | }, 20 | "scripts": { 21 | "start": "react-scripts start", 22 | "build": "react-scripts build", 23 | "test": "react-scripts test", 24 | "eject": "react-scripts eject" 25 | }, 26 | "eslintConfig": { 27 | "extends": "react-app" 28 | }, 29 | "browserslist": [ 30 | ">0.2%", 31 | "not dead", 32 | "not ie <= 11", 33 | "not op_mini all" 34 | ], 35 | "devDependencies": { 36 | "@types/react-redux": "^7.0.5", 37 | "@typescript-eslint/eslint-plugin": "^1.5.0", 38 | "@typescript-eslint/parser": "^1.5.0", 39 | "eslint-config-airbnb": "^17.1.0", 40 | "eslint-config-prettier": "^4.1.0", 41 | "eslint-import-resolver-typescript": "^1.1.1", 42 | "eslint-plugin-import": "^2.16.0", 43 | "eslint-plugin-jsx-a11y": "^6.2.1", 44 | "eslint-plugin-prettier": "^3.0.1", 45 | "eslint-plugin-react": "^7.12.4", 46 | "prettier": "^1.16.4" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 15 | 16 | 25 | React App 26 | 27 | 28 | 29 |
    30 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
    10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
    13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
    18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
    23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
    26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | 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. 35 | 36 | 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. 37 | 38 | 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. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | --------------------------------------------------------------------------------