Skip to content

Commit

Permalink
Merge pull request #4 from Emerrrail/dev
Browse files Browse the repository at this point in the history
Fixed bugs
  • Loading branch information
Emerrrail committed Apr 1, 2022
2 parents 61f9117 + d9a057f commit e11c7e0
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 deletions.
Binary file added public/logo192.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/Layouts/UserLayout/UserLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ function UserLayout ({ children }) {

const dispatch = useDispatch()

const onTogglerClick = () => {
const onSwitchButtonClick = () => {
dispatch(toggleOwnerInfo())
}

return (
<div>
<div
className={`userLayout__toggler_container${matches ? '' : ' hidden'}`}
onClick={onTogglerClick}
onClick={onSwitchButtonClick}
>
<Toggler />
</div>
<OwnerInfo />
<OwnerInfo onSwitchButtonClick={onSwitchButtonClick} />
{children}
</div>
)
Expand Down
5 changes: 3 additions & 2 deletions src/Pages/UserPage/UserPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import UserRepos from '../../components/UserRepos/UserRepos'
import UserFollowers from '../../components/UserFollowers/UserFollowers'
import Error from '../../components/Error/Error'
import { getReposRequest } from '../../Services/store/actions/index'
import { scrollToTop } from '../../helper-function/scrollToTop'

function UserPage ({ errorRepos, errorFollowers }) {
const { username, page } = useParams()
Expand All @@ -14,9 +15,9 @@ function UserPage ({ errorRepos, errorFollowers }) {

useEffect(() => {
dispatch(getReposRequest(username))
scrollToTop()
}, [dispatch, username])
// 在搜尋失敗後,成為error的狀態,因為UserRepos沒有生成,也不會再打API,所以就停在error畫面了。
// 可以在UserPage dispatch action

return (
<div>
{!errorRepos && !errorFollowers &&
Expand Down
4 changes: 2 additions & 2 deletions src/components/Button/Button.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import './Button.css'
import React from 'react'
import { onClickUrl } from '../../helper-function/onClickUrl'
import { onUrlClick } from '../../helper-function/onUrlClick'

function Button ({ text, url }) {
return (
<button
className='button'
onClick={onClickUrl(url)}
onClick={onUrlClick(url)}
>{text}
</button>
)
Expand Down
18 changes: 11 additions & 7 deletions src/components/OwnerInfo/OwnerInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import Mail from '../icon/Mail'
import Button from '../Button/Button'
import LinkIcon from '../icon/LinkIcon'
import Repositories from '../icon/Repositories'
import { onClickUrl } from '../../helper-function/onClickUrl'
import { onUrlClick } from '../../helper-function/onUrlClick'
import { getOwnerDataRequest } from '../../Services/store/actions/index'

function OwnerInfo ({ ownerData, loading, open }) {
function OwnerInfo ({ ownerData, loading, open, onSwitchButtonClick }) {
const [matches, setMatches] = useState(window.matchMedia('(max-width: 576px)').matches)

window.matchMedia('(max-width: 576px)').addEventListener('change', (event) => setMatches(event.matches))

console.log('open, matches', open, matches)

const dispatch = useDispatch()

const { username } = useParams()
Expand Down Expand Up @@ -65,7 +63,7 @@ function OwnerInfo ({ ownerData, loading, open }) {
{ownerData.email}
</div>}
{ownerData.blog &&
<div className='ownerInfo__link' onClick={onClickUrl(ownerData.blog)}>
<div className='ownerInfo__link' onClick={onUrlClick(ownerData.blog)}>
<LinkIcon />
{ownerData.blog}
</div>}
Expand All @@ -76,13 +74,19 @@ function OwnerInfo ({ ownerData, loading, open }) {
</div>
<div className='ownerInfo__menu'>
<Link to={`/users/${username}/repos`}>
<div className={`ownerInfo__repositories${reposSelected ? ' selected' : ''}`}>
<div
className={`ownerInfo__repositories${reposSelected ? ' selected' : ''}`}
onClick={onSwitchButtonClick}
>
<Repositories />
Repositories
</div>
</Link>
<Link to={`/users/${username}/followers`}>
<div className={`ownerInfo__followers${followersSelected ? ' selected' : ''}`}>
<div
className={`ownerInfo__followers${followersSelected ? ' selected' : ''}`}
onClick={onSwitchButtonClick}
>
<Followers />
Followers
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/components/PlaceholderFollowers/PlaceholderFollowers.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@
.placeholderFollowers__title {
width: 70%;
}

@media (max-width: 880px) {
.placeholderFollowers {
grid-template-columns: 1fr;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ const openInNewTab = (url) => {
if (newWindow) newWindow.opener = null
}

export const onClickUrl = (url) => {
export const onUrlClick = (url) => {
return () => openInNewTab(url)
}
6 changes: 6 additions & 0 deletions src/helper-function/scrollToTop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: 'auto'
})
}

1 comment on commit e11c7e0

@vercel
Copy link

@vercel vercel bot commented on e11c7e0 Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.