Skip to content

Commit 50b2465

Browse files
committed
Update contract-function.tsx
1 parent b31ab5a commit 50b2465

File tree

1 file changed

+63
-39
lines changed

1 file changed

+63
-39
lines changed

apps/dashboard/src/components/contract-functions/contract-function.tsx

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import { Input } from "@/components/ui/input";
34
import { useDashboardRouter } from "@/lib/DashboardRouter";
45
import { cn } from "@/lib/utils";
56
import {
@@ -331,43 +332,55 @@ export const ContractFunctionsPanel: React.FC<ContractFunctionsPanelProps> = ({
331332
? 1
332333
: 0;
333334

334-
const functionSection = (e: ExtensionFunctions) => (
335-
<Flex key={e.extension} flexDir="column" mb={6}>
336-
{e.extension ? (
337-
<>
338-
<Flex alignItems="center" alignContent="center" gap={2}>
339-
<Image
340-
src="/assets/dashboard/extension-check.svg"
341-
alt="Extension detected"
342-
objectFit="contain"
343-
mb="2px"
344-
/>
345-
<Heading as="label" size="label.md">
346-
{e.extension}
347-
</Heading>
348-
</Flex>
349-
<Divider my={2} />
350-
</>
351-
) : (
352-
<>
353-
<Flex alignItems="center" alignContent="center" gap={2}>
354-
<Heading as="label" size="label.md">
355-
Other Functions
356-
</Heading>
357-
</Flex>
358-
<Divider my={2} />
359-
</>
360-
)}
361-
{e.functions.map((fn) => (
362-
<FunctionsOrEventsListItem
363-
key={`${fn.name}_${fn.type}_${fn.inputs.length}`}
364-
fn={fn}
365-
selectedFunction={selectedFunction}
366-
setSelectedFunction={setSelectedFunction}
367-
/>
368-
))}
369-
</Flex>
370-
);
335+
const [keywordSearch, setKeywordSearch] = useState<string>("");
336+
const handleKeywordSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
337+
setKeywordSearch(e.target.value);
338+
};
339+
340+
const functionSection = (e: ExtensionFunctions) => {
341+
const filteredFunctions = keywordSearch
342+
? e.functions.filter((o) =>
343+
o.name.toLowerCase().includes(keywordSearch.toLowerCase()),
344+
)
345+
: e.functions;
346+
return (
347+
<Flex key={e.extension} flexDir="column" mb={6} m={4}>
348+
{e.extension ? (
349+
<>
350+
<Flex alignItems="center" alignContent="center" gap={2}>
351+
<Image
352+
src="/assets/dashboard/extension-check.svg"
353+
alt="Extension detected"
354+
objectFit="contain"
355+
mb="2px"
356+
/>
357+
<Heading as="label" size="label.md">
358+
{e.extension}
359+
</Heading>
360+
</Flex>
361+
<Divider my={2} />
362+
</>
363+
) : (
364+
<>
365+
<Flex alignItems="center" alignContent="center" gap={2}>
366+
<Heading as="label" size="label.md">
367+
Other Functions
368+
</Heading>
369+
</Flex>
370+
<Divider my={2} />
371+
</>
372+
)}
373+
{filteredFunctions.map((fn) => (
374+
<FunctionsOrEventsListItem
375+
key={`${fn.name}_${fn.type}_${fn.inputs.length}`}
376+
fn={fn}
377+
selectedFunction={selectedFunction}
378+
setSelectedFunction={setSelectedFunction}
379+
/>
380+
))}
381+
</Flex>
382+
);
383+
};
371384

372385
return (
373386
<SimpleGrid height="100%" columns={12} gap={5}>
@@ -389,6 +402,7 @@ export const ContractFunctionsPanel: React.FC<ContractFunctionsPanelProps> = ({
389402
position="relative"
390403
display="flex"
391404
flexDir="column"
405+
onChange={() => setKeywordSearch("")}
392406
>
393407
<TabList as={Flex}>
394408
{writeFunctions.length > 0 && (
@@ -408,12 +422,22 @@ export const ContractFunctionsPanel: React.FC<ContractFunctionsPanelProps> = ({
408422
</TabList>
409423
<TabPanels h="auto" overflow="auto">
410424
{writeFunctions.length > 0 && (
411-
<TabPanel>
425+
<TabPanel p="0">
426+
<Input
427+
placeholder="🔎 Search"
428+
className="sticky top-0 mb-3 rounded-none border-r-none border-l-none focus-visible:ring-0"
429+
onChange={handleKeywordSearch}
430+
/>
412431
{writeFunctions.map((e) => functionSection(e))}
413432
</TabPanel>
414433
)}
415434
{viewFunctions.length > 0 && (
416-
<TabPanel>
435+
<TabPanel p="0">
436+
<Input
437+
placeholder="🔎 Search"
438+
className="sticky top-0 mb-3 rounded-none border-r-none border-l-none focus-visible:ring-0"
439+
onChange={handleKeywordSearch}
440+
/>
417441
{viewFunctions.map((e) => functionSection(e))}
418442
</TabPanel>
419443
)}

0 commit comments

Comments
 (0)