Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trello 19 #31

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
23 changes: 23 additions & 0 deletions src/pages/tracked-contracts/TrackedChain.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';

interface TrackedChainProps {
name: string;
active: boolean;
onClick: () => void;
}

const TrackedChain: React.FC<TrackedChainProps> = ({ name, active, onClick }) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it here, in the same folder, I don't think it's gonna be used anywhere else so no need to put it inside components

return (
<div
className={`focus:outline-none py-4 capitalize cursor-pointer ${active ? 'font-bold text-primary' : ''}`}
role="button"
onClick={() => onClick()}
onKeyPress={() => onClick()}
tabIndex={0}
>
{name}
</div>
);
};

export default TrackedChain;
36 changes: 7 additions & 29 deletions src/pages/tracked-contracts/TrackedContractsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react';
import { Card, CardBody, CardHeader } from '../../components/common';
import SearchInput from '../../components/common/Input';
import mockDataChain from './mock-data';
import TrackedChain from './TrackedChain';

type ChainType = 'evm' | 'substrate';

Expand All @@ -28,38 +29,15 @@ const TrackedContractsList: React.FC<{}> = () => {
setChains(mockDataChain as Chain[]);
}, []);

// Filter out by the search but also keep the current active in the search
const allChains = chains
.filter((data) => {
if (!searchChain) {
return data;
}
if (data.name.includes(searchChain.trim().toLocaleLowerCase())) {
return data;
}
return null;
})
.map((chain) => {
return (
<div
className={`focus:outline-none py-4 capitalize cursor-pointer ${
chain.name === activeChain?.name ? 'font-bold text-primary' : ''
}`}
role="button"
onClick={() => setActiveChain(chain)}
onKeyPress={() => setActiveChain(chain)}
tabIndex={0}
>
{chain.name}
</div>
);
});
.filter((chain) => chain.name.includes(searchChain.trim().toLocaleLowerCase()) || activeChain?.name === chain.name)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just this filter works actually no need to check for if defined or null. Also added the fact that if a chan is already active you might still want to see it despite searching

.map((chain) => (
<TrackedChain active={chain.name === activeChain?.name} name={chain.name} onClick={() => setActiveChain(chain)} />
));

const activeContracts =
activeChain && activeChain.tracked_contracts.length
? activeChain.tracked_contracts.map((contract) => {
return contract;
})
: 'No Tracked Contracts';
activeChain && activeChain.tracked_contracts.length ? activeChain.tracked_contracts : 'No Tracked Contracts';

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also work

const activeContracts =
    activeChain && activeChain.tracked_contracts.length
      ? activeChain.tracked_contracts
      : 'No Tracked Contracts';

return (
<div className="container mx-auto">
Expand Down