@shiftengineering/folio 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,6 +26,7 @@ This package exports three main features:
26
26
  - `useFolioFiles` - Get files for a project
27
27
  - `useAddFolioProject` - Create new projects
28
28
  - `useAddFolioFiles` - Add files to a project
29
+ - `useAddFolioDirectoryWithFiles` - Add a directory with files to a project
29
30
 
30
31
  ### Basic Setup
31
32
 
@@ -78,6 +79,7 @@ import {
78
79
  useFolioFiles,
79
80
  useAddFolioProject,
80
81
  useAddFolioFiles,
82
+ useAddFolioDirectoryWithFiles,
81
83
  } from "@shiftengineering/folio";
82
84
  import { useState } from "react";
83
85
 
@@ -101,6 +103,10 @@ function FolioProjectManager() {
101
103
  const { addFiles, isAdding: isAddingFiles } =
102
104
  useAddFolioFiles(selectedProjectId);
103
105
 
106
+ // Add a directory with files to a project
107
+ const { addDirectoryWithFiles, isAdding: isAddingDirectory } =
108
+ useAddFolioDirectoryWithFiles(selectedProjectId);
109
+
104
110
  const handleCreateProject = () => {
105
111
  addProject("My New Project");
106
112
  };
@@ -109,6 +115,17 @@ function FolioProjectManager() {
109
115
  addFiles([{ blobUrl: "/path/to/file.pdf", name: "My Document.pdf" }]);
110
116
  };
111
117
 
118
+ const handleAddDirectory = () => {
119
+ addDirectoryWithFiles({
120
+ directoryName: "My Documents",
121
+ directoryMetadata: JSON.stringify({ category: "reports" }),
122
+ files: [
123
+ { blobUrl: "/path/to/file1.pdf", name: "Document 1.pdf" },
124
+ { blobUrl: "/path/to/file2.pdf", name: "Document 2.pdf" },
125
+ ],
126
+ });
127
+ };
128
+
112
129
  if (isProjectsLoading) return <div>Loading projects...</div>;
113
130
  if (projectsError) return <div>Error: {projectsError.message}</div>;
114
131
 
@@ -139,6 +156,9 @@ function FolioProjectManager() {
139
156
  <button onClick={handleAddFile} disabled={isAddingFiles}>
140
157
  {isAddingFiles ? "Adding..." : "Add File"}
141
158
  </button>
159
+ <button onClick={handleAddDirectory} disabled={isAddingDirectory}>
160
+ {isAddingDirectory ? "Adding..." : "Add Directory with Files"}
161
+ </button>
142
162
 
143
163
  {isFilesLoading ? (
144
164
  <div>Loading files...</div>
@@ -222,27 +242,40 @@ Hook for adding a new project.
222
242
 
223
243
  #### `useAddFolioFiles(projectId?: number)`
224
244
 
225
- Hook for adding files to a project.
245
+ Hook for adding files to a project. Files are always created at the root level (parentId = null) and are not directories.
246
+
247
+ | Return Property | Type | Description |
248
+ | --------------- | ---------------------------------------------------------------------- | ---------------------------------- |
249
+ | `addFiles` | `(files: { blobUrl: string; name: string }[]) => void` | Function to add files |
250
+ | `addFilesAsync` | `(files: { blobUrl: string; name: string }[]) => Promise<FolioFile[]>` | Async version returning a promise |
251
+ | `isAdding` | `boolean` | Whether files are being added |
252
+ | `isError` | `boolean` | Whether an error occurred |
253
+ | `error` | `Error \| null` | Error object if an error occurred |
254
+ | `newFiles` | `FolioFile[] \| undefined` | The newly added files if available |
255
+
256
+ #### `useAddFolioDirectoryWithFiles(projectId?: number)`
257
+
258
+ Hook for adding a directory with files to a project. Directory names must be unique at the root level (duplicates will be silently skipped with a console warning).
226
259
 
227
- | Return Property | Type | Description |
228
- | --------------- | ---------------------------------------------------------- | ---------------------------------- |
229
- | `addFiles` | `(files: Omit<FolioFile, "id">[]) => void` | Function to add files |
230
- | `addFilesAsync` | `(files: Omit<FolioFile, "id">[]) => Promise<FolioFile[]>` | Async version returning a promise |
231
- | `isAdding` | `boolean` | Whether files are being added |
232
- | `isError` | `boolean` | Whether an error occurred |
233
- | `error` | `Error \| null` | Error object if an error occurred |
234
- | `newFiles` | `FolioFile[] \| undefined` | The newly added files if available |
260
+ | Return Property | Type | Description |
261
+ | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
262
+ | `addDirectoryWithFiles` | `(params: { directoryName: string; directoryMetadata: string; files: { blobUrl: string; name: string }[] }) => void` | Function to add a directory with files |
263
+ | `addDirectoryWithFilesAsync` | `(params: { directoryName: string; directoryMetadata: string; files: { blobUrl: string; name: string }[] }) => Promise<{ directory: FolioFile \| null; files: FolioFile[] }>` | Async version returning a promise |
264
+ | `isAdding` | `boolean` | Whether the directory and files are being added |
265
+ | `isError` | `boolean` | Whether an error occurred |
266
+ | `error` | `Error \| null` | Error object if an error occurred |
267
+ | `result` | `{ directory: FolioFile \| null; files: FolioFile[] } \| undefined` | The newly added directory and files. If directory is null, it means a directory with that name already existed |
235
268
 
236
269
  ## Types
237
270
 
238
271
  The library exports these TypeScript types:
239
272
 
240
- | Type | Description |
241
- | -------------------- | ------------------------------------- |
242
- | `FolioFile` | Represents a file in Folio |
243
- | `FolioProject` | Represents a project in Folio |
244
- | `FolioEmbedProps` | Props for the FolioEmbed component |
245
- | `FolioProviderProps` | Props for the FolioProvider component |
273
+ | Type | Description |
274
+ | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
275
+ | `FolioFile` | Represents a file in Folio. Contains properties: `id`, `name`, `blobUrl`, `parentId` (null for root items), and `isDirectory` (boolean) |
276
+ | `FolioProject` | Represents a project in Folio |
277
+ | `FolioEmbedProps` | Props for the FolioEmbed component |
278
+ | `FolioProviderProps` | Props for the FolioProvider component |
246
279
 
247
280
  ## License
248
281