aboutsummaryrefslogtreecommitdiff
path: root/src/store/actions/socials.ts
blob: 1824ca53bf80edf54b23cf8a8c9cd096e41b20a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {RootState} from '../rootReducer';
import {loadSocialPosts} from '../../services';
import {Action, ThunkAction} from '@reduxjs/toolkit';
import {userSocialsFetched, individualSocialfetched} from '../reducers';
import {loadAllSocialsForUser} from '../../utils';

export const loadIndividualSocial =
  (
    userId: string,
    socialType: string,
  ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
  async (dispatch) => {
    try {
      const social = await loadSocialPosts(userId, socialType);
      dispatch({
        type: individualSocialfetched.type,
        payload: {socialType, social},
      });
    } catch (error) {
      console.log(error);
    }
  };

export const loadAllSocials =
  (
    userId: string,
  ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
  async (dispatch) => {
    try {
      const socials = await loadAllSocialsForUser(userId);
      dispatch({
        type: userSocialsFetched.type,
        payload: socials,
      });
    } catch (error) {
      console.log(error);
    }
  };