From 0499cc5a681bd9ce87bb847c62234f48a59cbb42 Mon Sep 17 00:00:00 2001
From: Austin Chen
Date: Thu, 18 Aug 2022 09:26:18 -0700
Subject: [PATCH] Sort the contracts in the correct masonry order
---
web/components/contract/contracts-grid.tsx | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/web/components/contract/contracts-grid.tsx b/web/components/contract/contracts-grid.tsx
index 915facd9..cd7746ce 100644
--- a/web/components/contract/contracts-grid.tsx
+++ b/web/components/contract/contracts-grid.tsx
@@ -61,16 +61,30 @@ export function ContractsGrid(props: {
)
}
+ // Reorganize the contracts so that the masonry layout shows them in the original order
+ // E.g. from [0, 1, 2, 3] => [0, 2, 1, 3]
+ // E.g. from [0, 1, 2, 3, 4, 5, 6] => [0, 2, 4, 1, 3, 5, 6]
+ const halfway = Math.floor(contracts.length / 2)
+ function reorder(i: number) {
+ return i < halfway
+ ? i * 2
+ : Math.min((i - halfway) * 2 + 1, (contracts?.length ?? 1) - 1)
+ }
+ const twoColContracts = Array.from(
+ { length: contracts.length },
+ (_, i) => contracts[reorder(i)]
+ )
return (
-
- {contracts.map((contract) => (
+ {/* TODO: When columns-1, don't reorder the contracts */}
+ {twoColContracts.map((contract) => (
))}
-
+