+ const picker = getTreePicker<ProjectsTreePickerItem>(pickerId)(getState().treePicker);
+ if (picker) {
+
+ const node = getNode(id)(picker);
+ if (node && 'kind' in node.value && node.value.kind === ResourceKind.COLLECTION) {
+
+ const filesTree = await services.collectionService.files(node.value.portableDataHash);
+
+ dispatch(
+ treePickerActions.APPEND_TREE_PICKER_NODE_SUBTREE({
+ id,
+ pickerId,
+ subtree: mapTree(node => ({ ...node, status: TreeNodeStatus.LOADED }))(filesTree)
+ }));
+
+ dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id, pickerId }));
+ }
+ }
+ };
+
+
+export const initUserProject = (pickerId: string) =>
+ async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+ const uuid = services.authService.getUuid();
+ if (uuid) {
+ dispatch(receiveTreePickerData({
+ id: '',
+ pickerId,
+ data: [{ uuid, name: 'Projects' }],
+ extractNodeData: value => ({
+ id: value.uuid,
+ status: TreeNodeStatus.INITIAL,
+ value,
+ }),
+ }));
+ }
+ };
+export const loadUserProject = (pickerId: string, includeCollections = false, includeFiles = false) =>
+ async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+ const uuid = services.authService.getUuid();
+ if (uuid) {
+ dispatch(loadProject({ id: uuid, pickerId, includeCollections, includeFiles }));
+ }
+ };
+
+export const SHARED_PROJECT_ID = 'Shared with me';
+export const initSharedProject = (pickerId: string) =>
+ async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+ dispatch(receiveTreePickerData({
+ id: '',
+ pickerId,
+ data: [{ uuid: SHARED_PROJECT_ID, name: SHARED_PROJECT_ID }],
+ extractNodeData: value => ({
+ id: value.uuid,
+ status: TreeNodeStatus.INITIAL,
+ value,
+ }),
+ }));
+ };
+
+export const FAVORITES_PROJECT_ID = 'Favorites';
+export const initFavoritesProject = (pickerId: string) =>
+ async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+ dispatch(receiveTreePickerData({
+ id: '',
+ pickerId,
+ data: [{ uuid: FAVORITES_PROJECT_ID, name: FAVORITES_PROJECT_ID }],
+ extractNodeData: value => ({
+ id: value.uuid,
+ status: TreeNodeStatus.INITIAL,
+ value,
+ }),
+ }));
+ };
+
+interface LoadFavoritesProjectParams {
+ pickerId: string;
+ includeCollections?: boolean;
+ includeFiles?: boolean;
+}
+
+export const loadFavoritesProject = (params: LoadFavoritesProjectParams) =>
+ async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+ const { pickerId, includeCollections = false, includeFiles = false } = params;
+ const uuid = services.authService.getUuid();
+ if (uuid) {
+
+ const filters = pipe(
+ (fb: FilterBuilder) => includeCollections
+ ? fb.addIsA('headUuid', [ResourceKind.PROJECT, ResourceKind.COLLECTION])
+ : fb.addIsA('headUuid', [ResourceKind.PROJECT]),
+ fb => fb.getFilters(),
+ )(new FilterBuilder());
+
+ const { items } = await services.favoriteService.list(uuid, { filters });
+
+ dispatch<any>(receiveTreePickerData<GroupContentsResource>({
+ id: 'Favorites',
+ pickerId,
+ data: items,
+ extractNodeData: item => ({
+ id: item.uuid,
+ value: item,
+ status: item.kind === ResourceKind.PROJECT
+ ? TreeNodeStatus.INITIAL
+ : includeFiles
+ ? TreeNodeStatus.INITIAL
+ : TreeNodeStatus.LOADED
+ }),
+ }));
+ }
+ };