make home tabs controlled

This commit is contained in:
hzrd149 2023-02-07 17:04:18 -06:00
parent 1d34ec31eb
commit ca8df3fff5
3 changed files with 25 additions and 10 deletions

View File

@ -21,6 +21,14 @@ const RequireSetup = ({ children }: { children: JSX.Element }) => {
return children;
};
const HomePage = () => (
<RequireSetup>
<Page>
<HomeView />
</Page>
</RequireSetup>
);
export const App = () => {
return (
<ErrorBoundary>
@ -72,16 +80,7 @@ export const App = () => {
</RequireSetup>
}
/>
<Route
path="/"
element={
<RequireSetup>
<Page>
<HomeView />
</Page>
</RequireSetup>
}
/>
<Route path="/*" element={<HomePage />} />
</Routes>
</ErrorBoundary>
);

View File

@ -40,6 +40,13 @@ export const PostMenu = ({ event }: { event: NostrEvent }) => {
>
Open in BRB
</MenuItem>
<MenuItem
as="a"
href={`https://snort.social/e/${event.id}`}
target="_blank"
>
Open in snort.social
</MenuItem>
<MenuItem onClick={() => copyToClipboard(event.id)}>
Copy {truncatedId(event.id)}
</MenuItem>

View File

@ -1,8 +1,15 @@
import { Tab, TabList, TabPanel, TabPanels, Tabs } from "@chakra-ui/react";
import { useMatch, useNavigate } from "react-router-dom";
import { DiscoverTab } from "./discover-tab";
import { FollowingTab } from "./following-tab";
export const HomeView = () => {
const navigate = useNavigate();
const followingMatch = useMatch("/following");
const discoverMatch = useMatch("/discover");
const tabs = ["/following", "/discover"];
return (
<Tabs
display="flex"
@ -10,6 +17,8 @@ export const HomeView = () => {
flexGrow="1"
overflow="hidden"
isLazy
index={discoverMatch ? 1 : 0}
onChange={(v) => navigate(tabs[v])}
>
<TabList>
<Tab>Following</Tab>