@ -44,6 +44,13 @@ export { useUnmuteGroup } from './groups/useUnmuteGroup';
|
||||
export { useUpdateGroup } from './groups/useUpdateGroup';
|
||||
export { useUpdateGroupTag } from './groups/useUpdateGroupTag';
|
||||
|
||||
// Statuses
|
||||
export { useBookmarkFolders } from './statuses/useBookmarkFolders';
|
||||
export { useBookmarkFolder } from './statuses/useBookmarkFolder';
|
||||
export { useCreateBookmarkFolder } from './statuses/useCreateBookmarkFolder';
|
||||
export { useDeleteBookmarkFolder } from './statuses/useDeleteBookmarkFolder';
|
||||
export { useUpdateBookmarkFolder } from './statuses/useUpdateBookmarkFolder';
|
||||
|
||||
// Streaming
|
||||
export { useUserStream } from './streaming/useUserStream';
|
||||
export { useCommunityStream } from './streaming/useCommunityStream';
|
||||
|
||||
31
src/api/hooks/statuses/useBookmarkFolder.ts
Normal file
31
src/api/hooks/statuses/useBookmarkFolder.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { selectEntity } from 'soapbox/entity-store/selectors';
|
||||
import { useAppSelector } from 'soapbox/hooks';
|
||||
import { type BookmarkFolder } from 'soapbox/schemas/bookmark-folder';
|
||||
|
||||
import { useBookmarkFolders } from './useBookmarkFolders';
|
||||
|
||||
function useBookmarkFolder(folderId?: string) {
|
||||
const {
|
||||
isError,
|
||||
isFetched,
|
||||
isFetching,
|
||||
isLoading,
|
||||
invalidate,
|
||||
} = useBookmarkFolders();
|
||||
|
||||
const bookmarkFolder = useAppSelector(state => folderId
|
||||
? selectEntity<BookmarkFolder>(state, Entities.BOOKMARK_FOLDERS, folderId)
|
||||
: undefined);
|
||||
|
||||
return {
|
||||
bookmarkFolder,
|
||||
isError,
|
||||
isFetched,
|
||||
isFetching,
|
||||
isLoading,
|
||||
invalidate,
|
||||
};
|
||||
}
|
||||
|
||||
export { useBookmarkFolder };
|
||||
25
src/api/hooks/statuses/useBookmarkFolders.ts
Normal file
25
src/api/hooks/statuses/useBookmarkFolders.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntities } from 'soapbox/entity-store/hooks';
|
||||
import { useApi } from 'soapbox/hooks';
|
||||
import { useFeatures } from 'soapbox/hooks/useFeatures';
|
||||
import { bookmarkFolderSchema, type BookmarkFolder } from 'soapbox/schemas/bookmark-folder';
|
||||
|
||||
function useBookmarkFolders() {
|
||||
const api = useApi();
|
||||
const features = useFeatures();
|
||||
|
||||
const { entities, ...result } = useEntities<BookmarkFolder>(
|
||||
[Entities.BOOKMARK_FOLDERS],
|
||||
() => api.get('/api/v1/pleroma/bookmark_folders'),
|
||||
{ enabled: features.bookmarkFolders, schema: bookmarkFolderSchema },
|
||||
);
|
||||
|
||||
const bookmarkFolders = entities;
|
||||
|
||||
return {
|
||||
...result,
|
||||
bookmarkFolders,
|
||||
};
|
||||
}
|
||||
|
||||
export { useBookmarkFolders };
|
||||
31
src/api/hooks/statuses/useCreateBookmarkFolder.ts
Normal file
31
src/api/hooks/statuses/useCreateBookmarkFolder.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useCreateEntity } from 'soapbox/entity-store/hooks';
|
||||
import { useApi } from 'soapbox/hooks';
|
||||
import { bookmarkFolderSchema } from 'soapbox/schemas/bookmark-folder';
|
||||
|
||||
interface CreateBookmarkFolderParams {
|
||||
name: string;
|
||||
emoji?: string;
|
||||
}
|
||||
|
||||
function useCreateBookmarkFolder() {
|
||||
const api = useApi();
|
||||
|
||||
const { createEntity, ...rest } = useCreateEntity(
|
||||
[Entities.BOOKMARK_FOLDERS],
|
||||
(params: CreateBookmarkFolderParams) =>
|
||||
api.post('/api/v1/pleroma/bookmark_folders', params, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
}),
|
||||
{ schema: bookmarkFolderSchema },
|
||||
);
|
||||
|
||||
return {
|
||||
createBookmarkFolder: createEntity,
|
||||
...rest,
|
||||
};
|
||||
}
|
||||
|
||||
export { useCreateBookmarkFolder };
|
||||
16
src/api/hooks/statuses/useDeleteBookmarkFolder.ts
Normal file
16
src/api/hooks/statuses/useDeleteBookmarkFolder.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntityActions } from 'soapbox/entity-store/hooks';
|
||||
|
||||
function useDeleteBookmarkFolder() {
|
||||
const { deleteEntity, isSubmitting } = useEntityActions(
|
||||
[Entities.BOOKMARK_FOLDERS],
|
||||
{ delete: '/api/v1/pleroma/bookmark_folders/:id' },
|
||||
);
|
||||
|
||||
return {
|
||||
deleteBookmarkFolder: deleteEntity,
|
||||
isSubmitting,
|
||||
};
|
||||
}
|
||||
|
||||
export { useDeleteBookmarkFolder };
|
||||
31
src/api/hooks/statuses/useUpdateBookmarkFolder.ts
Normal file
31
src/api/hooks/statuses/useUpdateBookmarkFolder.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useCreateEntity } from 'soapbox/entity-store/hooks';
|
||||
import { useApi } from 'soapbox/hooks';
|
||||
import { bookmarkFolderSchema } from 'soapbox/schemas/bookmark-folder';
|
||||
|
||||
interface UpdateBookmarkFolderParams {
|
||||
name: string;
|
||||
emoji?: string;
|
||||
}
|
||||
|
||||
function useUpdateBookmarkFolder(folderId: string) {
|
||||
const api = useApi();
|
||||
|
||||
const { createEntity, ...rest } = useCreateEntity(
|
||||
[Entities.BOOKMARK_FOLDERS],
|
||||
(params: UpdateBookmarkFolderParams) =>
|
||||
api.patch(`/api/v1/pleroma/bookmark_folders/${folderId}`, params, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
}),
|
||||
{ schema: bookmarkFolderSchema },
|
||||
);
|
||||
|
||||
return {
|
||||
updateBookmarkFolder: createEntity,
|
||||
...rest,
|
||||
};
|
||||
}
|
||||
|
||||
export { useUpdateBookmarkFolder };
|
||||
Reference in New Issue
Block a user