zhengyiming
2025-02-10 0f686ea1fe4700a909a6159efcf1fcb0e1f88a17
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
import * as userServices from '@12333/services/api/User';
import { Message } from '@12333/utils';
import { useAccessLogin } from './access';
 
type UseFollowUserOptions = {
  onFollowSuccess?: () => void;
  onUnFollowSuccess?: () => void;
};
 
export function useFollowUser(options: UseFollowUserOptions = {}) {
  const { onFollowSuccess, onUnFollowSuccess } = options;
 
  const followUser = useAccessLogin(async (params: API.FollowUserInput) => {
    try {
      await userServices.followUser(params);
      onFollowSuccess?.();
    } catch (error) {}
  });
 
  const unFollowUser = useAccessLogin(async (params: API.UnFollowUserInput) => {
    try {
      await Message.confirm({ message: '确认取消关注吗?' });
      await userServices.unFollowUser(params);
      onUnFollowSuccess?.();
    } catch (error) {}
  });
 
  return {
    followUser,
    unFollowUser,
  };
}