From 3ac23c878c2e4a90b8fe937244c0ba227a744b51 Mon Sep 17 00:00:00 2001 From: Daniel Vigaru <22689627+danielvigaru@users.noreply.github.com> Date: Wed, 22 Jan 2025 21:52:21 +0200 Subject: [PATCH 1/4] fix: left margin for list items --- apps/mobile/app/dashboard/(tabs)/lists.tsx | 6 +++- apps/mobile/lib/utils.ts | 36 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/apps/mobile/app/dashboard/(tabs)/lists.tsx b/apps/mobile/app/dashboard/(tabs)/lists.tsx index 9cc49cd4..0dae3ea7 100644 --- a/apps/mobile/app/dashboard/(tabs)/lists.tsx +++ b/apps/mobile/app/dashboard/(tabs)/lists.tsx @@ -8,6 +8,7 @@ import CustomSafeAreaView from "@/components/ui/CustomSafeAreaView"; import FullPageSpinner from "@/components/ui/FullPageSpinner"; import PageTitle from "@/components/ui/PageTitle"; import { api } from "@/lib/trpc"; +import { condProps } from "@/lib/utils"; import { ChevronRight, Plus } from "lucide-react-native"; import { useBookmarkLists } from "@hoarder/shared-react/hooks/lists"; @@ -130,7 +131,10 @@ export default function Lists() { renderItem={(l) => ( 0, + props: { marginLeft: l.item.level * 20 }, + })} > {l.item.numChildren > 0 && ( ; +} +/** + * Merge props conditionally. + * + * @example + * ``` + * + * ``` + * results in: + * ``` + * + * ``` + * @example + * ``` + * + * ``` + * results in: + * ``` + * + * ``` + */ +export function condProps(...condProps: ConditionalProps[]) { + return condProps.reduce((acc, { condition, props }) => { + return condition ? { ...acc, ...props } : acc; + }, {}); +} From 2c80953f3c4e352e97fc5fce3f05107eb89f3b40 Mon Sep 17 00:00:00 2001 From: Daniel Vigaru <22689627+danielvigaru@users.noreply.github.com> Date: Thu, 23 Jan 2025 17:09:42 +0200 Subject: [PATCH 2/4] refactor: move type into func definition --- apps/mobile/lib/utils.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/mobile/lib/utils.ts b/apps/mobile/lib/utils.ts index 38e55ef8..ee4c4386 100644 --- a/apps/mobile/lib/utils.ts +++ b/apps/mobile/lib/utils.ts @@ -6,10 +6,6 @@ export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } -interface ConditionalProps { - condition: boolean; - props: Record; -} /** * Merge props conditionally. * @@ -36,7 +32,12 @@ interface ConditionalProps { * * ``` */ -export function condProps(...condProps: ConditionalProps[]) { +export function condProps( + ...condProps: { + condition: boolean; + props: Record; + }[] +) { return condProps.reduce((acc, { condition, props }) => { return condition ? { ...acc, ...props } : acc; }, {}); From 005aeb65e363c417949959662f4b0bb199ce3d70 Mon Sep 17 00:00:00 2001 From: Daniel Vigaru <22689627+danielvigaru@users.noreply.github.com> Date: Tue, 28 Jan 2025 21:36:38 +0200 Subject: [PATCH 3/4] fix: missing return type Co-authored-by: Joseph Chambers <5374985+imcodingideas@users.noreply.github.com> --- apps/mobile/lib/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/mobile/lib/utils.ts b/apps/mobile/lib/utils.ts index ee4c4386..b7178eec 100644 --- a/apps/mobile/lib/utils.ts +++ b/apps/mobile/lib/utils.ts @@ -37,7 +37,7 @@ export function condProps( condition: boolean; props: Record; }[] -) { +): Record { return condProps.reduce((acc, { condition, props }) => { return condition ? { ...acc, ...props } : acc; }, {}); From 6a3c4d50b1ab565bae5eec8acb98f805e5360186 Mon Sep 17 00:00:00 2001 From: Daniel Vigaru <22689627+danielvigaru@users.noreply.github.com> Date: Tue, 28 Jan 2025 21:51:19 +0200 Subject: [PATCH 4/4] style: remove trailing space --- apps/mobile/lib/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/mobile/lib/utils.ts b/apps/mobile/lib/utils.ts index b7178eec..bfb6c9ed 100644 --- a/apps/mobile/lib/utils.ts +++ b/apps/mobile/lib/utils.ts @@ -37,7 +37,7 @@ export function condProps( condition: boolean; props: Record; }[] -): Record { +): Record { return condProps.reduce((acc, { condition, props }) => { return condition ? { ...acc, ...props } : acc; }, {});