You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
import React, { FC, useEffect } from 'react'
|
|
import { useSelector, useDispatch } from 'react-redux'
|
|
import { useHistory } from 'react-router-dom'
|
|
|
|
import { handleApiError } from 'src/api/errors'
|
|
import { fetchTimeline } from 'src/actions/posts'
|
|
import { getTimeline } from 'src/selectors/posts'
|
|
import { getAuthenticated } from 'src/selectors/authentication'
|
|
|
|
import { AppState, Post, AppThunkDispatch } from 'src/types'
|
|
|
|
import PostList from 'src/components/post-list'
|
|
|
|
const Timeline: FC = () => {
|
|
const authenticated = useSelector<AppState, boolean>(getAuthenticated)
|
|
const posts = useSelector<AppState, Post[]>(getTimeline)
|
|
const dispatch = useDispatch<AppThunkDispatch>()
|
|
const history = useHistory()
|
|
|
|
useEffect(() => {
|
|
const init = async () => {
|
|
try {
|
|
await dispatch(fetchTimeline())
|
|
} catch (err) {
|
|
handleApiError(err, dispatch, history)
|
|
}
|
|
}
|
|
|
|
if (authenticated) init()
|
|
}, [authenticated])
|
|
|
|
return (
|
|
<div>
|
|
<PostList posts={posts} />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default Timeline
|