Skip to content

Commit

Permalink
-types added to RecursiveTree props
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroldthe24th committed Jul 17, 2023
1 parent 8e57b4c commit 13a90c0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 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
10 changes: 9 additions & 1 deletion 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
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

0 comments on commit 13a90c0

Please sign in to comment.