Skip to content

Commit

Permalink
Merge pull request #1925 from holium/trove-space-fix
Browse files Browse the repository at this point in the history
-fix navigating to a space with selected trove
  • Loading branch information
Haroldthe24th authored Jul 17, 2023
2 parents 4d47f0c + 13a90c0 commit d5fc880
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
6 changes: 3 additions & 3 deletions trove/src/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
WrappedBackground,
} from '../components';
import { moveFileAction, moveFolderAction } from '../store/troveActions';
import useTroveStore, { TroveStore } from '../store/troveStore';
import useTroveStore, { Node, TroveStore } from '../store/troveStore';
import { theme } from '../theme';
export const Main = ({
troveRenderTree,
Expand All @@ -32,7 +32,6 @@ export const Main = ({
const [displayFolderInput, setDisplayFolderInput] = useState<boolean>(false);
const [displayFileInput, setDisplayFileInput] = useState<boolean>(false);
const [displayFileLink, setDisplayFileLink] = useState<boolean>(false);

const api = useTroveStore((store: TroveStore) => store.api);

const myPerms = useTroveStore((store: TroveStore) => store.myPerms);
Expand All @@ -45,9 +44,10 @@ export const Main = ({
(store: TroveStore) => store.setSelectedNode
);
const space = useTroveStore((store: TroveStore) => store.currentSpace);
const handleSelection = (data: any = null) => {
const handleSelection = (data: Node = null) => {
//if we get the same instance twice, we unselect
setSelectedNode(null);
if (!data) return;
if (data?.id === selectedNode?.id) {
//this block isn't empty
} else {
Expand Down
5 changes: 5 additions & 0 deletions trove/src/components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ export const Navigation = ({ selectedSpace }: Props) => {
//presisted space data for filtering search correctly
const navigate = useNavigate();
const setSpace = useTroveStore((store: TroveStore) => store.setSpace);
const setSelectedTopLevelFolder = useTroveStore(
(store: TroveStore) => store.setSelectedTopLevelFolder
);
useEffect(() => {
//everytime space changes redirect to that space
if (selectedSpace) {
//make sure we don't have a selected top level forlder when we navigate (trove)
setSelectedTopLevelFolder(null);
navigate(selectedSpace);
}
}, [selectedSpace]);
Expand Down
12 changes: 10 additions & 2 deletions trove/src/components/RecursiveTree.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { memo } from 'react';
import Box from '@mui/material/Box';

import { Node, TroveRenderTree } from '../store/troveStore';
import { FileItem } from './FileItem';
import { FolderItem } from './FolderItem';
//TODO: make two components for folders and one for files
interface Props {
itemList: undefined | [] | TroveRenderTree;
handleSelection: (data: Node) => void;
deleteFile: (key: string) => void;
selected: Node;
writePerms: boolean;
}
export const RecursiveTree = memo(
({ itemList, handleSelection, selected, writePerms, deleteFile }: any) => {
({ itemList, handleSelection, selected, writePerms, deleteFile }: Props) => {
const createTree = (name: any, data: any, parentCount = 0) => {
if (data.type === 'folder') {
return (
Expand Down Expand Up @@ -53,7 +61,7 @@ export const RecursiveTree = memo(
};
return (
<Box>
{itemList.map((item: any) => {
{itemList?.map((item: any) => {
if (item.type === 'folder') {
return createTree(item.path, item);
} else {
Expand Down
36 changes: 31 additions & 5 deletions trove/src/store/troveStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,37 @@ import { Role } from '../types';

export type Folder = null | string;

type Node = null | {
export type Node = null | {
id: string;
type: 'file' | 'folder';
};

interface TroveRenderFile {
[key: string]: {
url: string;
dat: {
size: string;
title: string;
key: string;
from: number;
description: string;
by: string;
extension: string;
};
type: string;
};
}
interface TroveRenderFolder {
text: string;
path: string;
type: string;
timestamp: number;
children: TroveRenderFolder | TroveRenderFile | []; //has either a folder or a file as a child or is an empty array
}
export type TroveRenderTree =
| {
[key: string]: TroveRenderFolder | TroveRenderFile | []; //a map of ship/space to trove folder and their files..
}[]
| null;
export interface TroveStore {
api: null | typeof trovePreload;
setApi: (api: typeof trovePreload) => void;
Expand All @@ -20,8 +46,8 @@ export interface TroveStore {
inPersonalSpace: null | boolean;
setInPersonalSpace: (state: boolean) => void;

troveRenderTree: any; //calculated from the troves variable, for rendering in react
setTroveRenderTree: (newTroveRenderTree: any) => void;
troveRenderTree: TroveRenderTree; //calculated from the troves variable, for rendering in react
setTroveRenderTree: (newTroveRenderTree: TroveRenderTree) => void;

topLevelFolders: any;
setTopLevelFolders: (newTopLevelFolders: any) => void;
Expand Down Expand Up @@ -65,7 +91,7 @@ const useTroveStore = create<TroveStore>((set) => ({
setInPersonalSpace: (state: any) => set(() => ({ inPersonalSpace: state })),

troveRenderTree: null,
setTroveRenderTree: (newTroveRenderTree: any) =>
setTroveRenderTree: (newTroveRenderTree: TroveRenderTree) =>
set(() => ({ troveRenderTree: newTroveRenderTree })),

topLevelFolders: [],
Expand Down

1 comment on commit d5fc880

@vercel
Copy link

@vercel vercel bot commented on d5fc880 Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Haroldthe24th is attempting to deploy a commit to the Holium Team on Vercel.

To accomplish this, @Haroldthe24th needs to request access to the Team.

Afterwards, an owner of the Team is required to accept their membership request.

If you're already a member of the respective Vercel Team, make sure that your Personal Vercel Account is connected to your GitHub account.

Please sign in to comment.