-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' of https://github.com/cellajs/cella into f…
…eature/development-secure-http2
- Loading branch information
Showing
32 changed files
with
247 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,32 @@ | ||
import { File, FileAudio, FileText, FileVideo } from 'lucide-react'; | ||
import type React from 'react'; | ||
import { useMemo } from 'react'; | ||
import FilePlaceholder from './file-placeholder'; | ||
import { useLocalFile } from './use-local-file'; | ||
|
||
interface AttachmentThumbProps { | ||
url: string; | ||
contentType: string; | ||
name: string; | ||
openDialog: () => void; | ||
} | ||
|
||
const AttachmentThumb: React.FC<AttachmentThumbProps> = ({ url: baseUrl, contentType, name, openDialog }) => { | ||
const AttachmentThumb: React.FC<AttachmentThumbProps> = ({ url: baseUrl, contentType, name }) => { | ||
const localUrl = useLocalFile(baseUrl, contentType); | ||
|
||
// Use either remote URL or local URL | ||
const url = useMemo(() => { | ||
return baseUrl.startsWith('http') ? `${baseUrl}?width=100&format=avif` : localUrl; | ||
if (baseUrl.startsWith('http')) return `${baseUrl}?width=100&format=avif`; | ||
if (baseUrl.startsWith('/static/')) return baseUrl; | ||
return localUrl; | ||
}, [baseUrl, localUrl]); | ||
|
||
const handleKeyDown = (e: React.KeyboardEvent) => { | ||
if (e.key === 'Enter') openDialog(); | ||
}; | ||
|
||
const renderIcon = (iconSize = 24) => { | ||
const renderIcon = () => { | ||
if (!url) return; | ||
if (contentType.includes('image')) | ||
return <img src={url} draggable="false" alt={name} className="h-8 w-8 bg-muted rounded-md object-cover" loading="lazy" decoding="async" />; | ||
if (contentType.includes('video')) return <FileVideo size={iconSize} />; | ||
if (contentType.includes('pdf')) return <FileText size={iconSize} />; | ||
if (contentType.includes('audio')) return <FileAudio size={iconSize} />; | ||
|
||
return <File size={iconSize} />; | ||
return <FilePlaceholder fileType={contentType} />; | ||
}; | ||
|
||
return ( | ||
<div className="cursor-pointer w-full flex justify-center" onClick={openDialog} onKeyDown={handleKeyDown} aria-label={`Preview ${name}`}> | ||
{renderIcon()} | ||
</div> | ||
); | ||
return renderIcon(); | ||
}; | ||
|
||
export default AttachmentThumb; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { File, FileAudio, FileImage, FileText, FileVideo } from 'lucide-react'; | ||
|
||
interface Props { | ||
fileType: string | undefined; | ||
iconSize?: number; | ||
strokeWidth?: number; | ||
className?: string; | ||
} | ||
|
||
const FilePlaceholder = ({ fileType, iconSize = 20, strokeWidth = 1.5, className }: Props) => { | ||
if (!fileType) return <File size={iconSize} />; | ||
if (fileType.includes('image')) return <FileImage size={iconSize} strokeWidth={strokeWidth} className={className} />; | ||
if (fileType.includes('video')) return <FileVideo size={iconSize} strokeWidth={strokeWidth} className={className} />; | ||
if (fileType.includes('pdf')) return <FileText size={iconSize} strokeWidth={strokeWidth} className={className} />; | ||
if (fileType.includes('audio')) return <FileAudio size={iconSize} strokeWidth={strokeWidth} className={className} />; | ||
return <File size={iconSize} />; | ||
}; | ||
|
||
export default FilePlaceholder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.