wasp/examples/realworld/ext/MainPage.js

65 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-11-28 00:52:38 +03:00
import React, { useState } from 'react'
import { Link } from 'react-router-dom'
2020-11-26 18:35:38 +03:00
import _ from 'lodash'
import useAuth from '@wasp/auth/useAuth.js'
2020-11-30 20:11:40 +03:00
import { useQuery } from '@wasp/queries'
2020-11-26 18:35:38 +03:00
import getTags from '@wasp/queries/getTags'
import getFollowedArticles from '@wasp/queries/getFollowedArticles'
import getAllArticles from '@wasp/queries/getAllArticles'
2020-11-19 17:32:37 +03:00
import Navbar from './Navbar'
2020-11-30 20:11:40 +03:00
import ArticleListPaginated from './article/components/ArticleListPaginated'
2020-11-19 17:32:37 +03:00
const MainPage = () => {
const { data: me } = useAuth()
return (
<div>
2020-11-19 17:32:37 +03:00
<Navbar />
2020-11-26 18:35:38 +03:00
<Tags />
{ me && (
<div>
<h1> Your Feed </h1>
<ArticleListPaginated
query={getFollowedArticles}
makeQueryArgs={({ skip, take }) => ({ skip, take })}
pageSize={2}
/>
</div>
)}
<div>
<h1> Global Feed </h1>
<ArticleListPaginated
query={getAllArticles}
makeQueryArgs={({ skip, take }) => ({ skip, take })}
pageSize={2}
/>
</div>
</div>
)
}
2020-11-26 18:35:38 +03:00
const Tags = () => {
const { data: tags } = useQuery(getTags)
if (!tags) return null
const popularTags = _.take(_.sortBy(tags, [t => -1 * t.numArticles]), 10)
return (
<div>
Popular tags: { popularTags.map(tag => (
<div>
{ tag.name } ({ tag.numArticles })
</div>
))}
</div>
)
}
export default MainPage