-
Notifications
You must be signed in to change notification settings - Fork 18
Hooks2 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eya26
wants to merge
4
commits into
MedTech-CS311:class-components
Choose a base branch
from
eya26:hooks2
base: class-components
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
Hooks2 #2
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Large diffs are not rendered by default.
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
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 |
|---|---|---|
| @@ -1,17 +1,20 @@ | ||
| import React from "react"; | ||
|
|
||
| import { Link } from "react-router-dom"; | ||
| import logo from "../../assets/img/logo.svg"; | ||
| function Navbar () { | ||
|
|
||
| export default class Navbar extends React.Component { | ||
|
|
||
| render() { | ||
|
|
||
| return ( | ||
| <div className="navbar"> | ||
| <div className="navbar-logo-container"> | ||
| <img src={logo} className="navbar-logo-img" alt="logo"/> | ||
| </div> | ||
| </div> | ||
| <nav class="myNav"> | ||
| <img src={logo} className="navbar-logo-img" alt="logo"/> | ||
| <ul> | ||
| <li><a href="/List.js">Organisations</a></li> | ||
| <li><a href="/RepositoriesList.js">Repositories</a></li> | ||
| </ul> | ||
| </nav> | ||
| ) | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| } | ||
| export default Navbar; |
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 |
|---|---|---|
| @@ -1,60 +1,56 @@ | ||
| import React from "react"; | ||
| import axios from "axios"; | ||
| import React, { useEffect, useState } from "react"; | ||
| //import axios from "axios"; | ||
| import SingleRepository from "./SingleRepository"; | ||
| import { useSelector, useDispatch } from "react-redux"; | ||
| import fetchRepos from "../../redux/actions/repos.actions"; | ||
|
|
||
| export default class RepositoriesList extends React.Component { | ||
| constructor() { | ||
| super() | ||
| this.state = { | ||
| filters: { | ||
| page: 1, | ||
| per_page: 10, | ||
| visibility: "public" | ||
| }, | ||
| repos: [] | ||
| } | ||
| } | ||
| function RepositoriesList () { | ||
| const [filters, setFilters] = useState({page:1,per_page:10,visibility:"public"}) | ||
| //const [repos,setRepo] = useState([]) | ||
|
|
||
| componentDidMount() { | ||
| this.fetchRepos(); | ||
| } | ||
| const repos = useSelector((state) => state.repos.reposList ) | ||
| const dispatch = useDispatch() | ||
|
|
||
| fetchRepos = () => { | ||
| this.setState({ repos: "loading" }) | ||
| useEffect ( () => { | ||
| dispatch(fetchRepos) | ||
| }, []) | ||
|
|
||
| /*const fetchRepos = () => { | ||
| setRepo( "loading" ) | ||
| axios.get("https://api.github.com/user/repos", { | ||
| params: this.state.filters | ||
| params: filters | ||
| }) | ||
| .then((response) => { | ||
| this.setState({ repos: response.data }) | ||
| setRepo(response.data ) | ||
| }) | ||
| .catch((error) => { | ||
| console.log(error) | ||
| this.setState({ repos: [] }) | ||
| setRepo( [] ) | ||
| }) | ||
| } | ||
| }*/ | ||
|
|
||
| handleNextPage = () => { | ||
| this.setState({ | ||
| filters: { ...this.state.filters, page: this.state.filters.page + 1} | ||
| const handleNextPage = () => { | ||
| setFilters({ | ||
| filters: { ...filters, page: filters.page + 1} | ||
| }, () => { | ||
| this.fetchRepos(); | ||
| fetchRepos(); | ||
| }) | ||
| } | ||
|
|
||
| handlePrevPage = () => { | ||
| const handlePrevPage = () => { | ||
| this.setState({ | ||
| filters: { ...this.state.filters, page: this.state.filters.page - 1} | ||
| filters: { ...filters, page: filters.page - 1} | ||
| }, () => { | ||
| this.fetchRepos(); | ||
| fetchRepos(); | ||
| }) | ||
| } | ||
|
|
||
| render() { | ||
|
|
||
| return ( | ||
| <div className="repositories-container"> | ||
| <h2 className="repositories-header">Popular Repositories:</h2> | ||
|
|
||
| {this.state.repos === "loading" ? | ||
| {repos === "loading" ? | ||
|
|
||
| ( | ||
| <div className="repositories-list-container"> | ||
|
|
@@ -65,7 +61,7 @@ export default class RepositoriesList extends React.Component { | |
| : | ||
|
|
||
| ( | ||
| this.state.repos.length === 0 ? | ||
| repos.length === 0 ? | ||
| ( | ||
| <div className="repositories-list-container"> | ||
| <span>No repositories ...</span> | ||
|
|
@@ -75,33 +71,35 @@ export default class RepositoriesList extends React.Component { | |
| ( | ||
| <div className="repositories-list-container"> | ||
| { | ||
| this.state.repos.map((repo, index) => ( | ||
| repos.map((repo, index) => ( | ||
| <div className="single-repository-container" key={index}> | ||
| <SingleRepository repo={repo} /> | ||
| </div> | ||
| )) | ||
| } | ||
|
|
||
| <div className="repositoies-list-navigation-buttons-container"> | ||
| {/*<div className="repositoies-list-navigation-buttons-container"> | ||
| <button | ||
| onClick={this.handlePrevPage} | ||
| onClick={handlePrevPage} | ||
| className="repositoies-list-navigation-button" | ||
| disabled={this.state.filters.page === 1} | ||
| disabled={filters.page === 1} | ||
| > | ||
| {"<"} | ||
| </button> | ||
| <button | ||
| onClick={this.handleNextPage} | ||
| onClick={handleNextPage} | ||
| className="repositoies-list-navigation-button" | ||
| > | ||
| {">"} | ||
| </button> | ||
| </div> | ||
| </div>*/} | ||
|
Contributor
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. This code as well |
||
| </div> | ||
| ) | ||
| ) | ||
| } | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| export default RepositoriesList; | ||
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.
This outdated code is better removed to not affect code readability