From d3bc47e5b16cbc7fbfb23e7e87717901982ab836 Mon Sep 17 00:00:00 2001 From: Yuho Date: Fri, 5 Jan 2024 13:12:48 +0800 Subject: [PATCH] update mobile ui --- components/CustomTable/CustomTable.tsx | 51 ++++++++++++-------- components/Header/stats/components.tsx | 3 +- screens/Dashboard/dashboardOverview.tsx | 12 +++-- screens/Dashboard/index.tsx | 37 ++++++++++---- screens/Dashboard/supplyBorrowListMobile.tsx | 45 +++++++++++++++-- 5 files changed, 109 insertions(+), 39 deletions(-) diff --git a/components/CustomTable/CustomTable.tsx b/components/CustomTable/CustomTable.tsx index 5a98d31e..21264932 100644 --- a/components/CustomTable/CustomTable.tsx +++ b/components/CustomTable/CustomTable.tsx @@ -1,5 +1,5 @@ import styled from "styled-components"; -import React, { useEffect } from "react"; +import React, { useEffect, useRef } from "react"; import { twMerge } from "tailwind-merge"; import CustomPagination from "./CustomPagination"; import CustomTableMobile from "./CustomTableMobile"; @@ -47,6 +47,7 @@ const CustomTable = ({ selectedRowIndex, }: Props) => { const isMobile = isMobileDevice(); + const headersRef = useRef([]); if (isMobile) { return ( @@ -116,29 +117,33 @@ const CustomTable = ({ } return { text, size: d.size }; }); + + const headersWidth = headersRef.current.map((d) => d.getBoundingClientRect().width); const headerNode = ( -
-
- {headers?.map((d, i) => { - const styles: { flex?: string } = {}; - if (d.size) { - styles.flex = `0 0 ${d.size}px`; - } - const keyId = typeof d.text === "string" ? d.text : i; - return ( -
- {d.text} -
- ); - })} -
+
+ {headers?.map((d, i) => { + const styles: { flex?: string } = {}; + if (d.size) { + styles.flex = `0 0 ${d.size}px`; + } + const keyId = typeof d.text === "string" ? d.text : i; + + const assignRef = (el) => { + headersRef.current[i] = el; + }; + return ( +
+ {d.text} +
+ ); + })}
); let bodyNodes; if (data?.length) { bodyNodes = data?.map((d, i) => { - const tdNode = columns?.map((col) => { + const tdNode = columns?.map((col, colIndex) => { let content = null; if (typeof col.cell === "function") { content = col.cell({ @@ -148,8 +153,12 @@ const CustomTable = ({ content = d[col.accessorKey]; } const styles: { flex?: string } = {}; - if (col.size) { - styles.flex = `0 0 ${col.size}px`; + const colSize = headersWidth[colIndex]; + // if (col.size) { + // styles.flex = `0 0 ${col.size}px`; + // } + if (colSize) { + styles.flex = `0 0 ${colSize}px`; } return (
@@ -238,7 +247,7 @@ const StyledTable = styled.div` .custom-table-th { text-align: left; - padding: 10px 5px; + padding: 10px 5px 10px 0; } } @@ -246,7 +255,7 @@ const StyledTable = styled.div` min-height: 85px; .custom-table-td { - padding: 15px 5px; + padding: 15px 5px 15px 0; justify-content: center; display: flex; flex-direction: column; diff --git a/components/Header/stats/components.tsx b/components/Header/stats/components.tsx index 3fab4fa3..e298001f 100644 --- a/components/Header/stats/components.tsx +++ b/components/Header/stats/components.tsx @@ -86,7 +86,8 @@ export const Stat = ({ onClick?: () => void; }) => { return ( -
onClick && onClick()} style={{ minHeight: 81 }} className="md:w-[351px]"> +
onClick && onClick()} style={{ minHeight: 81 }}> + {/*
onClick && onClick()} style={{ minHeight: 81 }} className="md:w-[351px]"> */}
{typeof title === "string" ?
{title}
: title} {titleTooltip && } diff --git a/screens/Dashboard/dashboardOverview.tsx b/screens/Dashboard/dashboardOverview.tsx index e0f94e6d..290604f1 100644 --- a/screens/Dashboard/dashboardOverview.tsx +++ b/screens/Dashboard/dashboardOverview.tsx @@ -114,6 +114,7 @@ const DashboardOverview = ({ suppliedRows, borrowedRows }) => { }); }; + const hasMultiHealths = userHealth?.allHealths?.length > 1 && userHealth?.hasBorrow; return ( <>
@@ -125,14 +126,15 @@ const DashboardOverview = ({ suppliedRows, borrowedRows }) => {
-
-
-
+
+ {/*
*/} +
+
-
+
{/* {
- {userHealth?.allHealths?.length > 1 && userHealth?.hasBorrow ? ( + {hasMultiHealths ? (
{userHealth.allHealths.map((value: any) => { const isActive = value.id === userHealthCur?.id; diff --git a/screens/Dashboard/index.tsx b/screens/Dashboard/index.tsx index 0197b12f..dbb00f2d 100644 --- a/screens/Dashboard/index.tsx +++ b/screens/Dashboard/index.tsx @@ -88,13 +88,13 @@ const StyledSupplyBorrow = styled.div` const yourSuppliedColumns = [ { header: "Assets", + size: 160, cell: ({ originalData }) => { const { metadata } = originalData || {}; const { icon, tokens, symbol } = metadata || {}; let iconImg; - let symbolNode = ""; + let symbolNode = symbol; if (icon) { - symbolNode = symbol; iconImg = ( token ); } else if (tokens?.length) { + symbolNode = ""; iconImg = ( -
+
{tokens?.map((d, i) => { const isLast = i === tokens.length - 1; symbolNode += `${d.metadata.symbol}${!isLast ? "-" : ""}`; @@ -129,7 +133,12 @@ const yourSuppliedColumns = [ return (
{iconImg} -
+
{symbolNode}
@@ -244,11 +253,11 @@ const YourSupplied = ({ suppliedRows, accountId, total }) => { const StyledCustomTable = styled(CustomTable)` .custom-table-tbody { - margin: -2px -30px 0; + margin-top: -2px; .custom-table-row { - padding-left: 30px; - padding-right: 30px; + //padding-left: 20px; + //padding-right: 20px; cursor: pointer; .custom-table-action { @@ -270,11 +279,21 @@ const StyledCustomTable = styled(CustomTable)` } } } + + .custom-table-thead, + .custom-table-tbody { + margin: 0 -30px; + } + .custom-table-header-row, + .custom-table-row { + padding: 0 20px; + } `; const yourBorrowedColumns = [ { header: "Assets", + size: 140, cell: ({ originalData }) => { return (
@@ -292,7 +311,7 @@ const yourBorrowedColumns = [ }, { header: "Collateral Type", - size: 140, + size: 130, cell: ({ originalData }) => { const { collateralType, metadataLP } = originalData || {}; let tokenNames = ""; diff --git a/screens/Dashboard/supplyBorrowListMobile.tsx b/screens/Dashboard/supplyBorrowListMobile.tsx index 997108e1..e1afec46 100644 --- a/screens/Dashboard/supplyBorrowListMobile.tsx +++ b/screens/Dashboard/supplyBorrowListMobile.tsx @@ -125,7 +125,35 @@ const StyledTabActiveBall = styled.div` `; const SupplyItem = ({ data }) => { - const { canUseAsCollateral } = data || {}; + const { canUseAsCollateral, metadata } = data || {}; + const { icon, tokens, symbol } = metadata || {}; + let iconImg; + let symbolNode = symbol; + if (icon) { + iconImg = token; + } else if (tokens?.length) { + symbolNode = ""; + iconImg = ( +
+ {tokens?.map((d, i) => { + const isLast = i === tokens.length - 1; + symbolNode += `${d.metadata.symbol}${!isLast ? "-" : ""}`; + return ( + token + ); + })} +
+ ); + } + return (
{ style={{ padding: "16px", borderColor: "#31344C" }} >
- token + {iconImg}
-
{data?.symbol}
+
{symbolNode}
{hiddenAssets.includes(data?.tokenId || "") ? null : ( { }; const BorrowItem = ({ data }) => { + const { metadataLP, collateralType } = data || {}; + let tokenNames = ""; + metadataLP?.tokens?.forEach((d, i) => { + const isLast = i === metadataLP.tokens.length - 1; + tokenNames += `${d.metadata.symbol}${!isLast ? "-" : ""}`; + }); return (
{ token
{data?.symbol}
+ {tokenNames && ( +
+ {tokenNames} +
+ )}