-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cfcf4a
commit 222e82a
Showing
27 changed files
with
282 additions
and
391 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,11 @@ | ||
import React from 'react'; | ||
|
||
function Button({ label, onClick }) { | ||
return ( | ||
<button className="button" onClick={onClick}> | ||
{label} | ||
</button> | ||
); | ||
} | ||
|
||
export default Button; |
This file contains 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,70 @@ | ||
import React from 'react'; | ||
|
||
import { getRandomMarker } from '../state/selectors'; | ||
import { useStateValue } from '../state/StateProvider'; | ||
import Fade from './Fade'; | ||
import Button from './Button'; | ||
|
||
function getSearchURL(city, country, keyword) { | ||
const formattedQuery = `${encodeURIComponent(city)}, ${encodeURIComponent( | ||
country, | ||
)} ${encodeURIComponent(keyword.join('|'))}`.replace(/(%20| )/g, '+'); | ||
return `https://www.google.com/search?q=${formattedQuery}`; | ||
} | ||
|
||
function Details() { | ||
const [state, dispatch] = useStateValue(); | ||
const { keyword, start, focusedMarker } = state; | ||
const randomMarker = getRandomMarker(state); | ||
|
||
let content; | ||
if (focusedMarker) { | ||
const { city, countryCode, countryName, value } = focusedMarker; | ||
const url = getSearchURL(city, countryName, keyword); | ||
const relatedTopics = state.relatedTopics[countryCode] || []; | ||
content = ( | ||
<> | ||
<div className="header"> | ||
<Button | ||
label="Back to globe" | ||
onClick={() => dispatch({ type: 'FOCUS' })} | ||
/> | ||
<Button | ||
label="Random City" | ||
onClick={() => dispatch({ type: 'FOCUS', payload: randomMarker })} | ||
/> | ||
</div> | ||
<div className="content"> | ||
<h2> | ||
{city}, {countryName} ({value}) | ||
</h2> | ||
<div className="details-content"> | ||
RELATED TOPICS | ||
{relatedTopics.map(({ topic, link }) => { | ||
return ( | ||
<a | ||
key={topic} | ||
href={`https://trends.google.com${link}`} | ||
rel="noopener noreferrer" | ||
target="_blank"> | ||
{topic} | ||
</a> | ||
); | ||
})} | ||
</div> | ||
<a href={url} rel="noopener noreferrer" target="_blank"> | ||
View search results | ||
</a> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<Fade className="details" shown={start}> | ||
{content} | ||
</Fade> | ||
); | ||
} | ||
|
||
export default Details; |
This file was deleted.
Oops, something went wrong.
This file contains 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,30 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
export default function Fade({ children, className, shown }) { | ||
const [shouldRender, setShouldRender] = useState(shown); | ||
|
||
useEffect(() => { | ||
if (shown) { | ||
setShouldRender(true); | ||
} | ||
}, [shown]); | ||
|
||
const onAnimationEnd = () => { | ||
if (!shown) { | ||
setShouldRender(false); | ||
} | ||
}; | ||
|
||
return ( | ||
shouldRender && ( | ||
<div | ||
className={className} | ||
style={{ | ||
animation: `${shown ? 'fade-in' : 'fade-out'} 1s`, | ||
}} | ||
onAnimationEnd={onAnimationEnd}> | ||
{children} | ||
</div> | ||
) | ||
); | ||
} |
This file contains 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.