Skip to content

Commit 88ae996

Browse files
committed
fix(collections): view type not refreshing properly
1 parent d1d1d05 commit 88ae996

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

apps/client/src/widgets/collections/NoteList.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,27 @@ interface NoteListProps {
2323
isEnabled: boolean;
2424
ntxId: string | null | undefined;
2525
media: ViewModeMedia;
26+
viewType: ViewTypeOptions | undefined;
2627
onReady?: () => void;
2728
}
2829

2930
export default function NoteList<T extends object>(props: Pick<NoteListProps, "displayOnlyCollections" | "media" | "onReady">) {
3031
const { note, noteContext, notePath, ntxId } = useNoteContext();
31-
const isEnabled = noteContext?.hasNoteList();
32-
return <CustomNoteList note={note} isEnabled={!!isEnabled} notePath={notePath} ntxId={ntxId} {...props} />
32+
const viewType = useNoteViewType(note);
33+
const [ enabled, setEnabled ] = useState(noteContext?.hasNoteList());
34+
useEffect(() => {
35+
setEnabled(noteContext?.hasNoteList());
36+
}, [ noteContext, viewType ])
37+
return <CustomNoteList viewType={viewType} note={note} isEnabled={!!enabled} notePath={notePath} ntxId={ntxId} {...props} />
3338
}
3439

3540
export function SearchNoteList<T extends object>(props: Omit<NoteListProps, "isEnabled">) {
36-
return <CustomNoteList {...props} isEnabled={true} />
41+
const viewType = useNoteViewType(props.note);
42+
return <CustomNoteList {...props} isEnabled={true} viewType={viewType} />
3743
}
3844

39-
export function CustomNoteList<T extends object>({ note, isEnabled: shouldEnable, notePath, highlightedTokens, displayOnlyCollections, ntxId, onReady, ...restProps }: NoteListProps) {
45+
export function CustomNoteList<T extends object>({ note, viewType, isEnabled: shouldEnable, notePath, highlightedTokens, displayOnlyCollections, ntxId, onReady, ...restProps }: NoteListProps) {
4046
const widgetRef = useRef<HTMLDivElement>(null);
41-
const viewType = useNoteViewType(note);
4247
const noteIds = useNoteIds(shouldEnable ? note : null, viewType, ntxId);
4348
const isFullHeight = (viewType && viewType !== "list" && viewType !== "grid");
4449
const [ isIntersecting, setIsIntersecting ] = useState(false);

0 commit comments

Comments
 (0)