Dwayne Harris
5 years ago
15 changed files with 205 additions and 126 deletions
-
4src/actions/posts.ts
-
36src/actions/users.ts
-
2src/components/app.tsx
-
3src/components/composer.tsx
-
6src/components/pages/create-app.tsx
-
33src/components/pages/edit-app.tsx
-
8src/components/pages/home.tsx
-
53src/components/pages/self.tsx
-
2src/components/pages/view-app.tsx
-
2src/components/pages/view-group.tsx
-
39src/components/timeline.tsx
-
2src/selectors/authentication.ts
-
9src/selectors/posts.ts
-
2src/types/entities.ts
-
10src/types/store.ts
@ -0,0 +1,39 @@ |
|||
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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue