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

Cat UI change #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
192 changes: 96 additions & 96 deletions lib/comp/tx/TxCard.tsx
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
import Image from "next/image";
import type React from "react";

import { getCatStyle } from "@/util/cat";
import parseMoney from "@/util/parseMoney";
import { useTxStore } from "@/util/txStore";
import type { FullTxClientSide } from "@/util/types";

interface Props {
tx: FullTxClientSide;
setShowModal?: React.Dispatch<React.SetStateAction<boolean>>;
}
const TxCard = (props: Props) => {
const setTxOnModal = useTxStore((state) => state.setTxOnModal);

const splitAmount = parseMoney(
props.tx.catArray.reduce((total, cat) => total + cat.amount, 0),
);

return (
<section
className="flex h-fit w-full flex-col justify-between gap-x-4 gap-y-1 border border-zinc-400 px-3 py-2 text-start hover:cursor-pointer hover:bg-zinc-800 hover:text-zinc-200"
onKeyDown={() => {
if (!props.setShowModal) {
console.log("props.setShowModal not implemented");
return;
}
props.setShowModal(true);
setTxOnModal(props.tx);
}}
onClick={() => {
if (!props.setShowModal) {
console.log("props.setShowModal not implemented");
return;
}
props.setShowModal(true);
setTxOnModal(props.tx);
}}
>
<section className="flex w-full justify-between gap-x-3 truncate">
<div className="flex-start flex h-full justify-center gap-x-2 truncate">
<p className="truncate text-base font-semibold sm:text-lg">
{props.tx.name}
</p>
</div>

<div
className={`flex items-center gap-x-1 text-base sm:text-lg ${
props.tx.amount > 0 ? "" : "text-green-300"
}`}
>
{props.tx.splitArray.length > 1 && (
<span className="icon-[lucide--split] h-4 w-4 text-zinc-400" />
)}
<div>{splitAmount ? splitAmount * -1 : props.tx.amount * -1}</div>
<div>{props.tx.iso_currency_code}</div>
</div>
</section>

<section className="flex h-fit w-full justify-between gap-x-1">
<p className="text-xs text-zinc-400">{props.tx.datetime || "12:34"}</p>

<div
className="no-scrollbar flex gap-x-1 overflow-x-auto overscroll-none"
onWheel={(e) => {
e.currentTarget.scrollLeft += e.deltaY * 0.5;
}}
>
{props.tx.catArray.map((cat) => (
<div
key={cat.id}
className={`flex min-w-max gap-x-1 rounded-full p-2 text-zinc-800 ${
getCatStyle(cat.nameArray).bgColor
}`}
>
{props.tx.counterparties?.[0]?.logo_url ? (
<Image
className="rounded-full"
src={props.tx.counterparties[0].logo_url}
alt=""
width={16}
height={16}
/>
) : (
<span className={`${getCatStyle(cat.nameArray).icon} w-4`} />
)}
<p className="text-xs">{cat.nameArray.at(-1)}</p>
</div>
))}
</div>
</section>
</section>
);
};

export default TxCard;
import Image from "next/image";
import type React from "react";
import { getCatStyle } from "@/util/cat";
import parseMoney from "@/util/parseMoney";
import { useTxStore } from "@/util/txStore";
import type { FullTxClientSide } from "@/util/types";
interface Props {
tx: FullTxClientSide;
setShowModal?: React.Dispatch<React.SetStateAction<boolean>>;
}
const TxCard = (props: Props) => {
const setTxOnModal = useTxStore((state) => state.setTxOnModal);
const splitAmount = parseMoney(
props.tx.catArray.reduce((total, cat) => total + cat.amount, 0),
);
return (
<section
className="flex h-fit w-full flex-col justify-between gap-x-4 gap-y-1 border border-zinc-400 px-3 py-2 text-start hover:cursor-pointer hover:bg-zinc-800 hover:text-zinc-200"
onKeyDown={() => {
if (!props.setShowModal) {
console.log("props.setShowModal not implemented");
return;
}
props.setShowModal(true);
setTxOnModal(props.tx);
}}
onClick={() => {
if (!props.setShowModal) {
console.log("props.setShowModal not implemented");
return;
}
props.setShowModal(true);
setTxOnModal(props.tx);
}}
>
<section className="flex w-full justify-between gap-x-3 truncate">
<div className="flex-start flex h-full justify-center gap-x-2 truncate">
<p className="truncate text-base font-semibold sm:text-lg">
{props.tx.name}
</p>
</div>
<div
className={`flex items-center gap-x-1 text-base sm:text-lg ${
props.tx.amount > 0 ? "" : "text-green-300"
}`}
>
{props.tx.splitArray.length > 1 && (
<span className="icon-[lucide--split] h-4 w-4 text-zinc-400" />
)}
<div>{splitAmount ? splitAmount * -1 : props.tx.amount * -1}</div>
<div>{props.tx.iso_currency_code}</div>
</div>
</section>
<section className="flex h-fit w-full justify-between gap-x-1">
<p className="text-xs text-zinc-400">{props.tx.datetime || "12:34"}</p>
<div
className="no-scrollbar flex gap-x-1 overflow-x-auto overscroll-none"
onWheel={(e) => {
e.currentTarget.scrollLeft += e.deltaY * 0.5;
}}
>
{props.tx.catArray.map((cat) => (
<div
key={cat.id}
className={`flex min-w-max gap-x-1 rounded-full p-2 text-zinc-800 ${
getCatStyle(cat.nameArray).bgColor
}`}
>
{props.tx.counterparties?.[0]?.logo_url ? (
<Image
className="rounded-full"
src={props.tx.counterparties[0].logo_url}
alt=""
width={16}
height={16}
/>
) : (
<span className={`${getCatStyle(cat.nameArray).icon} w-4`} />
)}
<p className="text-xs">{cat.name}</p>
</div>
))}
</div>
</section>
</section>
);
};
export default TxCard;
Loading