@soppiya/app-bridge 1.0.0

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.
Files changed (81) hide show
  1. package/README.md +23 -0
  2. package/dist/assets/images/docs.js +2 -0
  3. package/dist/assets/images/document.js +2 -0
  4. package/dist/assets/images/pdf.js +2 -0
  5. package/dist/assets/images/play.js +2 -0
  6. package/dist/assets/images/ppt.js +2 -0
  7. package/dist/assets/images/rar.js +2 -0
  8. package/dist/assets/images/sound.js +2 -0
  9. package/dist/assets/images/txt.js +2 -0
  10. package/dist/assets/images/xls.js +2 -0
  11. package/dist/assets/images/zip.js +2 -0
  12. package/dist/components/index.d.ts +2 -0
  13. package/dist/components/index.js +3 -0
  14. package/dist/components/infinity-scroll/InfinityScroll.d.ts +5 -0
  15. package/dist/components/infinity-scroll/InfinityScroll.js +29 -0
  16. package/dist/components/infinity-scroll/index.d.ts +1 -0
  17. package/dist/components/infinity-scroll/index.js +2 -0
  18. package/dist/components/media/Media.d.ts +11 -0
  19. package/dist/components/media/Media.js +349 -0
  20. package/dist/components/media/Media.stories.d.ts +18 -0
  21. package/dist/components/media/Media.stories.js +13 -0
  22. package/dist/components/media/MediaItem.d.ts +12 -0
  23. package/dist/components/media/MediaItem.js +104 -0
  24. package/dist/components/media/MediaPreview.d.ts +7 -0
  25. package/dist/components/media/MediaPreview.js +127 -0
  26. package/dist/components/media/MediaSorting.d.ts +8 -0
  27. package/dist/components/media/MediaSorting.js +85 -0
  28. package/dist/components/media/format.d.ts +1 -0
  29. package/dist/components/media/format.js +28 -0
  30. package/dist/components/media/graph.d.ts +22 -0
  31. package/dist/components/media/graph.js +75 -0
  32. package/dist/components/media/index.d.ts +1 -0
  33. package/dist/components/media/index.js +2 -0
  34. package/dist/components/media/types.d.ts +13 -0
  35. package/dist/components/media/types.js +6 -0
  36. package/dist/components/media/uploadMedias.d.ts +7 -0
  37. package/dist/components/media/uploadMedias.js +31 -0
  38. package/dist/components/media/useDeleteMedias.d.ts +7 -0
  39. package/dist/components/media/useDeleteMedias.js +14 -0
  40. package/dist/components/media/useDrop.d.ts +11 -0
  41. package/dist/components/media/useDrop.js +41 -0
  42. package/dist/components/media/useMediaFilter.d.ts +5 -0
  43. package/dist/components/media/useMediaFilter.js +15 -0
  44. package/dist/components/media/useMediaSorting.d.ts +6 -0
  45. package/dist/components/media/useMediaSorting.js +19 -0
  46. package/dist/components/media/useMedias.d.ts +31 -0
  47. package/dist/components/media/useMedias.js +58 -0
  48. package/dist/components/media/useStorage.d.ts +8 -0
  49. package/dist/components/media/useStorage.js +17 -0
  50. package/dist/components/media/useThumbnail.d.ts +5 -0
  51. package/dist/components/media/useThumbnail.js +64 -0
  52. package/dist/components/savebar/SaveBar.d.ts +9 -0
  53. package/dist/components/savebar/SaveBar.js +21 -0
  54. package/dist/components/savebar/index.d.ts +1 -0
  55. package/dist/components/savebar/index.js +2 -0
  56. package/dist/hooks/index.d.ts +1 -0
  57. package/dist/hooks/index.js +2 -0
  58. package/dist/hooks/useSoppiyaBridge.d.ts +3 -0
  59. package/dist/hooks/useSoppiyaBridge.js +9 -0
  60. package/dist/index.d.ts +3 -0
  61. package/dist/index.js +3 -0
  62. package/dist/shared/graphql/fragment-masking.d.ts +19 -0
  63. package/dist/shared/graphql/fragment-masking.js +15 -0
  64. package/dist/shared/graphql/gql.d.ts +56 -0
  65. package/dist/shared/graphql/gql.js +12 -0
  66. package/dist/shared/graphql/graphql.d.ts +3881 -0
  67. package/dist/shared/graphql/graphql.js +1226 -0
  68. package/dist/shared/graphql/index.d.ts +2 -0
  69. package/dist/shared/graphql/index.js +2 -0
  70. package/dist/static/image/docs.png +0 -0
  71. package/dist/static/image/document.png +0 -0
  72. package/dist/static/image/pdf.png +0 -0
  73. package/dist/static/image/play.png +0 -0
  74. package/dist/static/image/ppt.png +0 -0
  75. package/dist/static/image/rar.png +0 -0
  76. package/dist/static/image/sound.png +0 -0
  77. package/dist/static/image/txt.png +0 -0
  78. package/dist/static/image/xls.png +0 -0
  79. package/dist/static/image/zip.png +0 -0
  80. package/dist/styles.css +869 -0
  81. package/package.json +66 -0
@@ -0,0 +1,127 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import docs from "../../assets/images/docs.js";
3
+ import pdf from "../../assets/images/pdf.js";
4
+ import ppt from "../../assets/images/ppt.js";
5
+ import rar from "../../assets/images/rar.js";
6
+ import txt from "../../assets/images/txt.js";
7
+ import xls from "../../assets/images/xls.js";
8
+ import zip from "../../assets/images/zip.js";
9
+ import { BlockStack, Box, Button, InlineStack, SoppiyaIcon, Text } from "@soppiya/elementus";
10
+ import { formatToBytes } from "./format.js";
11
+ const MediaPreview_MediaPreview = ({ media, onClose })=>{
12
+ const getFileImg = ()=>{
13
+ if (media?.mimetype?.includes("pdf")) return pdf;
14
+ if (media?.mimetype?.includes("vnd.openxmlformats-officedocument.spreadsheetml.sheet") || media?.mimetype?.includes("vnd.ms-excel")) return xls;
15
+ if (media?.mimetype?.includes("x-zip-compressed")) return zip;
16
+ if (media?.mimetype?.includes("x-compressed")) return rar;
17
+ if (media?.mimetype?.includes("text/plain") || media?.mimetype?.includes("rtf")) return txt;
18
+ else if (media?.mimetype?.includes("vnd.openxmlformats-officedocument.presentationml.presentation") || media?.mimetype?.includes("vnd.ms-powerpoint")) return ppt;
19
+ else if (media?.mimetype?.includes("vnd.openxmlformats-officedocument.wordprocessingml.document") || media?.mimetype?.includes("msword")) return docs;
20
+ };
21
+ let mediaSrc = null;
22
+ switch(media?.type){
23
+ case "image":
24
+ mediaSrc = /*#__PURE__*/ jsx(Box, {
25
+ className: "h-full",
26
+ children: /*#__PURE__*/ jsx("img", {
27
+ src: String(media?.url),
28
+ className: "object-contain !h-full"
29
+ })
30
+ });
31
+ break;
32
+ case "audio":
33
+ mediaSrc = /*#__PURE__*/ jsx(Box, {
34
+ className: "w-full",
35
+ children: /*#__PURE__*/ jsx("audio", {
36
+ controls: true,
37
+ src: String(media?.url),
38
+ className: "w-full"
39
+ })
40
+ });
41
+ break;
42
+ case "video":
43
+ mediaSrc = /*#__PURE__*/ jsx(Box, {
44
+ className: "w-full",
45
+ children: /*#__PURE__*/ jsx("video", {
46
+ controls: true,
47
+ src: String(media?.url),
48
+ className: "object-contain max-h-[300px] w-full mx-auto"
49
+ })
50
+ });
51
+ break;
52
+ case "file":
53
+ mediaSrc = /*#__PURE__*/ jsx(Box, {
54
+ className: "w-full flex justify-center",
55
+ children: /*#__PURE__*/ jsx("img", {
56
+ src: getFileImg(),
57
+ alt: "file icon",
58
+ className: "w-[100px] h-[100px] object-contain"
59
+ })
60
+ });
61
+ break;
62
+ default:
63
+ /*#__PURE__*/ String(media?.url);
64
+ }
65
+ return /*#__PURE__*/ jsxs(BlockStack, {
66
+ padding: {
67
+ px: 80,
68
+ py: 60
69
+ },
70
+ gapY: 60,
71
+ justifyContent: "space-between",
72
+ className: "!bg-[#f7f7f7] h-[calc(100%-80px)] z-30 top-[80px] md:top-0 md:h-auto visible left-0 !absolute md:!relative !w-full md:!w-[273px] lg:!w-[336px]",
73
+ children: [
74
+ /*#__PURE__*/ jsxs(InlineStack, {
75
+ alignItems: "center",
76
+ justifyContent: "space-between",
77
+ children: [
78
+ /*#__PURE__*/ jsx(Box, {
79
+ children: /*#__PURE__*/ jsx(Text, {
80
+ size: "md",
81
+ weight: "semibold",
82
+ children: "Preview"
83
+ })
84
+ }),
85
+ /*#__PURE__*/ jsx(Box, {
86
+ children: /*#__PURE__*/ jsx(Button, {
87
+ variant: "plain",
88
+ onClick: ()=>onClose(),
89
+ children: /*#__PURE__*/ jsx(SoppiyaIcon, {
90
+ icon: "cross.svg",
91
+ size: "sm"
92
+ })
93
+ })
94
+ })
95
+ ]
96
+ }),
97
+ /*#__PURE__*/ jsx(InlineStack, {
98
+ alignItems: "center",
99
+ justifyContent: "center",
100
+ gapX: 80,
101
+ className: "h-[calc(100%-80px)]",
102
+ children: mediaSrc
103
+ }),
104
+ /*#__PURE__*/ jsxs(BlockStack, {
105
+ children: [
106
+ /*#__PURE__*/ jsxs(Text, {
107
+ size: "sm",
108
+ weight: "medium",
109
+ color: "info",
110
+ children: [
111
+ "\u2022",
112
+ formatToBytes(Number(media?.size), 2)
113
+ ]
114
+ }),
115
+ /*#__PURE__*/ jsx(Text, {
116
+ size: "sm",
117
+ weight: "medium",
118
+ color: "secondary",
119
+ children: media?.file_name
120
+ })
121
+ ]
122
+ })
123
+ ]
124
+ });
125
+ };
126
+ const MediaPreview = MediaPreview_MediaPreview;
127
+ export { MediaPreview as default };
@@ -0,0 +1,8 @@
1
+ import { InputMaybe, MediaSortKeys } from "../../shared/graphql/graphql";
2
+ import { MediaSort } from "./types";
3
+ type MediaSortingProps = {
4
+ sort: MediaSort;
5
+ onChange: (sortKey: InputMaybe<MediaSortKeys>, reverse: boolean) => void;
6
+ };
7
+ declare const MediaSorting: ({ sort, onChange }: MediaSortingProps) => import("react/jsx-runtime").JSX.Element;
8
+ export default MediaSorting;
@@ -0,0 +1,85 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { MediaSortKeys } from "../../shared/graphql/graphql.js";
3
+ import { Box, Button, Card, Listbox, Radio, SoppiyaIcon } from "@soppiya/elementus";
4
+ import { useClickAway } from "@uidotdev/usehooks";
5
+ import { useState } from "react";
6
+ const MediaSorting = ({ sort, onChange })=>{
7
+ const [open, setOpen] = useState(false);
8
+ const ref = useClickAway(()=>setOpen(false));
9
+ const toggleOpen = ()=>{
10
+ setOpen(!open);
11
+ };
12
+ return /*#__PURE__*/ jsxs(Box, {
13
+ ref: ref,
14
+ className: "relative",
15
+ children: [
16
+ /*#__PURE__*/ jsx(Button, {
17
+ variant: "outline",
18
+ color: "secondary",
19
+ className: "!px-[8px]",
20
+ onClick: toggleOpen,
21
+ children: /*#__PURE__*/ jsx(SoppiyaIcon, {
22
+ size: "sm",
23
+ icon: "filter-01.svg"
24
+ })
25
+ }),
26
+ open && /*#__PURE__*/ jsx(Card, {
27
+ className: "absolute !w-[150px] z-1 right-0 top-9 overflow-hidden",
28
+ children: /*#__PURE__*/ jsxs(Listbox, {
29
+ children: [
30
+ /*#__PURE__*/ jsx(Listbox.Option, {
31
+ children: /*#__PURE__*/ jsx(Radio, {
32
+ label: "Date (new - old)",
33
+ labelPosition: "center",
34
+ checked: sort.sortKey === MediaSortKeys.createdAt && sort.reverse,
35
+ onChange: ()=>onChange(MediaSortKeys.createdAt, true)
36
+ })
37
+ }),
38
+ /*#__PURE__*/ jsx(Listbox.Option, {
39
+ children: /*#__PURE__*/ jsx(Radio, {
40
+ label: "Date (old - new)",
41
+ labelPosition: "center",
42
+ checked: sort.sortKey === MediaSortKeys.createdAt && !sort.reverse,
43
+ onChange: ()=>onChange(MediaSortKeys.createdAt, false)
44
+ })
45
+ }),
46
+ /*#__PURE__*/ jsx(Listbox.Option, {
47
+ children: /*#__PURE__*/ jsx(Radio, {
48
+ label: "File name (A - Z)",
49
+ labelPosition: "center",
50
+ checked: sort.sortKey === MediaSortKeys.file_name && !sort.reverse,
51
+ onChange: ()=>onChange(MediaSortKeys.file_name, false)
52
+ })
53
+ }),
54
+ /*#__PURE__*/ jsx(Listbox.Option, {
55
+ children: /*#__PURE__*/ jsx(Radio, {
56
+ label: "File name (Z - A)",
57
+ labelPosition: "center",
58
+ checked: sort.sortKey === MediaSortKeys.file_name && sort.reverse,
59
+ onChange: ()=>onChange(MediaSortKeys.file_name, true)
60
+ })
61
+ }),
62
+ /*#__PURE__*/ jsx(Listbox.Option, {
63
+ children: /*#__PURE__*/ jsx(Radio, {
64
+ label: "Type (A - Z)",
65
+ labelPosition: "center",
66
+ checked: sort.sortKey === MediaSortKeys.type && !sort.reverse,
67
+ onChange: ()=>onChange(MediaSortKeys.type, false)
68
+ })
69
+ }),
70
+ /*#__PURE__*/ jsx(Listbox.Option, {
71
+ children: /*#__PURE__*/ jsx(Radio, {
72
+ label: "Type (Z - A)",
73
+ labelPosition: "center",
74
+ checked: sort.sortKey === MediaSortKeys.type && sort.reverse,
75
+ onChange: ()=>onChange(MediaSortKeys.type, true)
76
+ })
77
+ })
78
+ ]
79
+ })
80
+ })
81
+ ]
82
+ });
83
+ };
84
+ const media_MediaSorting = MediaSorting;
85
+ export { media_MediaSorting as default };
@@ -0,0 +1 @@
1
+ export declare const formatToBytes: (bytes: number, decimals?: number) => string;
@@ -0,0 +1,28 @@
1
+ const formatToBytes = (bytes, decimals = 2)=>{
2
+ if (!bytes) return "0 Bytes";
3
+ const k = 1024;
4
+ const dm = decimals < 0 ? 0 : decimals;
5
+ const sizes = [
6
+ "Bytes",
7
+ "KB",
8
+ "MB",
9
+ "GB",
10
+ "TB",
11
+ "PB",
12
+ "EB",
13
+ "ZB",
14
+ "YB"
15
+ ];
16
+ const thresholdGB = 500 * Math.pow(k, 2);
17
+ let i;
18
+ let value;
19
+ if (bytes >= thresholdGB) {
20
+ i = 3;
21
+ value = bytes / Math.pow(k, 3);
22
+ } else {
23
+ i = Math.floor(Math.log(bytes) / Math.log(k));
24
+ value = bytes / Math.pow(k, i);
25
+ }
26
+ return `${parseFloat(value.toFixed(dm))} ${sizes[i]}`;
27
+ };
28
+ export { formatToBytes };
@@ -0,0 +1,22 @@
1
+ export declare const mediasQuery: import("@graphql-typed-document-node/core").TypedDocumentNode<import("../../shared/graphql/graphql").MediasQuery, import("../../shared/graphql/graphql").Exact<{
2
+ after?: import("../../shared/graphql/graphql").InputMaybe<import("../../shared/graphql/graphql").Scalars["ID"]["input"]>;
3
+ before?: import("../../shared/graphql/graphql").InputMaybe<import("../../shared/graphql/graphql").Scalars["ID"]["input"]>;
4
+ first?: import("../../shared/graphql/graphql").InputMaybe<import("../../shared/graphql/graphql").Scalars["Int"]["input"]>;
5
+ last?: import("../../shared/graphql/graphql").InputMaybe<import("../../shared/graphql/graphql").Scalars["Int"]["input"]>;
6
+ query?: import("../../shared/graphql/graphql").InputMaybe<import("../../shared/graphql/graphql").Scalars["String"]["input"]>;
7
+ reverse?: import("../../shared/graphql/graphql").InputMaybe<import("../../shared/graphql/graphql").Scalars["Boolean"]["input"]>;
8
+ sortKey?: import("../../shared/graphql/graphql").InputMaybe<import("../../shared/graphql/graphql").MediaSortKeys>;
9
+ filterKeys?: import("../../shared/graphql/graphql").InputMaybe<import("../../shared/graphql/graphql").MediaFilterKeys>;
10
+ }>>;
11
+ export declare const storagePlanQuery: import("@graphql-typed-document-node/core").TypedDocumentNode<import("../../shared/graphql/graphql").StoragePlanQuery, import("../../shared/graphql/graphql").Exact<{
12
+ [key: string]: never;
13
+ }>>;
14
+ export declare const mediaUsagesQuery: import("@graphql-typed-document-node/core").TypedDocumentNode<import("../../shared/graphql/graphql").MediaUsageQuery, import("../../shared/graphql/graphql").Exact<{
15
+ [key: string]: never;
16
+ }>>;
17
+ export declare const addMediasMutation: import("@graphql-typed-document-node/core").TypedDocumentNode<import("../../shared/graphql/graphql").AddMediasMutation, import("../../shared/graphql/graphql").Exact<{
18
+ input: Array<import("../../shared/graphql/graphql").Scalars["Upload"]["input"]> | import("../../shared/graphql/graphql").Scalars["Upload"]["input"];
19
+ }>>;
20
+ export declare const deleteMediasMutation: import("@graphql-typed-document-node/core").TypedDocumentNode<import("../../shared/graphql/graphql").DeleteMediasMutation, import("../../shared/graphql/graphql").Exact<{
21
+ cursors: Array<import("../../shared/graphql/graphql").Scalars["ID"]["input"]> | import("../../shared/graphql/graphql").Scalars["ID"]["input"];
22
+ }>>;
@@ -0,0 +1,75 @@
1
+ import { graphql } from "../../shared/graphql/index.js";
2
+ const mediasQuery = graphql(`
3
+ query Medias(
4
+ $after: ID
5
+ $before: ID
6
+ $first: Int
7
+ $last: Int
8
+ $query: String
9
+ $reverse: Boolean
10
+ $sortKey: MediaSortKeys
11
+ $filterKeys: MediaFilterKeys
12
+ ) {
13
+ medias(
14
+ after: $after
15
+ before: $before
16
+ first: $first
17
+ last: $last
18
+ query: $query
19
+ reverse: $reverse
20
+ sortKey: $sortKey
21
+ filterKeys: $filterKeys
22
+ ) {
23
+ edges {
24
+ node {
25
+ _id
26
+ file_name
27
+ url
28
+ size
29
+ type
30
+ mimetype
31
+ }
32
+ }
33
+ pageInfo {
34
+ endCursor
35
+ hasNextPage
36
+ hasPreviousPage
37
+ startCursor
38
+ }
39
+ }
40
+ }
41
+ `);
42
+ const storagePlanQuery = graphql(`
43
+ query StoragePlan {
44
+ plan {
45
+ storage
46
+ package {
47
+ _id
48
+ storage
49
+ }
50
+ }
51
+ }
52
+ `);
53
+ const mediaUsagesQuery = graphql(`
54
+ query MediaUsage {
55
+ mediaUsage
56
+ }
57
+ `);
58
+ const addMediasMutation = graphql(`
59
+ mutation AddMedias($input: [Upload!]!) {
60
+ addMedias(input: $input) {
61
+ _id
62
+ file_name
63
+ url
64
+ size
65
+ }
66
+ }
67
+ `);
68
+ const deleteMediasMutation = graphql(`
69
+ mutation DeleteMedias($cursors: [ID!]!) {
70
+ deleteMedias(cursors: $cursors) {
71
+ message
72
+ }
73
+ }
74
+ `);
75
+ export { addMediasMutation, deleteMediasMutation, mediaUsagesQuery, mediasQuery, storagePlanQuery };
@@ -0,0 +1 @@
1
+ export { default as Media } from "./Media";
@@ -0,0 +1,2 @@
1
+ import Media from "./Media.js";
2
+ export { Media };
@@ -0,0 +1,13 @@
1
+ import { InputMaybe, MediaSortKeys } from "../../shared/graphql/graphql";
2
+ export declare enum View {
3
+ List = "LIST",
4
+ Grid = "GRID"
5
+ }
6
+ export type UploadFile = {
7
+ url: string;
8
+ file: File;
9
+ };
10
+ export type MediaSort = {
11
+ sortKey: InputMaybe<MediaSortKeys>;
12
+ reverse: boolean;
13
+ };
@@ -0,0 +1,6 @@
1
+ var types_View = /*#__PURE__*/ function(View) {
2
+ View["List"] = "LIST";
3
+ View["Grid"] = "GRID";
4
+ return View;
5
+ }({});
6
+ export { types_View as View };
@@ -0,0 +1,7 @@
1
+ import { useMutation } from "@apollo/client/react";
2
+ export declare const useUploadMedias: () => {
3
+ uploadMedias: useMutation.MutationFunction<import("../../shared/graphql/graphql").AddMediasMutation, {
4
+ input: Array<import("../../shared/graphql/graphql").Scalars["Upload"]["input"]> | import("../../shared/graphql/graphql").Scalars["Upload"]["input"];
5
+ }, import("@apollo/client").ApolloCache>;
6
+ isUploadingMedias: boolean;
7
+ };
@@ -0,0 +1,31 @@
1
+ import { useMutation } from "@apollo/client/react";
2
+ import { addMediasMutation } from "./graph.js";
3
+ const useUploadMedias = ()=>{
4
+ const [uploadMedias, { loading: isUploadingMedias }] = useMutation(addMediasMutation, {
5
+ update (cache, { data }) {
6
+ cache.modify({
7
+ fields: {
8
+ medias (existing) {
9
+ const newEdges = data?.addMedias?.map((media)=>({
10
+ __typename: "MediaEdge",
11
+ node: media,
12
+ cursor: media?._id
13
+ }));
14
+ return {
15
+ ...existing,
16
+ edges: [
17
+ ...newEdges ?? [],
18
+ ...existing.edges
19
+ ]
20
+ };
21
+ }
22
+ }
23
+ });
24
+ }
25
+ });
26
+ return {
27
+ uploadMedias,
28
+ isUploadingMedias
29
+ };
30
+ };
31
+ export { useUploadMedias };
@@ -0,0 +1,7 @@
1
+ import { useMutation } from "@apollo/client/react";
2
+ export declare const useDeleteMedias: () => {
3
+ deleteMedias: useMutation.MutationFunction<import("../../shared/graphql/graphql").DeleteMediasMutation, {
4
+ cursors: Array<import("../../shared/graphql/graphql").Scalars["ID"]["input"]> | import("../../shared/graphql/graphql").Scalars["ID"]["input"];
5
+ }, import("@apollo/client").ApolloCache>;
6
+ isDeletingMedias: boolean;
7
+ };
@@ -0,0 +1,14 @@
1
+ import { useMutation } from "@apollo/client/react";
2
+ import { deleteMediasMutation } from "./graph.js";
3
+ const useDeleteMedias = ()=>{
4
+ const [deleteMedias, { loading: isDeletingMedias }] = useMutation(deleteMediasMutation, {
5
+ refetchQueries: [
6
+ "Medias"
7
+ ]
8
+ });
9
+ return {
10
+ deleteMedias,
11
+ isDeletingMedias
12
+ };
13
+ };
14
+ export { useDeleteMedias };
@@ -0,0 +1,11 @@
1
+ import { UploadFile } from "./types";
2
+ type UseDropProps = {
3
+ onComplete?: (files: UploadFile[]) => void;
4
+ };
5
+ export declare const useDrop: ({ onComplete }?: UseDropProps) => {
6
+ ref: import("react").RefObject<HTMLInputElement | null>;
7
+ onDrop: (event: React.DragEvent<HTMLDivElement>) => Promise<void>;
8
+ onDragOver: (event: React.DragEvent<HTMLDivElement>) => void;
9
+ onChangeFile: (event: React.ChangeEvent<HTMLInputElement>) => Promise<void>;
10
+ };
11
+ export {};
@@ -0,0 +1,41 @@
1
+ import { useRef } from "react";
2
+ const useDrop = ({ onComplete } = {})=>{
3
+ const ref = useRef(null);
4
+ const fileProcessing = (file)=>{
5
+ if (!file) return;
6
+ return new Promise((resolve, reject)=>{
7
+ const reader = new FileReader();
8
+ reader.onload = (event)=>{
9
+ const result = event.target?.result;
10
+ if ("string" == typeof result) resolve({
11
+ url: result,
12
+ file
13
+ });
14
+ else reject(new Error("FileReader result is not a string"));
15
+ };
16
+ reader.readAsDataURL(file);
17
+ });
18
+ };
19
+ const getProcessedFiles = async (files)=>Promise.all(files.map((file)=>fileProcessing(file)).filter((file)=>void 0 !== file));
20
+ const onDrop = async (event)=>{
21
+ event.preventDefault();
22
+ const files = Array.from(event.dataTransfer.files);
23
+ const results = await getProcessedFiles(files);
24
+ onComplete?.(results);
25
+ };
26
+ const onDragOver = (event)=>{
27
+ event.preventDefault();
28
+ };
29
+ const onChangeFile = async (event)=>{
30
+ const files = Array.from(event.target.files ?? []);
31
+ const results = await getProcessedFiles(files);
32
+ onComplete?.(results);
33
+ };
34
+ return {
35
+ ref,
36
+ onDrop,
37
+ onDragOver,
38
+ onChangeFile
39
+ };
40
+ };
41
+ export { useDrop };
@@ -0,0 +1,5 @@
1
+ export declare const useMediaFilter: () => {
2
+ query: string;
3
+ debounceQuery: string;
4
+ onChangeQuery: (value: string) => void;
5
+ };
@@ -0,0 +1,15 @@
1
+ import { useDebounce } from "@uidotdev/usehooks";
2
+ import { useState } from "react";
3
+ const useMediaFilter = ()=>{
4
+ const [query, setQuery] = useState("");
5
+ const debounceQuery = useDebounce(query, 300);
6
+ const onChangeQuery = (value)=>{
7
+ setQuery(value);
8
+ };
9
+ return {
10
+ query,
11
+ debounceQuery,
12
+ onChangeQuery
13
+ };
14
+ };
15
+ export { useMediaFilter };
@@ -0,0 +1,6 @@
1
+ import { InputMaybe, MediaSortKeys } from "../../shared/graphql/graphql";
2
+ import { MediaSort } from "./types";
3
+ export declare const useMediaSorting: () => {
4
+ sorting: MediaSort;
5
+ onChangeSorting: (sortKey: InputMaybe<MediaSortKeys>, reverse: boolean) => void;
6
+ };
@@ -0,0 +1,19 @@
1
+ import { MediaSortKeys } from "../../shared/graphql/graphql.js";
2
+ import { useState } from "react";
3
+ const useMediaSorting = ()=>{
4
+ const [sorting, setSorting] = useState({
5
+ sortKey: MediaSortKeys.createdAt,
6
+ reverse: true
7
+ });
8
+ const onChangeSorting = (sortKey, reverse)=>{
9
+ setSorting({
10
+ sortKey,
11
+ reverse
12
+ });
13
+ };
14
+ return {
15
+ sorting,
16
+ onChangeSorting
17
+ };
18
+ };
19
+ export { useMediaSorting };
@@ -0,0 +1,31 @@
1
+ import { InputMaybe, MediaFilterKeys, MediaSortKeys } from "../../shared/graphql/graphql";
2
+ type UseMediasProps = {
3
+ count?: number;
4
+ query?: string;
5
+ reverse?: boolean;
6
+ sortKey?: InputMaybe<MediaSortKeys>;
7
+ filterKeys?: InputMaybe<MediaFilterKeys>;
8
+ };
9
+ export declare const useMedias: ({ count, query, reverse, sortKey, filterKeys }?: UseMediasProps) => {
10
+ medias: ({
11
+ __typename: "Media";
12
+ _id?: string | null;
13
+ file_name?: string | null;
14
+ url?: string | null;
15
+ size?: string | null;
16
+ type?: import("../../shared/graphql/graphql").MediaType | null;
17
+ mimetype?: string | null;
18
+ } | null | undefined)[];
19
+ pageInfo: {
20
+ __typename: "PageInfo";
21
+ endCursor?: string | null;
22
+ hasNextPage?: boolean | null;
23
+ hasPreviousPage?: boolean | null;
24
+ startCursor?: string | null;
25
+ } | null | undefined;
26
+ isLoadingMedias: boolean;
27
+ isFetchingMore: boolean;
28
+ error: import("@apollo/client").ErrorLike | undefined;
29
+ fetchMoreMedias: () => void;
30
+ };
31
+ export {};
@@ -0,0 +1,58 @@
1
+ import { NetworkStatus } from "@apollo/client";
2
+ import { useQuery } from "@apollo/client/react";
3
+ import { useCallback, useRef } from "react";
4
+ import { mediasQuery } from "./graph.js";
5
+ const useMedias = ({ count = 20, query = "", reverse, sortKey, filterKeys } = {})=>{
6
+ const arrayRef = useRef([]);
7
+ const { data, loading: isLoadingMedias, error, networkStatus, fetchMore } = useQuery(mediasQuery, {
8
+ notifyOnNetworkStatusChange: true,
9
+ variables: {
10
+ first: count,
11
+ query,
12
+ reverse,
13
+ sortKey,
14
+ filterKeys
15
+ }
16
+ });
17
+ const medias = data?.medias?.edges?.map((edge)=>edge?.node) ?? arrayRef.current;
18
+ const isFetchingMore = networkStatus === NetworkStatus.fetchMore;
19
+ const pageInfo = data?.medias?.pageInfo;
20
+ const fetchMoreMedias = useCallback(()=>{
21
+ if (!pageInfo?.hasNextPage) return;
22
+ fetchMore({
23
+ variables: {
24
+ query,
25
+ reverse,
26
+ sortKey,
27
+ filterKeys,
28
+ first: count,
29
+ after: pageInfo.endCursor
30
+ },
31
+ updateQuery (prev, { fetchMoreResult }) {
32
+ if (!fetchMoreResult.medias?.edges || !prev.medias?.edges) return prev;
33
+ return {
34
+ medias: {
35
+ ...fetchMoreResult.medias,
36
+ edges: [
37
+ ...prev.medias.edges,
38
+ ...fetchMoreResult.medias.edges
39
+ ]
40
+ }
41
+ };
42
+ }
43
+ });
44
+ }, [
45
+ fetchMore,
46
+ pageInfo,
47
+ count
48
+ ]);
49
+ return {
50
+ medias,
51
+ pageInfo,
52
+ isLoadingMedias,
53
+ isFetchingMore,
54
+ error,
55
+ fetchMoreMedias
56
+ };
57
+ };
58
+ export { useMedias };
@@ -0,0 +1,8 @@
1
+ export declare const useStorage: () => {
2
+ mediaUsage: number;
3
+ totalStorage: number;
4
+ usageStorage: number;
5
+ refetchMediaUsage: (variables?: Partial<import("../../shared/graphql/graphql").Exact<{
6
+ [key: string]: never;
7
+ }>> | undefined) => Promise<import("@apollo/client").ApolloClient.QueryResult<import("../../shared/graphql/graphql").MediaUsageQuery>>;
8
+ };