Fix new categories not showing until Customize is opened

## Ticket
1307 newly added categories aren't adding to existing customized homepage

## Change
In Customize, new categories were appended at the bottom, but forgot to repeat the behavior on the actual homepage itself.
This commit is contained in:
infinite-persistence 2022-04-08 18:55:11 +08:00 committed by Thomas Zarebczan
parent 5a400ca2fa
commit 95df6fedc0

View file

@ -88,16 +88,26 @@ function HomePage(props: Props) {
let sortedRowData: Array<RowDataItem> = []; let sortedRowData: Array<RowDataItem> = [];
if (homepageOrder.active && authenticated) { if (homepageOrder.active && authenticated) {
homepageOrder.active.forEach((key) => { homepageOrder.active.forEach((key) => {
const item = rowData.find((data) => data.id === key); const dataIndex = rowData.findIndex((data) => data.id === key);
if (item) { if (dataIndex !== -1) {
sortedRowData.push(item); sortedRowData.push(rowData[dataIndex]);
rowData.splice(dataIndex, 1);
} else if (key === 'FYP') { } else if (key === 'FYP') {
sortedRowData.push(FYP_SECTION); sortedRowData.push(FYP_SECTION);
} }
}); });
if (homepageOrder.hidden) {
rowData.forEach((data: RowDataItem) => {
// $FlowIssue: null 'hidden' already avoided, but flow can't see beyond this anonymous function?
if (!homepageOrder.hidden.includes(data.id)) {
sortedRowData.push(data);
}
});
}
} else { } else {
rowData.forEach((key) => { rowData.forEach((key) => {
// always inject FYP is homepage not customized, hide news. // always inject FYP if homepage not customized, hide news.
if (key.id === 'FOLLOWING') { if (key.id === 'FOLLOWING') {
sortedRowData.push(key); sortedRowData.push(key);
if (hasMembership) { if (hasMembership) {