🍄 Separate trash for the personal and shared drive (#189)
This commit is contained in:
@@ -83,6 +83,13 @@ export class DriveApiClient {
|
||||
);
|
||||
}
|
||||
|
||||
static async restore(companyId: string, id: string | 'trash' | '') {
|
||||
return await Api.post<any, any>(
|
||||
`/internal/services/documents/v1/companies/${companyId}/item/${id}/restore${appendTdriveToken()}`,
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
static async update(companyId: string, id: string, update: Partial<DriveItem>) {
|
||||
return await Api.post<Partial<DriveItem>, DriveItem>(
|
||||
`/internal/services/documents/v1/companies/${companyId}/item/${id}${appendTdriveToken()}`,
|
||||
|
||||
@@ -96,6 +96,18 @@ export const useDriveActions = () => {
|
||||
[refresh],
|
||||
);
|
||||
|
||||
const restore = useCallback(
|
||||
async (id: string, parentId: string) => {
|
||||
try {
|
||||
await DriveApiClient.restore(companyId, id);
|
||||
await refresh(parentId || '');
|
||||
} catch (e) {
|
||||
ToasterService.error(Languages.t('hooks.use-drive-actions.unable_restore_file'));
|
||||
}
|
||||
},
|
||||
[refresh],
|
||||
);
|
||||
|
||||
const update = useCallback(
|
||||
async (update: Partial<DriveItem>, id: string, parentId: string) => {
|
||||
try {
|
||||
@@ -127,5 +139,5 @@ export const useDriveActions = () => {
|
||||
[refresh],
|
||||
);
|
||||
|
||||
return { create, refresh, download, downloadZip, remove, update, updateLevel };
|
||||
return { create, refresh, download, downloadZip, remove, restore, update, updateLevel };
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ export const useDriveItem = (id: string) => {
|
||||
const item = useRecoilValue(DriveItemAtom(id));
|
||||
const children = useRecoilValue(DriveItemChildrenAtom(id));
|
||||
const [loading, setLoading] = useRecoilState(LoadingStateInitTrue('useDriveItem-' + id));
|
||||
const { refresh: refreshItem, create, update: _update, updateLevel: _updateLevel, remove: _remove } = useDriveActions();
|
||||
const { refresh: refreshItem, create, update: _update, updateLevel: _updateLevel, remove: _remove, restore: _restore } = useDriveActions();
|
||||
const { uploadVersion: _uploadVersion } = useDriveUpload();
|
||||
|
||||
const refresh = useCallback(
|
||||
@@ -44,6 +44,16 @@ export const useDriveItem = (id: string) => {
|
||||
setLoading(false);
|
||||
}, [id, setLoading, refresh, item?.item?.parent_id]);
|
||||
|
||||
const restore = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
await _restore(id, item?.item?.parent_id || '');
|
||||
} catch (e) {
|
||||
ToasterService.error('Unable to restore this item.');
|
||||
}
|
||||
setLoading(false);
|
||||
}, [id, setLoading, refresh, item?.item?.parent_id]);
|
||||
|
||||
const update = useCallback(
|
||||
async (update: Partial<DriveItem>) => {
|
||||
setLoading(true);
|
||||
@@ -83,7 +93,7 @@ export const useDriveItem = (id: string) => {
|
||||
[companyId, id, setLoading, refresh, item?.item?.parent_id],
|
||||
);
|
||||
|
||||
const inTrash = id === 'trash' || item?.path?.some(i => i.parent_id === 'trash');
|
||||
const inTrash = id.includes('trash') || item?.path?.some(i => i?.parent_id?.includes('trash')) || item?.item?.is_in_trash;
|
||||
const sharedWithMe = id =="shared_with_me";
|
||||
|
||||
return {
|
||||
|
||||
@@ -31,7 +31,6 @@ export const useDrivePreviewModal = () => {
|
||||
|
||||
const close = () => {
|
||||
setStatus({ item: null, loading: true });
|
||||
history.push(RouterServices.generateRouteFromState({companyId: company, itemId: ""}));
|
||||
}
|
||||
|
||||
return { open, close, isOpen: !!status.item };
|
||||
|
||||
@@ -21,7 +21,7 @@ export type DriveItem = {
|
||||
workspace_id: string;
|
||||
|
||||
parent_id: string;
|
||||
in_trash: boolean;
|
||||
is_in_trash: boolean;
|
||||
is_directory: boolean;
|
||||
name: string;
|
||||
extension: string;
|
||||
@@ -35,6 +35,7 @@ export type DriveItem = {
|
||||
access_info: DriveItemAccessInfo;
|
||||
|
||||
size: number;
|
||||
scope: string;
|
||||
};
|
||||
|
||||
export type DriveFileAccessLevel = 'none' | 'read' | 'write' | 'manage';
|
||||
|
||||
@@ -27,6 +27,7 @@ export type ClientStateType = {
|
||||
companyId?: string;
|
||||
viewId?: string;
|
||||
itemId?: string;
|
||||
dirId?: string;
|
||||
workspaceId?: string;
|
||||
channelId?: string;
|
||||
messageId?: string;
|
||||
@@ -52,6 +53,7 @@ class RouterServices extends Observable {
|
||||
'/client/:companyId/v/:viewId',
|
||||
'/client/:companyId/preview/:itemId',
|
||||
'/client/:companyId/v/:viewId/preview/:itemId',
|
||||
'/client/:companyId/v/:viewId/d/:dirId',
|
||||
'/client/:companyId/w/:workspaceId',
|
||||
'/client/:companyId/w/:workspaceId/c/:channelId',
|
||||
'/client/:companyId/w/:workspaceId/c/:channelId/t/:threadId',
|
||||
@@ -185,6 +187,7 @@ class RouterServices extends Observable {
|
||||
companyId: match?.params?.companyId || '',
|
||||
viewId: match?.params?.viewId || '',
|
||||
itemId: match?.params?.itemId || '',
|
||||
dirId: match?.params?.dirId || '',
|
||||
workspaceId: match?.params?.workspaceId || '',
|
||||
channelId: match?.params?.channelId || '',
|
||||
messageId: match?.params?.messageId || '',
|
||||
@@ -291,6 +294,7 @@ class RouterServices extends Observable {
|
||||
(state.companyId ? `/${state.companyId}` : '') +
|
||||
(state.viewId ? `/v/${state.viewId}` : '') +
|
||||
(state.itemId ? `/preview/${state.itemId}` : '') +
|
||||
(state.dirId ? `/d/${state.dirId}` : '') +
|
||||
(state.sharedWithMe ? `/shared-with-me` : '') +
|
||||
(state.workspaceId ? `/w/${state.workspaceId}` : '') +
|
||||
(state.channelId ? `/c/${state.channelId}` : '') +
|
||||
|
||||
@@ -16,6 +16,11 @@ export const RoutePreviewSelector = selector<string>({
|
||||
get: ({ get }) => get(RouterState)?.itemId || '',
|
||||
});
|
||||
|
||||
export const RouteDirectorySelector = selector<string>({
|
||||
key: 'RouterDirectorySelector',
|
||||
get: ({ get }) => get(RouterState)?.dirId || '',
|
||||
});
|
||||
|
||||
export const RouterWorkspaceSelector = selector<string>({
|
||||
key: 'RouterWorkspaceSelector',
|
||||
get: ({ get }) => get(RouterState)?.workspaceId || '',
|
||||
|
||||
Reference in New Issue
Block a user