Skip to content

Commit a618efe

Browse files
committed
sort grants by budgetAmount
1 parent 9003a0f commit a618efe

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

widgets/src/components/HomeGrantList.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function HomeGrantList({}) {
2020
const now = new Date()
2121
now.setHours(0, 0, 0, 0)
2222

23-
const grants = await axios.get(getManageURL("public/grants"), { params: { _limit: numberOfEntries, _sort: "-budgetAmount", from: now} })
23+
const grants = await axios.get(getManageURL("public/grants"), { params: { _limit: numberOfEntries, from: now} })
2424
if (grants.data) {
2525
return grants.data.data
2626
}
@@ -30,8 +30,21 @@ export function HomeGrantList({}) {
3030
return <Loading widget="Lista dei grant" error={error}></Loading>
3131
}
3232

33-
const all_grant_list = data.slice(0, numberOfEntries).map((x) => (
34-
<GrantBox grant={x} key={x._id}></GrantBox>
33+
const parseBudgetAmount = (budgetStr) => {
34+
const numStr = budgetStr.replace(/^[$£]|\s/g, '')
35+
36+
return parseFloat(numStr.replace(/\./g, '').replace(',', '.'))
37+
};
38+
39+
const all_grant_list = data
40+
.slice(0, numberOfEntries)
41+
.sort((a, b) => {
42+
const amountA = parseBudgetAmount(a.budgetAmount)
43+
const amountB = parseBudgetAmount(b.budgetAmount)
44+
return amountB - amountA;
45+
})
46+
.map((x) => (
47+
<GrantBox grant={x} key={x._id}></GrantBox>
3548
));
3649

3750
const showButton = numberOfEntries <= all_grant_list.length;

0 commit comments

Comments
 (0)