🔢 Shared with me filters (#79)

 feat: shared with me filters
🐛 Fix try to access the service with init
🌐 feat: shared with me i18n
🌐russian translation

---------

Co-authored-by: Anton SHEPILOV <ashepilov@linagora.com>
This commit is contained in:
Montassar Ghanmy
2023-06-17 15:37:33 +01:00
committed by GitHub
parent fddd3b4ebd
commit 441c2b780f
19 changed files with 482 additions and 404 deletions
@@ -4,7 +4,7 @@ import { useCallback } from 'react';
import { useRecoilCallback } from 'recoil';
import { DriveApiClient } from '../api-client/api-client';
import { DriveItemAtom, DriveItemChildrenAtom } from '../state/store';
import { DriveItem, DriveItemDetails, DriveItemVersion } from '../types';
import { DriveItem, DriveItemVersion } from '../types';
/**
* Returns the children of a drive item
@@ -18,59 +18,20 @@ export const useDriveActions = () => {
({ set, snapshot }) =>
async (parentId: string) => {
if (parentId) {
if (parentId == "shared-with-me") {
const details = {
path: [
{
id: "shared-with-me",
name: "Shared with me"
}
],
item: {
id: "root",
parent_id: "",
company_id: "",
workspace_id: "",
name: "Shared with me",
size: 0,
description: "",
tags: [],
in_trash: false,
is_directory: true,
extension: "",
added: "",
last_modified: "",
last_version_cache: {},
access_info: {},
},
versions: [],
children: [],
access: "manage",
websockets: [
{
room: "/companies/aa7ffdd0-fadb-11ed-b891-510fe3501b2b/documents/item/root",
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhYTU0Y2YyMC1mYWRiLTExZWQtYjg5MS01MTBmZTM1MDFiMmIiLCJuYW1lIjoiL2NvbXBhbmllcy9hYTdmZmRkMC1mYWRiLTExZWQtYjg5MS01MTBmZTM1MDFiMmIvZG9jdW1lbnRzL2l0ZW0vcm9vdCIsImlhdCI6MTY4ODk1MDk2OCwibmJmIjoxNjg2MjcyNTA4fQ.H6BFRcLG3Op32sqKi45Pf1s2YKcVbMxGZGPJal06l1g"
}
]
};
try {
const details = await DriveApiClient.get(companyId, parentId);
set(DriveItemChildrenAtom(parentId), details.children);
return details;
} else {
try {
const details = await DriveApiClient.get(companyId, parentId);
set(DriveItemChildrenAtom(parentId), details.children);
set(DriveItemAtom(parentId), details);
for (const child of details.children) {
const currentValue = snapshot.getLoadable(DriveItemAtom(child.id)).contents;
if (!currentValue) {
//only update if not already in cache to avoid concurrent updates
set(DriveItemAtom(child.id), { item: child });
}
set(DriveItemAtom(parentId), details);
for (const child of details.children) {
const currentValue = snapshot.getLoadable(DriveItemAtom(child.id)).contents;
if (!currentValue) {
//only update if not already in cache to avoid concurrent updates
set(DriveItemAtom(child.id), { item: child });
}
return details;
} catch (e) {
ToasterService.error('Unable to load your files.');
}
return details;
} catch (e) {
ToasterService.error('Unable to load your files.');
}
}
},
@@ -7,16 +7,16 @@ import _ from 'lodash';
import { useRecoilState, useRecoilValue } from 'recoil';
import { SharedWithMeDriveItemsResultsState } from '../state/shared-with-me-drive-items-result';
import { SearchInputState } from '../../search/state/search-input';
import { SharedWithMeFilterState } from '../state/shared-with-me-filter';
export const useSharedWithMeDriveItemsLoading = () => {
return useRecoilValue(LoadingState('useSearchDriveItems'));
};
let currentQuery = '';
export const useSharedWithMeDriveItems = () => {
const companyId = useRouterCompany();
const searchInput = useRecoilValue(SearchInputState);
const sharedFilter = useRecoilValue(SharedWithMeFilterState);
const [loading, setLoading] = useRecoilState(LoadingState('useSearchDriveItems'));
const [items, setItems] = useRecoilState(SharedWithMeDriveItemsResultsState(companyId));
@@ -34,11 +34,24 @@ export const useSharedWithMeDriveItems = () => {
const refresh = async () => {
setLoading(true);
const query = searchInput.query;
currentQuery = query;
let filter:any = {...sharedFilter};
if (filter.date) {
if (filter.date === "today") {
filter = { ...filter, added_lt: '', added_gt: '' };
}
if (filter.date === "last_week") {
const today = new Date();
const lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7);
filter = { ...filter, added_lt: lastWeek.toISOString(), added_gt: '' };
}
if (filter.date === "last_month") {
const today = new Date();
const lastMonth = new Date(today.getFullYear(), today.getMonth() - 1, today.getDate());
filter = { ...filter, added_lt: lastMonth.toISOString(), added_gt: '' };
}
}
const response = await DriveApiClient.sharedWithMe(opt);
console.log("response is: ", response);
const response = await DriveApiClient.sharedWithMe(filter, opt);
const results = response.entities || [];
const update = {
@@ -47,9 +60,6 @@ export const useSharedWithMeDriveItems = () => {
// nextPage: response.next_page_token,
};
if (currentQuery !== query) {
return;
}
setItems(update);
setLoading(false);
};
@@ -62,18 +72,18 @@ export const useSharedWithMeDriveItems = () => {
useGlobalEffect(
'useSearchDriveItems',
() => {
(async () => {
setLoading(true);
if (searchInput.query) {
delayRequest('useSearchDriveItems', async () => {
await refresh();
});
} else {
refresh();
}
})();
(async () => {
setLoading(true);
if (sharedFilter.mimeType) {
delayRequest('useSearchDriveItems', async () => {
await refresh();
});
} else {
refresh();
}
})();
},
[searchInput.channelId, searchInput.workspaceId],
[sharedFilter, searchInput.channelId, searchInput.workspaceId],
);
return { loading, driveItems: [...items.results], loadMore, refresh };