mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-19 11:43:30 +00:00
added filtered duplicate parent id
This commit is contained in:
parent
62ca74994d
commit
7d5f9d90c4
@ -8,6 +8,7 @@ import { Placeholder } from '@components/note/placeholder';
|
||||
import { hasNewerNoteAtom } from '@stores/note';
|
||||
|
||||
import { dateToUnix } from '@utils/getDate';
|
||||
import { filterDuplicateParentID } from '@utils/transform';
|
||||
|
||||
import { ArrowUpIcon } from '@radix-ui/react-icons';
|
||||
import { useAtom } from 'jotai';
|
||||
@ -73,7 +74,11 @@ export default function Page() {
|
||||
// next query
|
||||
const result: any = await getLatestNotes({ date: dateToUnix(now.current) });
|
||||
// update data
|
||||
if (result.length > 0) {
|
||||
setData((data) => [...data, ...result]);
|
||||
} else {
|
||||
setData((data) => [...data, result]);
|
||||
}
|
||||
// hide newer trigger
|
||||
setHasNewerNote(false);
|
||||
// scroll to top
|
||||
@ -99,7 +104,7 @@ export default function Page() {
|
||||
)}
|
||||
<Virtuoso
|
||||
ref={virtuosoRef}
|
||||
data={data}
|
||||
data={filterDuplicateParentID(data)}
|
||||
itemContent={itemContent}
|
||||
computeItemKey={computeItemKey}
|
||||
components={COMPONENTS}
|
||||
|
@ -46,15 +46,10 @@ export const getParentID = (arr, fallback) => {
|
||||
return parentID;
|
||||
};
|
||||
|
||||
export const filteredData = (obj) => {
|
||||
const filteredArr = obj.reduce((item, current) => {
|
||||
const x = item.find((item) => item.parent_id === current.parent_id);
|
||||
if (!x) {
|
||||
return item.concat([current]);
|
||||
} else {
|
||||
return item;
|
||||
}
|
||||
}, []);
|
||||
export const filterDuplicateParentID = (arr) => {
|
||||
const filteredArray = arr.filter(
|
||||
(item, index) => index === arr.findIndex((other) => item.parent_id === other.parent_id)
|
||||
);
|
||||
|
||||
return filteredArr;
|
||||
return filteredArray;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user