@plugable-io/react 0.0.12 → 0.0.13
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/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +11 -24
- package/dist/index.mjs +11 -24
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -122,6 +122,7 @@ interface UseFilesOptions {
|
|
|
122
122
|
orderBy?: 'created_at' | 'name' | 'byte_size';
|
|
123
123
|
orderDirection?: 'asc' | 'desc';
|
|
124
124
|
staleTime?: number;
|
|
125
|
+
date?: string;
|
|
125
126
|
}
|
|
126
127
|
interface UseFilesResult {
|
|
127
128
|
files: FileObject[];
|
|
@@ -136,7 +137,7 @@ interface UseFilesResult {
|
|
|
136
137
|
setPage: (page: number) => void;
|
|
137
138
|
refresh: () => Promise<void>;
|
|
138
139
|
}
|
|
139
|
-
declare function useFiles({ metadata, startPage, perPage, mediaType, autoLoad, orderBy, orderDirection, staleTime, }?: UseFilesOptions): UseFilesResult;
|
|
140
|
+
declare function useFiles({ metadata, startPage, perPage, mediaType, autoLoad, orderBy, orderDirection, staleTime, date, }?: UseFilesOptions): UseFilesResult;
|
|
140
141
|
|
|
141
142
|
interface ThemeConfig {
|
|
142
143
|
accentColor?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -122,6 +122,7 @@ interface UseFilesOptions {
|
|
|
122
122
|
orderBy?: 'created_at' | 'name' | 'byte_size';
|
|
123
123
|
orderDirection?: 'asc' | 'desc';
|
|
124
124
|
staleTime?: number;
|
|
125
|
+
date?: string;
|
|
125
126
|
}
|
|
126
127
|
interface UseFilesResult {
|
|
127
128
|
files: FileObject[];
|
|
@@ -136,7 +137,7 @@ interface UseFilesResult {
|
|
|
136
137
|
setPage: (page: number) => void;
|
|
137
138
|
refresh: () => Promise<void>;
|
|
138
139
|
}
|
|
139
|
-
declare function useFiles({ metadata, startPage, perPage, mediaType, autoLoad, orderBy, orderDirection, staleTime, }?: UseFilesOptions): UseFilesResult;
|
|
140
|
+
declare function useFiles({ metadata, startPage, perPage, mediaType, autoLoad, orderBy, orderDirection, staleTime, date, }?: UseFilesOptions): UseFilesResult;
|
|
140
141
|
|
|
141
142
|
interface ThemeConfig {
|
|
142
143
|
accentColor?: string;
|
package/dist/index.js
CHANGED
|
@@ -575,10 +575,6 @@ function Dropzone({
|
|
|
575
575
|
|
|
576
576
|
// src/hooks/useFiles.ts
|
|
577
577
|
var import_react3 = require("react");
|
|
578
|
-
var DEBUG = true;
|
|
579
|
-
function log(msg, ...args) {
|
|
580
|
-
if (DEBUG) console.log(`[useFiles] ${msg}`, ...args);
|
|
581
|
-
}
|
|
582
578
|
function useFiles({
|
|
583
579
|
metadata,
|
|
584
580
|
startPage = 1,
|
|
@@ -587,7 +583,8 @@ function useFiles({
|
|
|
587
583
|
autoLoad = true,
|
|
588
584
|
orderBy,
|
|
589
585
|
orderDirection,
|
|
590
|
-
staleTime
|
|
586
|
+
staleTime,
|
|
587
|
+
date
|
|
591
588
|
} = {}) {
|
|
592
589
|
const { client, on, getCache, setCache, staleTime: providerStaleTime } = usePlugable();
|
|
593
590
|
const [files, setFiles] = (0, import_react3.useState)([]);
|
|
@@ -604,8 +601,9 @@ function useFiles({
|
|
|
604
601
|
perPage,
|
|
605
602
|
orderBy,
|
|
606
603
|
orderDirection,
|
|
607
|
-
page
|
|
608
|
-
|
|
604
|
+
page,
|
|
605
|
+
date
|
|
606
|
+
}), [stableMetadata, mediaType, perPage, orderBy, orderDirection, page, date]);
|
|
609
607
|
const fetchFiles = (0, import_react3.useCallback)(async (pageNum, skipCache = false) => {
|
|
610
608
|
const currentParamsKey = JSON.stringify({
|
|
611
609
|
metadata: stableMetadata,
|
|
@@ -613,23 +611,19 @@ function useFiles({
|
|
|
613
611
|
perPage,
|
|
614
612
|
orderBy,
|
|
615
613
|
orderDirection,
|
|
616
|
-
page: pageNum
|
|
614
|
+
page: pageNum,
|
|
615
|
+
date
|
|
617
616
|
});
|
|
618
|
-
log("fetchFiles called", { pageNum, skipCache, currentParamsKey });
|
|
619
617
|
if (!skipCache) {
|
|
620
618
|
const cachedEntry = getCache(currentParamsKey);
|
|
621
619
|
if (cachedEntry) {
|
|
622
620
|
const age = Date.now() - cachedEntry.timestamp;
|
|
623
621
|
const isStale = age > effectiveStaleTime;
|
|
624
|
-
log("Cache check", { exists: true, age, isStale });
|
|
625
622
|
if (!isStale) {
|
|
626
|
-
log("Serving from cache");
|
|
627
623
|
setFiles(cachedEntry.files);
|
|
628
624
|
setHasNext(cachedEntry.paging.has_next_page);
|
|
629
625
|
return;
|
|
630
626
|
}
|
|
631
|
-
} else {
|
|
632
|
-
log("Cache miss");
|
|
633
627
|
}
|
|
634
628
|
}
|
|
635
629
|
setIsLoading(true);
|
|
@@ -641,11 +635,10 @@ function useFiles({
|
|
|
641
635
|
per_page: perPage,
|
|
642
636
|
with_download_url: true,
|
|
643
637
|
...orderBy && { order_by: orderBy },
|
|
644
|
-
...orderDirection && { order_direction: orderDirection }
|
|
638
|
+
...orderDirection && { order_direction: orderDirection },
|
|
639
|
+
date
|
|
645
640
|
};
|
|
646
|
-
log("Sending API Request", options);
|
|
647
641
|
const response = await client.list(options);
|
|
648
|
-
log("API Response received", response);
|
|
649
642
|
setCache(currentParamsKey, {
|
|
650
643
|
files: response.files,
|
|
651
644
|
paging: response.paging,
|
|
@@ -654,38 +647,33 @@ function useFiles({
|
|
|
654
647
|
setFiles(response.files);
|
|
655
648
|
setHasNext(response.paging.has_next_page);
|
|
656
649
|
} catch (err) {
|
|
657
|
-
console.error("
|
|
650
|
+
console.error("Failed to load files:", err);
|
|
658
651
|
setFiles([]);
|
|
659
652
|
setHasNext(false);
|
|
660
653
|
} finally {
|
|
661
654
|
setIsLoading(false);
|
|
662
655
|
}
|
|
663
|
-
}, [client, stableMetadata, mediaType, perPage, orderBy, orderDirection, getCache, setCache, effectiveStaleTime]);
|
|
656
|
+
}, [client, stableMetadata, mediaType, perPage, orderBy, orderDirection, getCache, setCache, effectiveStaleTime, date]);
|
|
664
657
|
(0, import_react3.useEffect)(() => {
|
|
665
|
-
log("Effect triggered", { paramsKeyWithPage, autoLoad, initialized: hasInitializedRef.current });
|
|
666
658
|
if (!hasInitializedRef.current) {
|
|
667
659
|
hasInitializedRef.current = true;
|
|
668
660
|
if (!autoLoad) {
|
|
669
|
-
log("Skipping initial load because autoLoad is false");
|
|
670
661
|
return;
|
|
671
662
|
}
|
|
672
663
|
}
|
|
673
664
|
const cachedEntry = getCache(paramsKeyWithPage);
|
|
674
665
|
const isStale = cachedEntry ? Date.now() - cachedEntry.timestamp > effectiveStaleTime : true;
|
|
675
666
|
if (cachedEntry) {
|
|
676
|
-
log("Immediate cache hit in Effect", { isStale });
|
|
677
667
|
setFiles(cachedEntry.files);
|
|
678
668
|
setHasNext(cachedEntry.paging.has_next_page);
|
|
679
669
|
if (!isStale) {
|
|
680
670
|
return;
|
|
681
671
|
}
|
|
682
672
|
}
|
|
683
|
-
log("Proceeding to fetch");
|
|
684
673
|
fetchFiles(page, true);
|
|
685
674
|
}, [paramsKeyWithPage, autoLoad, getCache, effectiveStaleTime, fetchFiles, page]);
|
|
686
675
|
(0, import_react3.useEffect)(() => {
|
|
687
676
|
const unsubscribe = on("file.uploaded", () => {
|
|
688
|
-
log("Event file.uploaded received, refreshing...");
|
|
689
677
|
fetchFiles(page, true);
|
|
690
678
|
});
|
|
691
679
|
return unsubscribe;
|
|
@@ -697,7 +685,6 @@ function useFiles({
|
|
|
697
685
|
setPage((p) => Math.max(1, p - 1));
|
|
698
686
|
}, []);
|
|
699
687
|
const refresh = (0, import_react3.useCallback)(async () => {
|
|
700
|
-
log("Manual refresh triggered");
|
|
701
688
|
await fetchFiles(page, true);
|
|
702
689
|
}, [fetchFiles, page]);
|
|
703
690
|
return {
|
package/dist/index.mjs
CHANGED
|
@@ -529,10 +529,6 @@ function Dropzone({
|
|
|
529
529
|
|
|
530
530
|
// src/hooks/useFiles.ts
|
|
531
531
|
import { useState as useState3, useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
|
|
532
|
-
var DEBUG = true;
|
|
533
|
-
function log(msg, ...args) {
|
|
534
|
-
if (DEBUG) console.log(`[useFiles] ${msg}`, ...args);
|
|
535
|
-
}
|
|
536
532
|
function useFiles({
|
|
537
533
|
metadata,
|
|
538
534
|
startPage = 1,
|
|
@@ -541,7 +537,8 @@ function useFiles({
|
|
|
541
537
|
autoLoad = true,
|
|
542
538
|
orderBy,
|
|
543
539
|
orderDirection,
|
|
544
|
-
staleTime
|
|
540
|
+
staleTime,
|
|
541
|
+
date
|
|
545
542
|
} = {}) {
|
|
546
543
|
const { client, on, getCache, setCache, staleTime: providerStaleTime } = usePlugable();
|
|
547
544
|
const [files, setFiles] = useState3([]);
|
|
@@ -558,8 +555,9 @@ function useFiles({
|
|
|
558
555
|
perPage,
|
|
559
556
|
orderBy,
|
|
560
557
|
orderDirection,
|
|
561
|
-
page
|
|
562
|
-
|
|
558
|
+
page,
|
|
559
|
+
date
|
|
560
|
+
}), [stableMetadata, mediaType, perPage, orderBy, orderDirection, page, date]);
|
|
563
561
|
const fetchFiles = useCallback3(async (pageNum, skipCache = false) => {
|
|
564
562
|
const currentParamsKey = JSON.stringify({
|
|
565
563
|
metadata: stableMetadata,
|
|
@@ -567,23 +565,19 @@ function useFiles({
|
|
|
567
565
|
perPage,
|
|
568
566
|
orderBy,
|
|
569
567
|
orderDirection,
|
|
570
|
-
page: pageNum
|
|
568
|
+
page: pageNum,
|
|
569
|
+
date
|
|
571
570
|
});
|
|
572
|
-
log("fetchFiles called", { pageNum, skipCache, currentParamsKey });
|
|
573
571
|
if (!skipCache) {
|
|
574
572
|
const cachedEntry = getCache(currentParamsKey);
|
|
575
573
|
if (cachedEntry) {
|
|
576
574
|
const age = Date.now() - cachedEntry.timestamp;
|
|
577
575
|
const isStale = age > effectiveStaleTime;
|
|
578
|
-
log("Cache check", { exists: true, age, isStale });
|
|
579
576
|
if (!isStale) {
|
|
580
|
-
log("Serving from cache");
|
|
581
577
|
setFiles(cachedEntry.files);
|
|
582
578
|
setHasNext(cachedEntry.paging.has_next_page);
|
|
583
579
|
return;
|
|
584
580
|
}
|
|
585
|
-
} else {
|
|
586
|
-
log("Cache miss");
|
|
587
581
|
}
|
|
588
582
|
}
|
|
589
583
|
setIsLoading(true);
|
|
@@ -595,11 +589,10 @@ function useFiles({
|
|
|
595
589
|
per_page: perPage,
|
|
596
590
|
with_download_url: true,
|
|
597
591
|
...orderBy && { order_by: orderBy },
|
|
598
|
-
...orderDirection && { order_direction: orderDirection }
|
|
592
|
+
...orderDirection && { order_direction: orderDirection },
|
|
593
|
+
date
|
|
599
594
|
};
|
|
600
|
-
log("Sending API Request", options);
|
|
601
595
|
const response = await client.list(options);
|
|
602
|
-
log("API Response received", response);
|
|
603
596
|
setCache(currentParamsKey, {
|
|
604
597
|
files: response.files,
|
|
605
598
|
paging: response.paging,
|
|
@@ -608,38 +601,33 @@ function useFiles({
|
|
|
608
601
|
setFiles(response.files);
|
|
609
602
|
setHasNext(response.paging.has_next_page);
|
|
610
603
|
} catch (err) {
|
|
611
|
-
console.error("
|
|
604
|
+
console.error("Failed to load files:", err);
|
|
612
605
|
setFiles([]);
|
|
613
606
|
setHasNext(false);
|
|
614
607
|
} finally {
|
|
615
608
|
setIsLoading(false);
|
|
616
609
|
}
|
|
617
|
-
}, [client, stableMetadata, mediaType, perPage, orderBy, orderDirection, getCache, setCache, effectiveStaleTime]);
|
|
610
|
+
}, [client, stableMetadata, mediaType, perPage, orderBy, orderDirection, getCache, setCache, effectiveStaleTime, date]);
|
|
618
611
|
useEffect2(() => {
|
|
619
|
-
log("Effect triggered", { paramsKeyWithPage, autoLoad, initialized: hasInitializedRef.current });
|
|
620
612
|
if (!hasInitializedRef.current) {
|
|
621
613
|
hasInitializedRef.current = true;
|
|
622
614
|
if (!autoLoad) {
|
|
623
|
-
log("Skipping initial load because autoLoad is false");
|
|
624
615
|
return;
|
|
625
616
|
}
|
|
626
617
|
}
|
|
627
618
|
const cachedEntry = getCache(paramsKeyWithPage);
|
|
628
619
|
const isStale = cachedEntry ? Date.now() - cachedEntry.timestamp > effectiveStaleTime : true;
|
|
629
620
|
if (cachedEntry) {
|
|
630
|
-
log("Immediate cache hit in Effect", { isStale });
|
|
631
621
|
setFiles(cachedEntry.files);
|
|
632
622
|
setHasNext(cachedEntry.paging.has_next_page);
|
|
633
623
|
if (!isStale) {
|
|
634
624
|
return;
|
|
635
625
|
}
|
|
636
626
|
}
|
|
637
|
-
log("Proceeding to fetch");
|
|
638
627
|
fetchFiles(page, true);
|
|
639
628
|
}, [paramsKeyWithPage, autoLoad, getCache, effectiveStaleTime, fetchFiles, page]);
|
|
640
629
|
useEffect2(() => {
|
|
641
630
|
const unsubscribe = on("file.uploaded", () => {
|
|
642
|
-
log("Event file.uploaded received, refreshing...");
|
|
643
631
|
fetchFiles(page, true);
|
|
644
632
|
});
|
|
645
633
|
return unsubscribe;
|
|
@@ -651,7 +639,6 @@ function useFiles({
|
|
|
651
639
|
setPage((p) => Math.max(1, p - 1));
|
|
652
640
|
}, []);
|
|
653
641
|
const refresh = useCallback3(async () => {
|
|
654
|
-
log("Manual refresh triggered");
|
|
655
642
|
await fetchFiles(page, true);
|
|
656
643
|
}, [fetchFiles, page]);
|
|
657
644
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plugable-io/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "React components and hooks for Plugable File Management API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"react-dom": ">=16.8.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@plugable-io/js": "^0.0.
|
|
46
|
+
"@plugable-io/js": "^0.0.12"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/node": "^20.0.0",
|