Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 11 additions & 35 deletions src/components/contacts/ContactList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { filterFunctions } from "components/contacts/FiltersPopover";
import usePagination from "hooks/usePagination";
import useContactSearch from "hooks/useContactSearch";
import { locationSearch } from "utils/location";
import {
ContactsFilterControls,
ContactsTypeToggle,
} from "components/contacts/ContactsTable";
import { ContactsFilterControls, ContactsTypeToggle } from "components/contacts/ContactsTable";
import { useVouchees } from "providers/VoucheesData";
import { useVouchers } from "providers/VouchersData";
import { DesktopContactsTable } from "components/contacts/ContactsTable/DesktopContactsTable";
Expand Down Expand Up @@ -61,10 +58,8 @@ const sortFns = {
[SortOrder.DESC]: (a, b) => b.locking.sub(a.locking),
},
[RECEIVING_COLUMNS.BORROWABLE.id]: {
[SortOrder.ASC]: (a, b) =>
a.vouch.sub(a.locking).sub(b.vouch.sub(b.locking)),
[SortOrder.DESC]: (a, b) =>
b.vouch.sub(b.locking).sub(a.vouch.sub(a.locking)),
[SortOrder.ASC]: (a, b) => a.vouch.sub(a.locking).sub(b.vouch.sub(b.locking)),
[SortOrder.DESC]: (a, b) => b.vouch.sub(b.locking).sub(a.vouch.sub(a.locking)),
},
};

Expand Down Expand Up @@ -92,16 +87,12 @@ export default function ContactList({ initialType }) {

const [filters, setFilters] = useState(() => {
const urlSearchParams = locationSearch();
return urlSearchParams.has("filters")
? urlSearchParams.get("filters").split(",")
: [];
return urlSearchParams.has("filters") ? urlSearchParams.get("filters").split(",") : [];
});

const setContact = (contact) => {
setContactIndex(
filteredAndSorted.findIndex((c) =>
compareAddresses(contact.address, c.address)
)
filteredAndSorted.findIndex((c) => compareAddresses(contact.address, c.address))
);
};

Expand Down Expand Up @@ -152,9 +143,7 @@ export default function ContactList({ initialType }) {
...vouchers
.filter(
(voucher) =>
!vouchees.find((vouchee) =>
compareAddresses(vouchee.address, voucher.address)
)
!vouchees.find((vouchee) => compareAddresses(vouchee.address, voucher.address))
)
.map(({ address }) => ({
address,
Expand All @@ -170,9 +159,7 @@ export default function ContactList({ initialType }) {
...vouchees
.filter(
(vouchee) =>
!vouchers.find((voucher) =>
compareAddresses(voucher.address, vouchee.address)
)
!vouchers.find((voucher) => compareAddresses(voucher.address, vouchee.address))
)
.map(({ address }) => ({
address,
Expand All @@ -191,9 +178,7 @@ export default function ContactList({ initialType }) {
const filteredAndSorted = useMemo(() => {
const filtered = filters
? searched.filter((item) =>
filters
.map((filter) => filterFunctions[filter](item))
.every((x) => x === true)
filters.map((filter) => filterFunctions[filter](item)).every((x) => x === true)
)
: searched;

Expand All @@ -210,24 +195,15 @@ export default function ContactList({ initialType }) {

setSort({
...sort,
order: !sort.order
? SortOrder.DESC
: sort.order === SortOrder.DESC
? SortOrder.ASC
: null,
order: !sort.order ? SortOrder.DESC : sort.order === SortOrder.DESC ? SortOrder.ASC : null,
});
};

const {
data: contactsPage,
maxPages,
activePage,
onChange,
} = usePagination(filteredAndSorted);
const { data: contactsPage, maxPages, activePage, onChange } = usePagination(filteredAndSorted);

return (
<Card className="ContactList" overflow="visible">
<Box className="ContactList__header" p="24px">
<Box className="ContactList__header" p="24px" align="center">
<ContactsTypeToggle
type={type}
setType={(t) => {
Expand Down
12 changes: 11 additions & 1 deletion src/components/contacts/ContactList.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
@import "@unioncredit/ui/src/variables";

@media screen and (max-width: $breakpoint-mobile) {
.ContactList {
.table-head {
color: $zinc700;
}

.SegmentedControl__item--slider {
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1), 0px 4px 8px rgba(0, 0, 0, 0.15), 0px 0px 1px 0.5px rgba(0, 0, 0, 0.1) !important;
}
}

@media screen and (max-width: $breakpoint-tablet) {
.ContactList {
&__header {
padding: 16px !important;
Expand Down
21 changes: 6 additions & 15 deletions src/components/contacts/ContactsTable/ContactsFilterControls.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import "./ContactsFilterControls.scss";

import { Box, Button, Input, SearchIcon, VouchIcon } from "@unioncredit/ui";
import { VOUCH_MODAL } from "components/modals/VouchModal";
import { useModals } from "providers/ModalManager";
import FiltersPopover from "components/contacts/FiltersPopover";
import { ContactsType } from "constants";
import useResponsive from "hooks/useResponsive";

export const ContactsFilterControls = ({
type,
filters,
setQuery,
setFilers,
}) => {
export const ContactsFilterControls = ({ type, filters, setQuery, setFilers }) => {
const { open } = useModals();
const { isMicro, isMobile } = useResponsive();

return (
<Box>
<Box fluid className="ContactsFilterControls" align="center">
<Input
maxw="285px"
className="ContactsFilterControls__search"
prefix={<SearchIcon width="15px" />}
placeholder={isMicro ? "Search" : isMobile ? "Address or ENS" : "Filter by address or ENS"}
onChange={(event) => {
Expand All @@ -29,13 +26,7 @@ export const ContactsFilterControls = ({
<FiltersPopover filters={filters} setFilters={setFilers} />
)}

<Button
fluid
ml="8px"
label="New vouch"
icon={VouchIcon}
onClick={() => open(VOUCH_MODAL)}
/>
<Button fluid ml="8px" label="New vouch" icon={VouchIcon} onClick={() => open(VOUCH_MODAL)} />
</Box>
);
};
18 changes: 18 additions & 0 deletions src/components/contacts/ContactsTable/ContactsFilterControls.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@import "@unioncredit/ui/src/variables";

.ContactsFilterControls {
&__search {
width: 285px;

@media screen and (max-width: 800px) and (min-width: $breakpoint-tablet) {
width: 250px;
}
@media screen and (max-width: $breakpoint-tablet) {
width: 100%;
}
}
.button {
padding-left: 16px;
padding-right: 16px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const ContactsTypeToggle = ({ type, setType, clearFilters }) => (
<Box fluid>
<SegmentedControl
value={type}
className="ContactList__toggle"
initialActive={type === ContactsType.VOUCHEES ? 0 : 1}
onChange={(tab) => {
setType(tab.id);
Expand Down