This repository was archived by the owner on Aug 17, 2021. It is now read-only.
  
  
  - 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Routing #16
          
     Open
      
      
            veksi
  wants to merge
  9
  commits into
  master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
feature/routing
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Routing #16
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            9 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      a28b34a
              
                Project setup
              
              
                veksi 810b083
              
                Project setup
              
              
                veksi 0372299
              
                Project setup
              
              
                veksi 8a94479
              
                Add related typings
              
              
                veksi 5e4d8f0
              
                Add About container
              
              
                veksi ba9a321
              
                Add Home container
              
              
                veksi 3418360
              
                Refactor App container
              
              
                veksi 147b9bf
              
                Add IAbout interface
              
              
                veksi 02bf445
              
                Add mock api call
              
              
                veksi File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import { BrowserRouter } from 'react-router-dom'; | ||
|  | ||
| import { Navbar } from './Navbar'; | ||
|  | ||
| it('renders without crashing', () => { | ||
| const div = document.createElement('div'); | ||
| ReactDOM.render( | ||
| <BrowserRouter> | ||
| <Navbar /> | ||
| </BrowserRouter>, | ||
| div); | ||
| ReactDOM.unmountComponentAtNode(div); | ||
| }); | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { css } from 'emotion'; | ||
| import * as React from 'react'; | ||
| import { NavLink } from 'react-router-dom' | ||
| import { LINK_COLOR } from '../consts/colors'; | ||
|  | ||
| const navbarClass = css` | ||
| height: 100px; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| margin-bottom: 100px; | ||
| `; | ||
|  | ||
| const navigationLink = css` | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The class variables should be named consistently, so better to add the  | ||
| text-decoration: none; | ||
| color: white; | ||
| margin: 0 10px; | ||
|  | ||
| &:hover { | ||
| text-decoration: underline; | ||
| } | ||
| `; | ||
|  | ||
| const activeLink = css` | ||
| color: ${LINK_COLOR} !important; | ||
| `; | ||
|  | ||
| export const Navbar: React.FC<{}> = () => { | ||
|  | ||
| return ( | ||
| <nav className={navbarClass}> | ||
| <NavLink exact to="/" className={navigationLink} activeClassName={activeLink}>HOME</NavLink> | ||
| <NavLink to="/about" className={navigationLink} activeClassName={activeLink}>ABOUT</NavLink> | ||
| </nav> | ||
| ); | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import About from './About'; | ||
|  | ||
| it('renders without crashing', () => { | ||
| const div = document.createElement('div'); | ||
| ReactDOM.render(<About />, div); | ||
| ReactDOM.unmountComponentAtNode(div); | ||
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import * as React from 'react'; | ||
|  | ||
| import { getApiData } from '../services/api'; | ||
|  | ||
| const About: React.FC<{}> = () => { | ||
| const [title, setTitle] = React.useState(''); | ||
| const [content, setContent] = React.useState(''); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should also handle the loading and error states. That's quite simple with the  | ||
|  | ||
| React.useEffect(() => { | ||
| const fetchData = async () => { | ||
| const aboutPageContent = await getApiData(); | ||
| const { title, content } = aboutPageContent; | ||
|  | ||
| setTitle(title); | ||
| setContent(content); | ||
| } | ||
|  | ||
| fetchData(); | ||
| }, [title]); | ||
|  | ||
| return ( | ||
| <React.Fragment> | ||
| <div> | ||
| <h1>{title}</h1> | ||
| <p>{content}</p> | ||
| </div> | ||
| </React.Fragment> | ||
| ); | ||
| } | ||
|  | ||
| export default About; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,94 +1,53 @@ | ||
| import { css, keyframes } from 'emotion'; | ||
| import { css } from 'emotion'; | ||
| import * as React from 'react'; | ||
| import { BrowserRouter } from 'react-router-dom' | ||
| import { Switch, Route } from 'react-router' | ||
|  | ||
| import logo from '../assets/logo.svg'; | ||
| import { Footer } from '../components/Footer'; | ||
| import { BACKGROUND_PRIMARY, LINK_COLOR } from '../consts/colors'; | ||
| import { Navbar } from '../components/Navbar'; | ||
| import { BACKGROUND_PRIMARY } from '../consts/colors'; | ||
|  | ||
| const logoSpinKeyframes = keyframes` | ||
| from { | ||
| transform: rotate(0deg); | ||
| } | ||
| to { | ||
| transform: rotate(360deg); | ||
| } | ||
| `; | ||
| const Home = React.lazy(() => import('./Home')); | ||
| const About = React.lazy(() => import('./About')); | ||
|  | ||
| const appClass = css` | ||
| display: flex; | ||
| flex-direction: column; | ||
| text-align: center; | ||
| `; | ||
|  | ||
| const logoClass = (animationSpeed: number) => css` | ||
| animation: ${logoSpinKeyframes} infinite ${animationSpeed}s linear; | ||
| height: 30vmin; | ||
| `; | ||
|  | ||
| const buttonClass = css` | ||
| padding: 10px; | ||
| margin: 5px; | ||
| `; | ||
|  | ||
| const stateContaninerClass = css` | ||
| margin: 40px 0; | ||
| `; | ||
|  | ||
| const headerClass = css` | ||
| background-color: ${BACKGROUND_PRIMARY}; | ||
| min-height: 100vh; | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| font-size: calc(10px + 2vmin); | ||
| color: white; | ||
| `; | ||
|  | ||
| const linkClass = css` | ||
| color: ${LINK_COLOR}; | ||
| `; | ||
|  | ||
| const footerClass = css` | ||
| margin-top: 100px; | ||
| font-size: 16px; | ||
| `; | ||
|  | ||
| export const App: React.FC<{}> = () => { | ||
| const [animationSpeed, setAnimationSpeed] = React.useState(40); | ||
| const mainClass = css` | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| `; | ||
|  | ||
| const onButtonClick = (action: string) => { | ||
| return () => { | ||
| if (action === '+' && animationSpeed > 5) { | ||
| setAnimationSpeed(animationSpeed - 5); | ||
| } else if (action === '-') { | ||
| setAnimationSpeed(animationSpeed + 5); | ||
| } | ||
| } | ||
| } | ||
| export const App: React.FC<{}> = () => { | ||
|  | ||
| return ( | ||
| <div className={appClass}> | ||
| <main className={headerClass}> | ||
| <img src={logo} className={logoClass(animationSpeed)} alt="logo" /> | ||
| <p> | ||
| Edit <code>src/containers/App.tsx</code> and save to reload. | ||
| </p> | ||
| <div className={stateContaninerClass}> | ||
| <span>ANIMATION SPEED</span> | ||
| <div> | ||
| <button className={buttonClass} onClick={onButtonClick('+')}>+</button> | ||
| <button className={buttonClass} onClick={onButtonClick('-')}>-</button> | ||
| </div> | ||
| </div> | ||
| <a | ||
| className={linkClass} | ||
| href="https://reactjs.org" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| Learn React | ||
| </a> | ||
| <BrowserRouter> | ||
| <div className={appClass}> | ||
| <Navbar /> | ||
| <main className={mainClass}> | ||
| <React.Suspense fallback={<div>Loading...</div>}> | ||
| <Switch> | ||
| <Route exact path="/" component={Home}/> | ||
| <Route path="/about" component={About}/> | ||
| </Switch> | ||
| </React.Suspense> | ||
| </main> | ||
| <Footer className={footerClass} /> | ||
| </main> | ||
| </div> | ||
| </div> | ||
| </BrowserRouter> | ||
| ); | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import Home from './Home'; | ||
|  | ||
| it('renders without crashing', () => { | ||
| const div = document.createElement('div'); | ||
| ReactDOM.render(<Home />, div); | ||
| ReactDOM.unmountComponentAtNode(div); | ||
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { css, keyframes } from 'emotion'; | ||
| import * as React from 'react'; | ||
|  | ||
| import logo from '../assets/logo.svg'; | ||
| import { LINK_COLOR } from '../consts/colors'; | ||
|  | ||
| const logoSpinKeyframes = keyframes` | ||
| from { | ||
| transform: rotate(0deg); | ||
| } | ||
| to { | ||
| transform: rotate(360deg); | ||
| } | ||
| `; | ||
|  | ||
| const logoClass = (animationSpeed: number) => css` | ||
| animation: ${logoSpinKeyframes} infinite ${animationSpeed}s linear; | ||
| height: 30vmin; | ||
| `; | ||
|  | ||
| const buttonClass = css` | ||
| padding: 10px; | ||
| margin: 5px; | ||
| `; | ||
|  | ||
| const stateContaninerClass = css` | ||
| margin: 40px 0; | ||
| `; | ||
|  | ||
| const linkClass = css` | ||
| color: ${LINK_COLOR}; | ||
| `; | ||
|  | ||
| const Home: React.FC<{}> = () => { | ||
| const [animationSpeed, setAnimationSpeed] = React.useState(40); | ||
|  | ||
| const onButtonClick = (action: string) => { | ||
| return () => { | ||
| if (action === '+' && animationSpeed > 5) { | ||
| setAnimationSpeed(animationSpeed - 5); | ||
| } else if (action === '-') { | ||
| setAnimationSpeed(animationSpeed + 5); | ||
| } | ||
| } | ||
| } | ||
|  | ||
| return ( | ||
| <React.Fragment> | ||
| <img src={logo} className={logoClass(animationSpeed)} alt="logo" /> | ||
| <p> | ||
| Edit <code>src/containers/App.tsx</code> and save to reload. | ||
| </p> | ||
| <div className={stateContaninerClass}> | ||
| <span>ANIMATION SPEED</span> | ||
| <div> | ||
| <button className={buttonClass} onClick={onButtonClick('+')}>+</button> | ||
| <button className={buttonClass} onClick={onButtonClick('-')}>-</button> | ||
| </div> | ||
| </div> | ||
| <a | ||
| className={linkClass} | ||
| href="https://reactjs.org" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| Learn React | ||
| </a> | ||
| </React.Fragment> | ||
| ); | ||
| } | ||
|  | ||
| export default Home; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export interface IAbout { | ||
| title: string; | ||
| content: string; | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { IAbout } from '../interfaces/IAbout'; | ||
|  | ||
| export function getApiData(): Promise<IAbout> { | ||
| return new Promise((resolve) => { | ||
| setTimeout(() => { | ||
| resolve({ | ||
| title: 'JS-CRA-STARTER', | ||
| content: 'Some text, since someone said lorem ipsum is deprecated.' | ||
| }) | ||
| }, 500); | ||
| }) | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -21,6 +21,3 @@ | |
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|  | ||
|  | ||
| .cache | ||
This file was deleted.
      
      Oops, something went wrong.
      
    
  This file was deleted.
      
      Oops, something went wrong.
      
    
  This file was deleted.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't something like
const footer = create(<Footer />);also work instead of rendering into the DOM?