mirror of
https://github.com/hoornet/vega.git
synced 2026-04-24 06:40:01 -07:00
Persist feed tab across navigation — back button returns to correct tab
Feed tab (Global/Following) moved from local state to UI store so it survives thread/profile navigation. Fixed hardcoded "feed" in openThread calls to pass currentView instead.
This commit is contained in:
@@ -2,19 +2,17 @@ import { useEffect, useState } from "react";
|
||||
import { useFeedStore } from "../../stores/feed";
|
||||
import { useUserStore } from "../../stores/user";
|
||||
import { useMuteStore } from "../../stores/mute";
|
||||
import { useUIStore } from "../../stores/ui";
|
||||
import { fetchFollowFeed, getNDK } from "../../lib/nostr";
|
||||
import { NoteCard } from "./NoteCard";
|
||||
import { ComposeBox } from "./ComposeBox";
|
||||
import { NDKEvent } from "@nostr-dev-kit/ndk";
|
||||
|
||||
type FeedTab = "global" | "following";
|
||||
|
||||
export function Feed() {
|
||||
const { notes, loading, connected, error, connect, loadCachedFeed, loadFeed, focusedNoteIndex } = useFeedStore();
|
||||
const { loggedIn, follows } = useUserStore();
|
||||
const { mutedPubkeys } = useMuteStore();
|
||||
|
||||
const [tab, setTab] = useState<FeedTab>("global");
|
||||
const { feedTab: tab, setFeedTab: setTab } = useUIStore();
|
||||
const [followNotes, setFollowNotes] = useState<NDKEvent[]>([]);
|
||||
const [followLoading, setFollowLoading] = useState(false);
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ export function NoteCard({ event, focused }: NoteCardProps) {
|
||||
onClick={async (e) => {
|
||||
e.stopPropagation();
|
||||
const parent = await fetchNoteById(parentEventId);
|
||||
if (parent) openThread(parent, "feed");
|
||||
if (parent) openThread(parent, currentView as "feed" | "profile");
|
||||
}}
|
||||
className="hover:text-accent transition-colors"
|
||||
>
|
||||
|
||||
@@ -173,7 +173,7 @@ function tryOpenNostrEntity(raw: string): boolean {
|
||||
|
||||
function QuotePreview({ eventId }: { eventId: string }) {
|
||||
const [event, setEvent] = useState<NDKEvent | null>(null);
|
||||
const { openThread } = useUIStore();
|
||||
const { openThread, currentView } = useUIStore();
|
||||
const profile = useProfile(event?.pubkey ?? "");
|
||||
|
||||
useEffect(() => {
|
||||
@@ -189,7 +189,7 @@ function QuotePreview({ eventId }: { eventId: string }) {
|
||||
return (
|
||||
<div
|
||||
className="mt-2 border border-border bg-bg-raised px-3 py-2 cursor-pointer hover:bg-bg-hover transition-colors"
|
||||
onClick={(e) => { e.stopPropagation(); openThread(event, "feed"); }}
|
||||
onClick={(e) => { e.stopPropagation(); openThread(event, currentView as "feed" | "profile"); }}
|
||||
>
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
{profile?.picture && (
|
||||
|
||||
@@ -3,6 +3,7 @@ import { create } from "zustand";
|
||||
import { NDKEvent } from "@nostr-dev-kit/ndk";
|
||||
|
||||
type View = "feed" | "search" | "relays" | "settings" | "profile" | "thread" | "article-editor" | "article" | "about" | "zaps" | "dm" | "notifications";
|
||||
type FeedTab = "global" | "following";
|
||||
|
||||
interface UIState {
|
||||
currentView: View;
|
||||
@@ -10,11 +11,13 @@ interface UIState {
|
||||
selectedPubkey: string | null;
|
||||
selectedNote: NDKEvent | null;
|
||||
previousView: View;
|
||||
feedTab: FeedTab;
|
||||
pendingSearch: string | null;
|
||||
pendingDMPubkey: string | null;
|
||||
pendingArticleNaddr: string | null;
|
||||
showHelp: boolean;
|
||||
setView: (view: View) => void;
|
||||
setFeedTab: (tab: FeedTab) => void;
|
||||
openProfile: (pubkey: string) => void;
|
||||
openThread: (note: NDKEvent, from: View) => void;
|
||||
openSearch: (query: string) => void;
|
||||
@@ -33,11 +36,13 @@ export const useUIStore = create<UIState>((set, _get) => ({
|
||||
selectedPubkey: null,
|
||||
selectedNote: null,
|
||||
previousView: "feed",
|
||||
feedTab: "global",
|
||||
pendingSearch: null,
|
||||
pendingDMPubkey: null,
|
||||
pendingArticleNaddr: null,
|
||||
showHelp: false,
|
||||
setView: (currentView) => set({ currentView }),
|
||||
setFeedTab: (feedTab) => set({ feedTab }),
|
||||
openProfile: (pubkey) => set((s) => ({ currentView: "profile", selectedPubkey: pubkey, previousView: s.currentView as View })),
|
||||
openThread: (note, from) => set({ currentView: "thread", selectedNote: note, previousView: from }),
|
||||
openSearch: (query) => set({ currentView: "search", pendingSearch: query }),
|
||||
|
||||
Reference in New Issue
Block a user