Skip to content

Commit

Permalink
fix: tf layout and search
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency committed Dec 19, 2024
1 parent f9cda8c commit 3b4c899
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 65 deletions.
39 changes: 12 additions & 27 deletions components/factory/components/DenomList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import useIsMobile from '@/hooks/useIsMobile';
import TransferModal from '@/components/factory/modals/TransferModal';

type DenomListProps = {
denoms: ExtendedMetadataSDKType[]; // The list of denoms to display
isLoading: boolean; // Whether the denoms are still loading
refetchDenoms: () => void; // Function to refetch the denoms
refetchProposals?: () => void; // Function to refetch the proposals
address: string; // The address of the user
pageSize: number; // The number of denoms to display per page
isGroup?: boolean; // Whether the denoms are group tokens
admin: string; // The admin of the group tokens
denoms: ExtendedMetadataSDKType[];
isLoading: boolean;
refetchDenoms: () => void;
refetchProposals?: () => void;
address: string;
pageSize: number;
isGroup?: boolean;
admin: string;
searchTerm: string;
};

export default function DenomList({
Expand All @@ -32,8 +33,8 @@ export default function DenomList({
pageSize,
isGroup = false,
admin,
searchTerm = '',
}: Readonly<DenomListProps>) {
const [searchQuery, setSearchQuery] = useState('');
const [currentPage, setCurrentPage] = useState(1);
const [openUpdateDenomMetadataModal, setOpenUpdateDenomMetadataModal] = useState(false);
const [openTransferDenomModal, setOpenTransferDenomModal] = useState(false);
Expand All @@ -46,8 +47,8 @@ export default function DenomList({
>(null);

const filteredDenoms = useMemo(() => {
return denoms.filter(denom => denom?.display.toLowerCase().includes(searchQuery.toLowerCase()));
}, [denoms, searchQuery]);
return denoms.filter(denom => denom?.display.toLowerCase().includes(searchTerm.toLowerCase()));
}, [denoms, searchTerm]);

const totalPages = Math.ceil(filteredDenoms.length / pageSize);
const paginatedDenoms = filteredDenoms.slice(
Expand Down Expand Up @@ -187,22 +188,6 @@ export default function DenomList({
return (
<div className="w-full mx-auto rounded-[24px] h-full flex flex-col">
<div className="flex flex-col gap-4 mb-4">
{/*<div className="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">*/}
{/* <div className="flex flex-col sm:flex-row items-start sm:items-center gap-4 w-full md:w-auto">*/}
{/* {!isGroup && (*/}
{/* <div className="relative w-full sm:w-[224px]">*/}
{/* <input*/}
{/* type="text"*/}
{/* placeholder="Search for a token..."*/}
{/* className="input input-bordered w-full h-[40px] rounded-[12px] border-none bg-secondary text-secondary-content pl-10 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary"*/}
{/* value={searchQuery}*/}
{/* onChange={e => setSearchQuery(e.target.value)}*/}
{/* />*/}
{/* <SearchIcon className="h-6 w-6 absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400" />*/}
{/* </div>*/}
{/* )}*/}
{/* </div>*/}
{/*</div>*/}
<div className="overflow-auto">
<div className="max-w-8xl mx-auto">
<table className="table w-full border-separate border-spacing-y-3">
Expand Down
93 changes: 55 additions & 38 deletions pages/factory/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WalletNotConnected, FactoryIcon } from '@/components';
import { WalletNotConnected, FactoryIcon, SearchIcon } from '@/components';
import DenomList from '@/components/factory/components/DenomList';
import {
useTokenBalances,
Expand All @@ -9,7 +9,7 @@ import {

import { useChain } from '@cosmos-kit/react';
import Head from 'next/head';
import React, { useMemo } from 'react';
import React, { useMemo, useState } from 'react';
import { ExtendedMetadataSDKType } from '@/utils';
import env from '@/config/env';
import useIsMobile from '../../hooks/useIsMobile';
Expand Down Expand Up @@ -65,6 +65,7 @@ export default function Factory() {
}, [denoms, metadatas, balances, totalSupply]);

const isDataReady = combinedData.length > 0;
const [searchTerm, setSearchTerm] = useState('');

return (
<div className="min-h-screen relative py-4 px-2 mx-auto text-white ">
Expand Down Expand Up @@ -119,44 +120,60 @@ export default function Factory() {
icon={<FactoryIcon className="h-60 w-60 text-primary" />}
/>
) : (
<>
<div className="flex flex-col sm:flex-row items-start sm:items-center gap-4 w-full md:w-auto">
<h1
className="text-secondary-content"
style={{ fontSize: '20px', fontWeight: 700, lineHeight: '24px' }}
>
Tokens
</h1>
</div>

<div className="flex flex-col w-full mt-4">
{isLoading ? (
<DenomList
denoms={combinedData}
isLoading={isLoading}
refetchDenoms={refetchData}
pageSize={pageSize}
address={address ?? ''}
admin={address ?? ''}
/>
) : isError ? (
<div className="text-center my-auto text-error">
Error loading tokens. Please try again.
<div className="relative w-full h-full overflow-hidden scrollbar-hide">
<div className="h-full flex flex-col p-4">
<div className="flex flex-col md:flex-row justify-between items-start md:items-center mb-4 gap-4">
<div className="flex flex-col sm:flex-row items-start sm:items-center gap-4 w-full md:w-auto">
<h1
className="text-secondary-content"
style={{ fontSize: '20px', fontWeight: 700, lineHeight: '24px' }}
>
Tokens
</h1>
<div className="relative w-full sm:w-[224px]">
<input
type="text"
placeholder="Search for a token ..."
className="input input-bordered w-full h-[40px] rounded-[12px] border-none bg-secondary text-secondary-content pl-10 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary"
value={searchTerm}
onChange={e => setSearchTerm(e.target.value)}
/>
<SearchIcon className="h-6 w-6 absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400" />
</div>
</div>
) : !isDataReady ? (
<div className="text-center my-auto">No token data available.</div>
) : (
<DenomList
denoms={combinedData}
isLoading={isLoading}
refetchDenoms={refetchData}
pageSize={pageSize}
address={address ?? ''}
admin={address ?? ''}
/>
)}
</div>

<div className="flex flex-col w-full mt-4">
{isLoading ? (
<DenomList
denoms={combinedData}
isLoading={isLoading}
refetchDenoms={refetchData}
pageSize={pageSize}
address={address ?? ''}
admin={address ?? ''}
searchTerm={searchTerm}
/>
) : isError ? (
<div className="text-center my-auto text-error">
Error loading tokens. Please try again.
</div>
) : !isDataReady ? (
<div className="text-center my-auto">No token data available.</div>
) : (
<DenomList
denoms={combinedData}
isLoading={isLoading}
refetchDenoms={refetchData}
pageSize={pageSize}
address={address ?? ''}
admin={address ?? ''}
searchTerm={searchTerm}
/>
)}
</div>
</div>
</>
</div>
)}
</div>
</div>
Expand Down

0 comments on commit 3b4c899

Please sign in to comment.