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,
|
};
|
}
|