Skip to content

Commit

Permalink
feat: added search functionality (#20)
Browse files Browse the repository at this point in the history
* fix: clean up code style and formatting across multiple files

* fix: add missing newline at end of package.json

* fix: standardize casing in schema types and structure definitions

* fix: improve casing consistency in schema types and structure definitions

* fix: added schema to folder

* refactor: reorganize schema imports and move definitions to appropriate directories

* fix: standardize schema names and remove duplicate files

* feat: add file search functionality to FTP component

* fix: remove duplicate state declaration and update dependencies in FTP component
  • Loading branch information
MishraShardendu22 authored Jan 27, 2025
1 parent 7b009f1 commit de07e3d
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions src/components/FTPComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
'use client';

import { useCallback, useEffect, useMemo, useState } from 'react';
Expand All @@ -23,33 +24,46 @@ import {

export default function FTPComponent() {
const [data, setData] = useState<unknown[]>([]);
const [isUploading, setIsUploading] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [isRenaming, setIsRenaming] = useState(false);
const [isUploading, setIsUploading] = useState(false);
const [allFiles, setAllFiles] = useState<unknown[]>([]);
const [updatedFilename, setUpdatedFilename] = useState('');
const [loc, setLoc] = useState<'images' | 'docs'>('images');
const [editingFilename, setEditingFilename] = useState<string | null>(null); // Track which file is being edited
const [editingFilename, setEditingFilename] = useState<string | null>(null);

const toast = useToast();

const fetchData = useCallback(async () => {
if (toast && loc) {
try {
setIsLoading(true);
const result = await GetFiles(loc);
setData(result);
} catch (err) {
console.error(`FTP Error: ${err}`);
toast.push({
status: 'error',
title: "Can't connect to FTP server",
description: 'Check logs',
});
} finally {
setIsLoading(false);
}
try {
setIsLoading(true);
const result = await GetFiles(loc);
setData(result);
setAllFiles(result);
} catch (err) {
console.log(`FTP Error: ${err}`);
toast.push({
status: 'error',
title: "Can't connect to FTP server",
description: 'Check logs',
});
} finally {
setIsLoading(false);
}
}, [loc, toast]);

const searchFile = (searchQuery: string) => {
if (!searchQuery.trim()) {
setData(allFiles);
return;
}
}, [toast, loc]);

const filteredFiles = allFiles.filter((file: any) =>
file.name.toLowerCase().includes(searchQuery.toLowerCase())
);

setData(filteredFiles);
};

// Fetch files on component mount
useEffect(() => {
Expand Down Expand Up @@ -197,7 +211,7 @@ export default function FTPComponent() {
{
header: 'Name',
accessorKey: 'name',
// eslint-disable-next-line @typescript-eslint/no-explicit-any

cell: ({ row }: any) => (
<div className="flex items-center gap-2">
{editingFilename === row.original.name ? (
Expand Down Expand Up @@ -229,7 +243,7 @@ export default function FTPComponent() {
header: 'Actions',
accessorKey: 'actions',
enableSorting: false,
// eslint-disable-next-line @typescript-eslint/no-explicit-any

cell: ({ row }: any) => (
<div className="flex gap-2">
<button
Expand Down Expand Up @@ -295,6 +309,12 @@ export default function FTPComponent() {
setLoc(value as 'images' | 'docs')
}
>
<Input
type="text"
placeholder="Search files..."
onChange={(e) => searchFile(e.target.value)}
className="w-full md:w-1/3 px-2 py-1 border rounded-md"
/>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Select location" />
</SelectTrigger>
Expand Down

0 comments on commit de07e3d

Please sign in to comment.