[ABANDONED] React/Redux front end for the Flexor social network.
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.

35 lines
1019 B

5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
  1. import React, { FC, useEffect } from 'react'
  2. import { useSelector, useDispatch } from 'react-redux'
  3. import { useHistory } from 'react-router-dom'
  4. import { handleApiError } from '../api/errors'
  5. import { fetchTimeline } from '../actions/posts'
  6. import { getTimeline } from '../selectors/posts'
  7. import { getAuthenticated } from '../selectors/authentication'
  8. import { AppThunkDispatch } from '../types'
  9. import PostList from '../components/post-list'
  10. const Timeline: FC = () => {
  11. const authenticated = useSelector(getAuthenticated)
  12. const posts = useSelector(getTimeline)
  13. const dispatch = useDispatch<AppThunkDispatch>()
  14. const history = useHistory()
  15. useEffect(() => {
  16. const init = async () => {
  17. try {
  18. await dispatch(fetchTimeline())
  19. } catch (err) {
  20. handleApiError(err, dispatch, history)
  21. }
  22. }
  23. if (authenticated) init()
  24. }, [authenticated])
  25. return <PostList posts={posts} />
  26. }
  27. export default Timeline