bigbuffet-rw/app/soapbox/queries/carousels.ts

45 lines
919 B
TypeScript
Raw Normal View History

import { useMutation, useQuery } from '@tanstack/react-query';
2022-08-02 06:20:07 -07:00
import { useApi } from 'soapbox/hooks';
2022-08-02 06:20:07 -07:00
export type Avatar = {
2022-08-02 06:20:07 -07:00
account_id: string
account_avatar: string
acct: string
seen: boolean
2022-08-02 06:20:07 -07:00
}
const CarouselKeys = {
avatars: ['carouselAvatars'] as const,
};
function useCarouselAvatars() {
const api = useApi();
const getCarouselAvatars = async() => {
const { data } = await api.get('/api/v1/truth/carousels/avatars');
return data;
};
const result = useQuery<Avatar[]>(CarouselKeys.avatars, getCarouselAvatars, {
2022-08-02 06:20:07 -07:00
placeholderData: [],
keepPreviousData: true,
2022-08-02 06:20:07 -07:00
});
2022-08-08 12:53:21 -07:00
const avatars = result.data;
2022-08-02 06:20:07 -07:00
return {
2022-08-08 12:53:21 -07:00
...result,
data: avatars || [],
2022-08-02 06:20:07 -07:00
};
}
function useMarkAsSeen() {
const api = useApi();
return useMutation((account_id: string) => api.post('/api/v1/truth/carousels/avatars/seen', {
account_id,
}));
}
export { useCarouselAvatars, useMarkAsSeen };