Skip to content

Commit

Permalink
Partial fixes on linagora#2763
Browse files Browse the repository at this point in the history
  • Loading branch information
RomaricMourgues committed Feb 28, 2023
1 parent 3de6bc0 commit ae37be8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useRealtimeRoom } from 'app/features/global/hooks/use-realtime';
import { Application } from 'app/features/applications/types/application';
import { LoadingState } from 'app/features/global/state/atoms/Loading';
import useRouterWorkspace from 'app/features/router/hooks/use-router-workspace';
import { useGlobalEffect } from 'app/features/global/hooks/use-global-effect';

const logger = Logger.getLogger('useApplications');
/**
Expand Down Expand Up @@ -42,9 +43,13 @@ export function useCompanyApplications(companyId = '') {
onChangeCompanyApplications(companyId, applications);
}, [applications]);

useEffect(() => {
refresh();
}, [workspaceId]);
useGlobalEffect(
'useCompanyApplications',
() => {
refresh();
},
[workspaceId],
);

const get = (applicationId: string) => {
return applications.find(a => a.id === applicationId);
Expand Down
85 changes: 44 additions & 41 deletions twake/frontend/src/app/features/drive/hooks/use-drive-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,51 +110,54 @@ export const useDriveUpload = () => {
}
};

const uploadFromUrl =
(url: string, name: string, context: { companyId: string; parentId: string }) => () => {
const request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'blob';
request.onload = function () {
try {
const file = new File([request.response], name);
FileUploadService.upload([file], {
context: {
companyId: context.companyId,
parentId: context.parentId,
},
callback: (file, context) => {
if (file) {
create(
{
company_id: context.companyId,
workspace_id: 'drive', //We don't set workspace ID for now
parent_id: context.parentId,
const uploadFromUrl = (
url: string,
name: string,
context: { companyId: string; parentId: string },
) => {
const request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'blob';
request.onload = function () {
try {
const file = new File([request.response], name);
FileUploadService.upload([file], {
context: {
companyId: context.companyId,
parentId: context.parentId,
},
callback: (file, context) => {
if (file) {
create(
{
company_id: context.companyId,
workspace_id: 'drive', //We don't set workspace ID for now
parent_id: context.parentId,
name: file.metadata?.name,
size: file.upload_data?.size,
},
{
provider: 'internal',
application_id: '',
file_metadata: {
name: file.metadata?.name,
size: file.upload_data?.size,
mime: file.metadata?.mime,
thumbnails: file?.thumbnails,
source: 'internal',
external_id: file.id,
},
{
provider: 'internal',
application_id: '',
file_metadata: {
name: file.metadata?.name,
size: file.upload_data?.size,
mime: file.metadata?.mime,
thumbnails: file?.thumbnails,
source: 'internal',
external_id: file.id,
},
},
);
}
},
});
} catch (e) {
ToasterService.error('Error while creating an empty file.');
}
};
request.send();
},
);
}
},
});
} catch (e) {
ToasterService.error('Error while creating an empty file.');
}
};
request.send();
};

return { uploadTree, uploadFromUrl, uploadVersion };
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default (props: {
const inputElement = useRef<HTMLInputElement>(null);

useEffect(() => {
props.onChange(users);
if (users.length) props.onChange(users);
}, [users]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import A from 'app/atoms/link';
import { Modal, ModalContent } from 'app/atoms/modal';
import { Base } from 'app/atoms/text';
import { useApplications } from 'app/features/applications/hooks/use-applications';
import { useCompanyApplications } from 'app/features/applications/hooks/use-company-applications';
import { Application } from 'app/features/applications/types/application';
import { ReactNode } from 'react';
import { atom, useRecoilState } from 'recoil';
Expand Down Expand Up @@ -34,7 +35,7 @@ export const CreateModal = ({
addFromUrl: (url: string, name: string) => void;
}) => {
const [state, setState] = useRecoilState(CreateModalAtom);
const { applications } = useApplications();
const { applications } = useCompanyApplications();

return (
<Modal
Expand Down Expand Up @@ -114,7 +115,7 @@ export const CreateModal = ({
avatar={app.app.identity?.icon}
/>
}
text={`${app.emptyFile.name} (${app.app.identity?.name})`}
text={`${app.emptyFile.name}`}
onClick={() => addFromUrl(app.emptyFile.url, app.emptyFile.name)}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { AccessLevel } from './common';
export const InternalAccessManager = ({ id, disabled }: { id: string; disabled: boolean }) => {
const { item, loading, update } = useDriveItem(id);

console.log(item?.access_info.entities);

const userEntities = item?.access_info.entities.filter(a => a.type === 'user') || [];
const folderEntity = item?.access_info.entities.filter(a => a.type === 'folder')?.[0] || {
type: 'folder',
Expand Down

0 comments on commit ae37be8

Please sign in to comment.