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

30 lines
585 B
TypeScript
Raw Normal View History

2022-08-02 06:20:07 -07:00
import { useQuery } from '@tanstack/react-query';
import { useApi } from 'soapbox/hooks';
2022-08-02 06:20:07 -07:00
type Avatar = {
account_id: string
account_avatar: string
username: string
}
2022-08-08 12:53:21 -07:00
export default function useCarouselAvatars() {
const api = useApi();
const getCarouselAvatars = async() => {
const { data } = await api.get('/api/v1/truth/carousels/avatars');
return data;
};
2022-08-08 12:53:21 -07:00
const result = useQuery<Avatar[]>(['carouselAvatars'], getCarouselAvatars, {
2022-08-02 06:20:07 -07:00
placeholderData: [],
});
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
};
}