Skip to content
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Stored in /users/{uid}/files/{fileID} in Firebase.
*/
export type UserFile = {
type: string;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is "type"?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

it determines if the user is storing is a file or a folder

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

got it. what do you think about storing them separately: /users/{uid}/files/{fileID} and /users/{uid}/folders/{folderID}? or even /users/{uid}/files/folders/{folderID} if you prefer.

That way we can type them differently. In particular, some fields of files are not relevant for folders, like "language."

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

well storing separately will make the code significantly more complicated;
i would suggest

export type File = {
kind: "file";
id: string;
name: string;
language?: string;
// File-specific fields
};

export type Folder = {
kind: "folder";
id: string;
name: string;
// Folder-specific fields
};

export type UserItem = File | Folder;

using a discriminated union

so that it doesn't become as complex and still is one file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sure, I'm ok with that!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@meher0704 does this still need to be updated?

id: string; // not stored in database; injected by client
lastAccessTime: number;
title: string;
Expand Down
Loading