1- import { ActionIcon , Group , Skeleton , Table } from "@mantine/core" ;
1+ import {
2+ ActionIcon ,
3+ Group ,
4+ Skeleton ,
5+ Stack ,
6+ Table ,
7+ TextInput ,
8+ } from "@mantine/core" ;
9+ import { useClipboard } from "@mantine/hooks" ;
10+ import { useModals } from "@mantine/modals" ;
211import mime from "mime-types" ;
12+
313import Link from "next/link" ;
4- import { TbDownload , TbEye } from "react-icons/tb" ;
14+ import { TbDownload , TbEye , TbLink } from "react-icons/tb" ;
15+ import useConfig from "../../hooks/config.hook" ;
516import shareService from "../../services/share.service" ;
617import { FileMetaData } from "../../types/File.type" ;
18+ import { Share } from "../../types/share.type" ;
719import { byteToHumanSizeString } from "../../utils/fileSize.util" ;
20+ import toast from "../../utils/toast.util" ;
821
922const FileList = ( {
1023 files,
11- shareId ,
24+ share ,
1225 isLoading,
1326} : {
1427 files ?: FileMetaData [ ] ;
15- shareId : string ;
28+ share : Share ;
1629 isLoading : boolean ;
1730} ) => {
31+ const clipboard = useClipboard ( ) ;
32+ const config = useConfig ( ) ;
33+ const modals = useModals ( ) ;
34+
35+ const copyFileLink = ( file : FileMetaData ) => {
36+ const link = `${ config . get ( "APP_URL" ) } /api/shares/${ share . id } /files/${
37+ file . id
38+ } `;
39+
40+ if ( window . isSecureContext ) {
41+ clipboard . copy ( link ) ;
42+ toast . success ( "Your file link was copied to the keyboard." ) ;
43+ } else {
44+ modals . openModal ( {
45+ title : "File link" ,
46+ children : (
47+ < Stack align = "stretch" >
48+ < TextInput variant = "filled" value = { link } />
49+ </ Stack >
50+ ) ,
51+ } ) ;
52+ }
53+ } ;
54+
1855 return (
1956 < Table >
2057 < thead >
@@ -36,7 +73,7 @@ const FileList = ({
3673 { shareService . doesFileSupportPreview ( file . name ) && (
3774 < ActionIcon
3875 component = { Link }
39- href = { `/share/${ shareId } /preview/${
76+ href = { `/share/${ share . id } /preview/${
4077 file . id
4178 } ?type=${ mime . contentType ( file . name ) } `}
4279 target = "_blank"
@@ -45,10 +82,15 @@ const FileList = ({
4582 < TbEye />
4683 </ ActionIcon >
4784 ) }
85+ { ! share . hasPassword && (
86+ < ActionIcon size = { 25 } onClick = { ( ) => copyFileLink ( file ) } >
87+ < TbLink />
88+ </ ActionIcon >
89+ ) }
4890 < ActionIcon
4991 size = { 25 }
5092 onClick = { async ( ) => {
51- await shareService . downloadFile ( shareId , file . id ) ;
93+ await shareService . downloadFile ( share . id , file . id ) ;
5294 } }
5395 >
5496 < TbDownload />
0 commit comments