Code cleanup for 1.7.0
This commit is contained in:
@@ -87,7 +87,7 @@ function FileManagerContent({ initialHost, onClose }: FileManagerProps) {
|
||||
initialHost || null,
|
||||
);
|
||||
const [currentPath, setCurrentPath] = useState(
|
||||
initialHost?.defaultPath || "/"
|
||||
initialHost?.defaultPath || "/",
|
||||
);
|
||||
const [files, setFiles] = useState<FileItem[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
@@ -184,7 +184,7 @@ function FileManagerContent({ initialHost, onClose }: FileManagerProps) {
|
||||
|
||||
const handleCloseWithError = useCallback(
|
||||
(errorMessage: string) => {
|
||||
if (isClosing) return; // Prevent duplicate calls
|
||||
if (isClosing) return;
|
||||
setIsClosing(true);
|
||||
toast.error(errorMessage);
|
||||
if (onClose) {
|
||||
@@ -758,10 +758,10 @@ function FileManagerContent({ initialHost, onClose }: FileManagerProps) {
|
||||
const windowCount = Date.now() % 10;
|
||||
const baseOffsetX = 120 + windowCount * 30;
|
||||
const baseOffsetY = 120 + windowCount * 30;
|
||||
|
||||
|
||||
const maxOffsetX = Math.max(0, window.innerWidth - 800 - 100);
|
||||
const maxOffsetY = Math.max(0, window.innerHeight - 600 - 100);
|
||||
|
||||
|
||||
const offsetX = Math.min(baseOffsetX, maxOffsetX);
|
||||
const offsetY = Math.min(baseOffsetY, maxOffsetY);
|
||||
|
||||
|
||||
@@ -355,11 +355,22 @@ export function FileViewer({
|
||||
setShowLargeFileWarning(false);
|
||||
}
|
||||
|
||||
if (fileTypeInfo.type === "image" && file.name.toLowerCase().endsWith('.svg') && content) {
|
||||
if (
|
||||
fileTypeInfo.type === "image" &&
|
||||
file.name.toLowerCase().endsWith(".svg") &&
|
||||
content
|
||||
) {
|
||||
setImageLoading(false);
|
||||
setImageLoadError(false);
|
||||
}
|
||||
}, [content, savedContent, fileTypeInfo.type, isLargeFile, forceShowAsText, file.name]);
|
||||
}, [
|
||||
content,
|
||||
savedContent,
|
||||
fileTypeInfo.type,
|
||||
isLargeFile,
|
||||
forceShowAsText,
|
||||
file.name,
|
||||
]);
|
||||
|
||||
const handleContentChange = (newContent: string) => {
|
||||
setEditedContent(newContent);
|
||||
@@ -706,8 +717,8 @@ export function FileViewer({
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
) : file.name.toLowerCase().endsWith('.svg') ? (
|
||||
<div
|
||||
) : file.name.toLowerCase().endsWith(".svg") ? (
|
||||
<div
|
||||
className="max-w-full max-h-full flex items-center justify-center"
|
||||
style={{ maxHeight: "calc(100vh - 200px)" }}
|
||||
dangerouslySetInnerHTML={{ __html: content }}
|
||||
|
||||
@@ -9,15 +9,15 @@ interface DragAndDropState {
|
||||
interface UseDragAndDropProps {
|
||||
onFilesDropped: (files: FileList) => void;
|
||||
onError?: (error: string) => void;
|
||||
maxFileSize?: number; // in MB
|
||||
maxFileSize?: number;
|
||||
allowedTypes?: string[];
|
||||
}
|
||||
|
||||
export function useDragAndDrop({
|
||||
onFilesDropped,
|
||||
onError,
|
||||
maxFileSize = 5120, // 5GB default - much more reasonable
|
||||
allowedTypes = [], // empty means all types allowed
|
||||
maxFileSize = 5120,
|
||||
allowedTypes = [],
|
||||
}: UseDragAndDropProps) {
|
||||
const [state, setState] = useState<DragAndDropState>({
|
||||
isDragging: false,
|
||||
@@ -32,28 +32,23 @@ export function useDragAndDrop({
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = files[i];
|
||||
|
||||
// Check file size
|
||||
if (file.size > maxSizeBytes) {
|
||||
return `File "${file.name}" is too large. Maximum size is ${maxFileSize}MB.`;
|
||||
}
|
||||
|
||||
// Check file type if restrictions exist
|
||||
if (allowedTypes.length > 0) {
|
||||
const fileExt = file.name.split(".").pop()?.toLowerCase();
|
||||
const mimeType = file.type.toLowerCase();
|
||||
|
||||
const isAllowed = allowedTypes.some((type) => {
|
||||
// Check by extension
|
||||
if (type.startsWith(".")) {
|
||||
return fileExt === type.slice(1);
|
||||
}
|
||||
// Check by MIME type
|
||||
if (type.includes("/")) {
|
||||
return (
|
||||
mimeType === type || mimeType.startsWith(type.replace("*", ""))
|
||||
);
|
||||
}
|
||||
// Check by category
|
||||
switch (type) {
|
||||
case "image":
|
||||
return mimeType.startsWith("image/");
|
||||
@@ -114,7 +109,6 @@ export function useDragAndDrop({
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
// Set dropEffect to indicate what operation is allowed
|
||||
e.dataTransfer.dropEffect = "copy";
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user