Skip to content

Commit

Permalink
📁 Fix renaming and thumbnail (#2776)
Browse files Browse the repository at this point in the history
* Fix renaming and thumbnail

* Fixed realtime and context menu
  • Loading branch information
RomaricMourgues authored Mar 9, 2023
1 parent 0b9ca81 commit 0c3f576
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type DriveFileMetadata = {
name?: string;
mime?: string;
size?: number;
thumbnails?: DriveFileThumbnail;
thumbnails?: DriveFileThumbnail[];
};

type DriveFileThumbnail = {
Expand Down
2 changes: 2 additions & 0 deletions twake/backend/node/src/services/documents/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export class DocumentsService {
driveItemVersion.file_metadata.mime = fileToProcess.metadata.mime;
driveItemVersion.file_metadata.size = fileToProcess.upload_data.size;
driveItemVersion.file_metadata.name = fileToProcess.metadata.name;
driveItemVersion.file_metadata.thumbnails = fileToProcess.thumbnails;
if (context.user.application_id) {
driveItemVersion.application_id = context.user.application_id;
}
Expand Down Expand Up @@ -559,6 +560,7 @@ export class DocumentsService {
driveItemVersion.file_metadata.size = metadata.size;
driveItemVersion.file_metadata.name = metadata.name;
driveItemVersion.file_metadata.mime = metadata.mime;
driveItemVersion.file_metadata.thumbnails = metadata.thumbnails;
driveItemVersion.drive_item_id = item.id;
if (context.user.application_id) {
driveItemVersion.application_id = context.user.application_id;
Expand Down
4 changes: 3 additions & 1 deletion twake/backend/node/src/services/documents/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,11 +678,13 @@ export const getFileMetadata = async (
}

return {
source: "internal",
external_id: fileId,
mime: file.metadata.mime,
name: file.metadata.name,
size: file.upload_data.size,
};
thumbnails: file.thumbnails,
} as DriveFileMetadata;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ export const useDriveRealtime = (id: string) => {
refresh(id);
});
};

export const DriveRealtimeObject = ({ id }: { id: string }) => {
useDriveRealtime(id);
return <></>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const useRealtimeRoom = <T>(

useEffect(() => {
if (room !== roomConf) {
setRoom(roomConf);
setRoom({ ...roomConf });
if (room && subscribed.current && websocket) {
websocket.leave(room.room, tag);
subscribed.current = false;
Expand Down
4 changes: 2 additions & 2 deletions twake/frontend/src/app/views/applications/drive/browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getFilesTree } from 'app/components/uploads/file-tree-utils';
import UploadZone from 'app/components/uploads/upload-zone';
import { setTwakeTabToken } from 'app/features/drive/api-client/api-client';
import { useDriveItem } from 'app/features/drive/hooks/use-drive-item';
import { useDriveRealtime } from 'app/features/drive/hooks/use-drive-realtime';
import { DriveRealtimeObject } from 'app/features/drive/hooks/use-drive-realtime';
import { useDriveUpload } from 'app/features/drive/hooks/use-drive-upload';
import { DriveItemSelectedList } from 'app/features/drive/state/store';
import { formatBytes } from 'app/features/drive/utils';
Expand Down Expand Up @@ -61,7 +61,6 @@ export default memo(
} = useDriveItem(parentId);
const { item: trash } = useDriveItem('trash');
const { uploadTree, uploadFromUrl } = useDriveUpload();
useDriveRealtime(parentId);

const loading = loadingParent || loadingParentChange;

Expand Down Expand Up @@ -135,6 +134,7 @@ export default memo(
});
}}
>
<DriveRealtimeObject id={parentId} key={parentId} />
<CreateModal
selectFromDevice={() => uploadZoneRef.current?.open()}
addFromUrl={(url, name) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s
{ type: 'separator' },
{
type: 'menu',
text: 'Modify properties',
text: 'Rename',
hide: access === 'read',
onClick: () => setPropertiesModalState({ open: true, id: item.id }),
},
Expand Down Expand Up @@ -132,7 +132,7 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s
}
}

if (selectedCount && !item) {
if (selectedCount && (selectedCount >= 2 || !item)) {
// Add selected items related menus
const newMenuActions: any[] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const PropertiesModalContent = ({ id, onClose }: { id: string; onClose: () => vo
}, [item?.name]);

return (
<ModalContent title={'Properties of ' + item?.name}>
<ModalContent title={'Rename ' + item?.name}>
<InputLabel
className="mt-4"
label={'Name'}
Expand All @@ -67,7 +67,14 @@ const PropertiesModalContent = ({ id, onClose }: { id: string; onClose: () => vo
loading={loading}
onClick={async () => {
setLoading(true);
if (item) await update({ name }, id, item.parent_id);
if (item) {
let finalName = name;
if (!item?.is_directory) {
const ext = item?.name.split('.').pop();
finalName = name.split('.')[0] + (ext !== item?.name ? '.' + ext : '');
}
await update({ name: finalName }, id, item.parent_id);
}
onClose();
setLoading(false);
}}
Expand Down

0 comments on commit 0c3f576

Please sign in to comment.