Deck thread nav

This commit is contained in:
2023-09-18 12:37:15 +01:00
parent 8f9cbcedc8
commit bbbcbc0a92
5 changed files with 64 additions and 43 deletions

View File

@ -154,8 +154,7 @@ const TierThree = ({ active, isLastSubthread, notes, related, chains, onNavigate
return ( return (
<> <>
<div <div
className={`subthread-container ${hasMultipleNotes ? "subthread-multi" : ""} ${ className={`subthread-container ${hasMultipleNotes ? "subthread-multi" : ""} ${isLast ? "subthread-last" : "subthread-mid"
isLast ? "subthread-last" : "subthread-mid"
}`}> }`}>
<Divider variant="small" /> <Divider variant="small" />
<Note <Note
@ -185,8 +184,7 @@ const TierThree = ({ active, isLastSubthread, notes, related, chains, onNavigate
return ( return (
<div <div
key={r.id} key={r.id}
className={`subthread-container ${lastReply ? "" : "subthread-multi"} ${ className={`subthread-container ${lastReply ? "" : "subthread-multi"} ${lastReply ? "subthread-last" : "subthread-mid"
lastReply ? "subthread-last" : "subthread-mid"
}`}> }`}>
<Divider variant="small" /> <Divider variant="small" />
<Note <Note
@ -216,7 +214,7 @@ export function ThreadRoute() {
); );
} }
export function Thread() { export function Thread(props: { onBack?: () => void }) {
const thread = useContext(ThreadContext); const thread = useContext(ThreadContext);
const navigate = useNavigate(); const navigate = useNavigate();
@ -283,6 +281,8 @@ export function Thread() {
function goBack() { function goBack() {
if (parent) { if (parent) {
thread.setCurrent(parent); thread.setCurrent(parent);
} else if (props.onBack) {
props.onBack();
} else { } else {
navigate(-1); navigate(-1);
} }
@ -296,6 +296,7 @@ export function Thread() {
defaultMessage: "Back", defaultMessage: "Back",
description: "Navigate back button on threads view", description: "Navigate back button on threads view",
}); });
return ( return (
<> <>
<div className="main-content p"> <div className="main-content p">

View File

@ -22,6 +22,7 @@ export interface TimelineFollowsProps {
liveStreams?: boolean; liveStreams?: boolean;
noteFilter?: (ev: NostrEvent) => boolean; noteFilter?: (ev: NostrEvent) => boolean;
noteRenderer?: (ev: NostrEvent) => ReactNode; noteRenderer?: (ev: NostrEvent) => ReactNode;
noteOnClick?: (ev: NostrEvent) => void;
} }
/** /**
@ -91,7 +92,7 @@ const TimelineFollows = (props: TimelineFollowsProps) => {
<> <>
<div className="card latest-notes" onClick={() => onShowLatest()} ref={ref}> <div className="card latest-notes" onClick={() => onShowLatest()} ref={ref}>
{latestAuthors.slice(0, 3).map(p => { {latestAuthors.slice(0, 3).map(p => {
return <ProfileImage pubkey={p} showUsername={false} link={""} />; return <ProfileImage pubkey={p} showUsername={false} link={""} showFollowingMark={false} />;
})} })}
<FormattedMessage <FormattedMessage
defaultMessage="{n} new {n, plural, =1 {note} other {notes}}" defaultMessage="{n} new {n, plural, =1 {note} other {notes}}"
@ -102,7 +103,7 @@ const TimelineFollows = (props: TimelineFollowsProps) => {
{!inView && ( {!inView && (
<div className="card latest-notes latest-notes-fixed pointer fade-in" onClick={() => onShowLatest(true)}> <div className="card latest-notes latest-notes-fixed pointer fade-in" onClick={() => onShowLatest(true)}>
{latestAuthors.slice(0, 3).map(p => { {latestAuthors.slice(0, 3).map(p => {
return <ProfileImage pubkey={p} showUsername={false} link={""} />; return <ProfileImage pubkey={p} showUsername={false} link={""} showFollowingMark={false} />;
})} })}
<FormattedMessage <FormattedMessage
defaultMessage="{n} new {n, plural, =1 {note} other {notes}}" defaultMessage="{n} new {n, plural, =1 {note} other {notes}}"
@ -116,7 +117,7 @@ const TimelineFollows = (props: TimelineFollowsProps) => {
{mainFeed.map( {mainFeed.map(
a => a =>
props.noteRenderer?.(a) ?? ( props.noteRenderer?.(a) ?? (
<Note data={a as TaggedNostrEvent} related={relatedFeed(a.id)} key={a.id} depth={0} /> <Note data={a as TaggedNostrEvent} related={relatedFeed(a.id)} key={a.id} depth={0} onClick={props.noteOnClick} />
), ),
)} )}
<div className="flex f-center p"> <div className="flex f-center p">

View File

@ -60,6 +60,7 @@
display: flex; display: flex;
flex-direction: row; flex-direction: row;
border-radius: unset; border-radius: unset;
justify-content: center;
gap: 16px; gap: 16px;
--border-color: #3a3a3a; --border-color: #3a3a3a;
} }

View File

@ -1,5 +1,5 @@
import "./Deck.css"; import "./Deck.css";
import { CSSProperties, useContext, useEffect, useState } from "react"; import { CSSProperties, createContext, useContext, useEffect, useState } from "react";
import { Outlet, useNavigate } from "react-router-dom"; import { Outlet, useNavigate } from "react-router-dom";
import { FormattedMessage } from "react-intl"; import { FormattedMessage } from "react-intl";
import { NostrPrefix, createNostrLink } from "@snort/system"; import { NostrPrefix, createNostrLink } from "@snort/system";
@ -24,10 +24,20 @@ import useLogin from "Hooks/useLogin";
type Cols = "notes" | "articles" | "media" | "streams" | "notifications"; type Cols = "notes" | "articles" | "media" | "streams" | "notifications";
interface DeckScope {
thread?: string,
setThread: (e?: string) => void
}
export const DeckContext = createContext<DeckScope | undefined>(undefined);
export function SnortDeckLayout() { export function SnortDeckLayout() {
const login = useLogin(); const login = useLogin();
const navigate = useNavigate(); const navigate = useNavigate();
const [thread, setThread] = useState<string>(); const [deckScope, setDeckScope] = useState<DeckScope>({
setThread: (e?: string) => setDeckScope(s => ({ ...s, thread: e }))
});
useLoginFeed(); useLoginFeed();
useTheme(); useTheme();
@ -43,6 +53,7 @@ export function SnortDeckLayout() {
const cols = ["notes", "media", "notifications", "articles"] as Array<Cols>; const cols = ["notes", "media", "notifications", "articles"] as Array<Cols>;
return ( return (
<div className="deck-layout"> <div className="deck-layout">
<DeckContext.Provider value={deckScope}>
<DeckNav /> <DeckNav />
<div className="deck-cols"> <div className="deck-cols">
{cols.map(c => { {cols.map(c => {
@ -50,7 +61,7 @@ export function SnortDeckLayout() {
case "notes": case "notes":
return <NotesCol />; return <NotesCol />;
case "media": case "media":
return <MediaCol setThread={setThread} />; return <MediaCol setThread={deckScope.setThread} />;
case "articles": case "articles":
return <ArticlesCol />; return <ArticlesCol />;
case "notifications": case "notifications":
@ -58,19 +69,20 @@ export function SnortDeckLayout() {
} }
})} })}
</div> </div>
{thread && ( {deckScope.thread && (
<> <>
<Modal onClose={() => setThread(undefined)} className="thread-overlay"> <Modal onClose={() => deckScope.setThread(undefined)} className="thread-overlay">
<ThreadContextWrapper link={createNostrLink(NostrPrefix.Note, thread)}> <ThreadContextWrapper link={createNostrLink(NostrPrefix.Note, deckScope.thread)}>
<SpotlightFromThread onClose={() => setThread(undefined)} /> <SpotlightFromThread onClose={() => deckScope.setThread(undefined)} />
<div> <div>
<Thread /> <Thread onBack={() => deckScope.setThread(undefined)}/>
</div> </div>
</ThreadContextWrapper> </ThreadContextWrapper>
</Modal> </Modal>
</> </>
)} )}
<Toaster /> <Toaster />
</DeckContext.Provider>
</div> </div>
); );
} }
@ -80,7 +92,7 @@ function SpotlightFromThread({ onClose }: { onClose: () => void }) {
const parsed = thread.root ? transformTextCached(thread.root.id, thread.root.content, thread.root.tags) : []; const parsed = thread.root ? transformTextCached(thread.root.id, thread.root.content, thread.root.tags) : [];
const images = parsed.filter(a => a.type === "media" && a.mimeType?.startsWith("image/")); const images = parsed.filter(a => a.type === "media" && a.mimeType?.startsWith("image/"));
if (images.length === 0) return;
return <SpotlightMedia images={images.map(a => a.content)} idx={0} onClose={onClose} />; return <SpotlightMedia images={images.map(a => a.content)} idx={0} onClose={onClose} />;
} }

View File

@ -1,4 +1,4 @@
import { useEffect, useState } from "react"; import { useContext, useEffect, useState } from "react";
import { Link, Outlet, RouteObject, useParams } from "react-router-dom"; import { Link, Outlet, RouteObject, useParams } from "react-router-dom";
import { FormattedMessage } from "react-intl"; import { FormattedMessage } from "react-intl";
import { unixNow } from "@snort/shared"; import { unixNow } from "@snort/shared";
@ -16,6 +16,7 @@ import SuggestedProfiles from "Element/SuggestedProfiles";
import { TaskList } from "Tasks/TaskList"; import { TaskList } from "Tasks/TaskList";
import TimelineFollows from "Element/TimelineFollows"; import TimelineFollows from "Element/TimelineFollows";
import { RootTabs } from "Element/RootTabs"; import { RootTabs } from "Element/RootTabs";
import { DeckContext } from "Pages/DeckLayout";
import messages from "./messages"; import messages from "./messages";
@ -133,11 +134,16 @@ export const GlobalTab = () => {
}; };
export const NotesTab = () => { export const NotesTab = () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const deckContext = useContext(DeckContext);
return ( return (
<> <>
<FollowsHint /> <FollowsHint />
<TaskList /> <TaskList />
<TimelineFollows postsOnly={true} /> <TimelineFollows postsOnly={true} noteOnClick={deckContext ? (ev) => {
deckContext.setThread(ev.id);
} : undefined} />
</> </>
); );
}; };