@@ -10,6 +10,7 @@ import { toast } from 'react-toastify';
1010import ArticleCardSkeletton from '../components/ArticleView/ArticleCardSkeletton' ;
1111import getTrueArticles from '../helpers/getTrueArticles' ;
1212import countries from '../helpers/countriesIsoCodes' ;
13+ import ListArticlesResult from '../components/ArticleView/ArticleList' ;
1314
1415const getCountryNameByCode = ( continent , code ) => {
1516 const country = countries [ continent ] . find ( ( country ) => country . code === code ) ;
@@ -28,6 +29,8 @@ function App() {
2829 const [ countryFromUrl , setCountryFromUrl ] = useState ( '' ) ;
2930 const [ continentFromUrl , setContinentFromUrl ] = useState ( '' ) ;
3031 const [ filteredArticles , setFilteredArticles ] = useState ( articles ) ;
32+
33+ const [ view , setView ] = useState ( 'card' ) ;
3134 const handlePageChange = ( currentPage , paginatedItems ) => {
3235 setPaginatedItems ( paginatedItems ) ;
3336 } ;
@@ -168,17 +171,19 @@ function App() {
168171 < div className = 'bg-slate-100 rounded-xl max-md:flex max-md:justify-center' >
169172 < ArticleForm onSubmit = { handleSubmit } loading = { loading } continentUrl = { continentFromUrl } countryUrl = { countryFromUrl } />
170173 </ div >
174+
171175 { loading && (
172176 < div >
173- < ul className = 'flex flex-wrap items-center justify-center pt-[2rem] max-md:flex-col' >
177+ < ul className = 'flex flex-wrap items-center justify-center pt-4 gap-2 max-md:flex-col' >
174178 { [ 1 , 2 , 3 ] . map ( ( e , i ) => (
175- < div className = 'w-1/3 p-8 max-md:w-[90vw]' key = { i } >
179+ < div className = ' max-md:w-[90vw]' key = { i } >
176180 < ArticleCardSkeletton element = { e } />
177181 </ div >
178182 ) ) }
179183 </ ul >
180184 </ div >
181185 ) }
186+
182187 { articles . length > 0 && (
183188 < div className = 'flex justify-between max-md:flex-col-reverse pt-4' >
184189 < div className = 'relative flex text-left' >
@@ -233,24 +238,80 @@ function App() {
233238 < SearchBar articles = { articles } setFilteredArticles = { setFilteredArticles } />
234239 </ div >
235240 ) }
241+
242+ { articles . length > 0 && (
243+ < div className = 'py-4 flex items-center gap-3 rounded-lg border' >
244+ < button
245+ onClick = { ( ) => {
246+ setView ( 'card' ) ;
247+ } }
248+ className = { view == 'card' ? 'bg-white' : 'text-white' }
249+ >
250+ < svg
251+ aria-hidden = 'true'
252+ focusable = 'false'
253+ data-prefix = 'fas'
254+ data-icon = 'grid-2'
255+ role = 'img'
256+ xmlns = 'http://www.w3.org/2000/svg'
257+ viewBox = '0 0 512 512'
258+ className = 'svg-inline--fa fa-grid-2 fa-lg'
259+ >
260+ < path
261+ fill = 'currentColor'
262+ d = 'M224 80c0-26.5-21.5-48-48-48L80 32C53.5 32 32 53.5 32 80l0 96c0 26.5 21.5 48 48 48l96 0c26.5 0 48-21.5 48-48l0-96zm0 256c0-26.5-21.5-48-48-48l-96 0c-26.5 0-48 21.5-48 48l0 96c0 26.5 21.5 48 48 48l96 0c26.5 0 48-21.5 48-48l0-96zM288 80l0 96c0 26.5 21.5 48 48 48l96 0c26.5 0 48-21.5 48-48l0-96c0-26.5-21.5-48-48-48l-96 0c-26.5 0-48 21.5-48 48zM480 336c0-26.5-21.5-48-48-48l-96 0c-26.5 0-48 21.5-48 48l0 96c0 26.5 21.5 48 48 48l96 0c26.5 0 48-21.5 48-48l0-96z'
263+ className = ''
264+ > </ path >
265+ </ svg >
266+ </ button >
267+ < button
268+ onClick = { ( ) => {
269+ setView ( 'list' ) ;
270+ } }
271+ className = { view == 'list' ? 'bg-white' : 'text-white' }
272+ >
273+ < svg
274+ aria-hidden = 'true'
275+ focusable = 'false'
276+ data-prefix = 'fas'
277+ data-icon = 'list-ul'
278+ role = 'img'
279+ xmlns = 'http://www.w3.org/2000/svg'
280+ viewBox = '0 0 512 512'
281+ className = 'svg-inline--fa fa-list-ul fa-lg'
282+ >
283+ < path
284+ fill = 'currentColor'
285+ d = 'M64 144a48 48 0 1 0 0-96 48 48 0 1 0 0 96zM192 64c-17.7 0-32 14.3-32 32s14.3 32 32 32l288 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L192 64zm0 160c-17.7 0-32 14.3-32 32s14.3 32 32 32l288 0c17.7 0 32-14.3 32-32s-14.3-32-32-32l-288 0zm0 160c-17.7 0-32 14.3-32 32s14.3 32 32 32l288 0c17.7 0 32-14.3 32-32s-14.3-32-32-32l-288 0zM64 464a48 48 0 1 0 0-96 48 48 0 1 0 0 96zm48-208a48 48 0 1 0 -96 0 48 48 0 1 0 96 0z'
286+ className = ''
287+ > </ path >
288+ </ svg >
289+ </ button >
290+ </ div >
291+ ) }
236292 < div className = 'articles' >
237293 { filteredArticles && filteredArticles ?. length > 0 ? (
238294 < div >
239- < ul className = 'flex flex-wrap items-center justify-center pt-[2rem] max-md:flex-col' >
240- { paginatedItems ?. length > 0 &&
241- paginatedItems . map ( ( { article, project, rank, views_ceil, country } ) => (
242- < div className = 'w-1/3 p-8 max-md:w-[90vw]' key = { article } >
243- < ArticleCard
244- key = { article }
245- article = { article }
246- project = { project }
247- rank = { rank }
248- views_ceil = { views_ceil }
249- country = { country }
250- />
251- </ div >
252- ) ) }
253- </ ul >
295+ { view == 'card' && (
296+ < ul className = 'flex flex-wrap items-center justify-between gap-4 p-3 max-md:flex-col' >
297+ { paginatedItems ?. length > 0 &&
298+ paginatedItems . map ( ( { article, project, rank, views_ceil, country } ) => {
299+ return (
300+ < ArticleCard
301+ key = { article }
302+ article = { article }
303+ project = { project }
304+ rank = { rank }
305+ views_ceil = { views_ceil }
306+ country = { country }
307+ />
308+ ) ;
309+ } ) }
310+ </ ul >
311+ ) }
312+
313+ { view == 'list' && paginatedItems ?. length > 0 && < ListArticlesResult articlesData = { paginatedItems } /> }
314+
254315 < div className = 'flex justify-center mb-10' >
255316 < Pagination
256317 onCurrentChange = { handleCurrentPage }
0 commit comments