Bookmark folders

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-03-20 23:58:53 +01:00
parent 460e22ce2b
commit eceafedec4
31 changed files with 748 additions and 60 deletions

View File

@ -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';

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

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

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

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

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