Skip to content

Commit bb6ab45

Browse files
committed
feat: added functions for starting and stopping polling
closes #17
1 parent db355a8 commit bb6ab45

File tree

9 files changed

+2345
-1851
lines changed

9 files changed

+2345
-1851
lines changed

README.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 🗂️ use-fs
22

3-
A React hook for integrating with the [File System Access API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API). Visit [**use-fs.com**](https://use-fs.com) to try it out.
3+
A React hook for integrating with the [File System Access API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API). Visit [**use-fs.com**](https://use-fs.com) to try it out in your browser.
44

55
The File System Access API enables web applications to seamlessly work with files on a user's local system. After a user grants permission, web apps can read, write, and manage files directly - eliminating the need for repeated file selection dialogs. This capability is ideal for creating powerful browser-based tools.
66

@@ -33,7 +33,10 @@ function App() {
3333
onClear,
3434
isProcessing,
3535
writeFile,
36-
deleteFile
36+
deleteFile,
37+
startPolling,
38+
stopPolling,
39+
isPolling
3740
} = useFs({
3841
// Optional array of filter functions to exclude files/directories. By default `commonFilters` is used to ignore .git, node_modules, etc.
3942
filters: [
@@ -104,6 +107,24 @@ function App() {
104107
Clear
105108
</button>
106109

110+
<button
111+
onClick={startPolling}
112+
disabled={isProcessing || isPolling}
113+
>
114+
Start Polling
115+
</button>
116+
117+
<button
118+
onClick={stopPolling}
119+
disabled={isProcessing || !isPolling}
120+
>
121+
Stop Polling
122+
</button>
123+
124+
<div>
125+
Status: {isPolling ? 'Polling Active' : 'Polling Stopped'}
126+
</div>
127+
107128
{files.size > 0 && (
108129
<div>
109130
<h2>Files ({files.size}):</h2>
@@ -133,10 +154,11 @@ The hook provides several key features:
133154
1. **File System Access**: Prompts users to select a directory and maintains access to it.
134155
2. **File Writing**: Allows writing content to files with options for truncation and creation.
135156
3. **File Deletion**: Enables safe removal of files from the selected directory.
136-
4. **File Watching**: Continuously monitors selected directory for changes.
137-
5. **Content Management**: Provides access to file contents and updates in real-time.
138-
6. **Filtering**: Built-in and custom filters to exclude unwanted files/directories.
139-
7. **Performance Optimizations**:
157+
4. **File Watching**: Continuously monitors selected directory for changes with automatic polling.
158+
5. **Polling Control**: Manual control over when to start/stop monitoring for file changes.
159+
6. **Content Management**: Provides access to file contents and updates in real-time.
160+
7. **Filtering**: Built-in and custom filters to exclude unwanted files/directories.
161+
8. **Performance Optimizations**:
140162
- Batched file processing
141163
- Content caching
142164
- Debounced updates
@@ -161,4 +183,18 @@ The hook provides several key features:
161183
- `isProcessing: boolean` - Whether files are being processed
162184
- `isBrowserSupported: boolean` - Whether File System API is supported
163185
- `writeFile: (path: string, data: string | ArrayBuffer | Blob, options?: FileWriteOptions) => Promise<void>` - Function to write to files
164-
- `deleteFile: (path: string) => Promise<void>` - Function to delete files
186+
- `deleteFile: (path: string) => Promise<void>` - Function to delete files
187+
- `startPolling: () => void` - Function to manually start polling for file changes
188+
- `stopPolling: () => void` - Function to manually stop polling for file changes
189+
- `isPolling: boolean` - Whether the hook is actively polling for changes
190+
191+
192+
## 📚 Contributing
193+
194+
1. Navigate to the `docs` directory
195+
2. Run `pnpm install` to install the dependencies
196+
3. Run `pnpm dev` to start the development server
197+
3. Navigate to `http://localhost:3000` to view the demo.
198+
5. Modify the `Demo.tsx` file to make your changes.
199+
200+
If you're making changes to the `use-fs` package, you can run `pnpm build` to build the package and then run `pnpm link use-fs` to link the package to the `docs` directory for local development and testing.

docs/README.md

Lines changed: 0 additions & 26 deletions
This file was deleted.

docs/content/docs/index.mdx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
---
2-
title: Hello World
3-
description: Your first document
2+
title: use-fs
3+
description: A React hook for integrating with the File System Access API.
44
---
5-
6-
Welcome to the docs! You can start writing documents in `/content/docs`.
7-
8-
## What is Next?
9-
10-
<Cards>
11-
<Card title="Learn more about Next.js" href="https://nextjs.org/docs" />
12-
<Card title="Learn more about Fumadocs" href="https://fumadocs.vercel.app" />
13-
</Cards>

docs/content/docs/test.mdx

Lines changed: 0 additions & 17 deletions
This file was deleted.

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"react": "^19.0.0",
1818
"react-dom": "^19.0.0",
1919
"react-install-command": "^1.1.2",
20-
"use-fs": "^0.0.12"
20+
"use-fs": "0.0.12"
2121
},
2222
"devDependencies": {
2323
"@iconify/react": "^5.2.0",

0 commit comments

Comments
 (0)