Skip to content

Commit

Permalink
preload next & prev grid image modal
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalmi committed Dec 19, 2023
1 parent c1c99f1 commit 47f70b0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
18 changes: 17 additions & 1 deletion packages/app/src/Element/Feed/TimelineRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ function Grid({ frags }: { frags: Array<TimelineFragment> }) {
}, [allEvents]);

const modalThread = modalThreadIndex !== undefined ? mediaEvents[modalThreadIndex] : undefined;
const nextModalThread = modalThreadIndex !== undefined ? mediaEvents[modalThreadIndex + 1] : undefined;
const prevModalThread = modalThreadIndex !== undefined ? mediaEvents[modalThreadIndex - 1] : undefined;

return (
<>
Expand All @@ -46,14 +48,28 @@ function Grid({ frags }: { frags: Array<TimelineFragment> }) {
</div>
{modalThread && (
<SpotlightThreadModal
key={modalThreadIndex}
key={modalThread.id}
thread={NostrLink.fromEvent(modalThread)}
onClose={() => setModalThreadIndex(undefined)}
onBack={() => setModalThreadIndex(undefined)}
onNext={() => setModalThreadIndex(Math.min(modalThreadIndex + 1, mediaEvents.length - 1))}
onPrev={() => setModalThreadIndex(Math.max(modalThreadIndex - 1, 0))}
/>
)}
{nextModalThread && ( // preload next
<SpotlightThreadModal
className="hidden"
key={`${nextModalThread.id}-next`}
thread={NostrLink.fromEvent(nextModalThread)}
/>
)}
{prevModalThread && ( // preload previous
<SpotlightThreadModal
className="hidden"
key={`${prevModalThread.id}-prev`}
thread={NostrLink.fromEvent(prevModalThread)}
/>
)}
</>
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/Element/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function Modal(props: ModalProps) {
}, []);

return createPortal(
<div className={`modal${props.className ? ` ${props.className}` : ""}`} onClick={props.onClose}>
<div className={props.className === "hidden" ? props.className : `modal ${props.className || ""}`} onClick={props.onClose}>
<div
className={props.bodyClassName || "modal-body"}
onClick={e => {
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/Element/Spotlight/SpotlightThreadModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import getEventMedia from "@/Element/Event/getEventMedia";

interface SpotlightThreadModalProps {
thread: NostrLink;
className?: string;
onClose?: () => void;
onBack?: () => void;
onNext?: () => void;
Expand All @@ -24,7 +25,7 @@ export function SpotlightThreadModal(props: SpotlightThreadModalProps) {
};

return (
<Modal id="thread-overlay" onClose={onClose} bodyClassName={"flex flex-1"}>
<Modal className={props.className} onClose={onClose} bodyClassName={"flex flex-1"}>
<ThreadContextWrapper link={props.thread}>
<div className="flex flex-row h-screen w-screen">
<div className="flex w-full md:w-2/3 items-center justify-center overflow-hidden" onClick={onClickBg}>
Expand Down
3 changes: 1 addition & 2 deletions packages/app/src/Pages/DeckLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ export function SnortDeckLayout() {
{deckState.article && (
<>
<Modal
id="thread-overlay-article"
onClose={() => setDeckState({})}
className="thread-overlay long-form"
className="long-form"
onClick={() => setDeckState({})}>
<div onClick={e => e.stopPropagation()}>
<LongFormText ev={deckState.article} isPreview={false} related={[]} />
Expand Down

0 comments on commit 47f70b0

Please sign in to comment.