Skip to content

Commit

Permalink
wip(routing): remove old routing hooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcMcIntosh committed Feb 7, 2025
1 parent 44d8f77 commit cd0c9f6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 57 deletions.
12 changes: 10 additions & 2 deletions src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type LayoutProps = {
style?: React.CSSProperties;
};

export const Layout: React.FC<LayoutProps> = ({
export const BasicLayout: React.FC<LayoutProps> = ({
children,
className,
style,
Expand Down Expand Up @@ -44,7 +44,15 @@ export const Layout: React.FC<LayoutProps> = ({
className={classNames(styles.Layout, className)}
style={style}
>
{children ?? <Outlet />}
{children}
</Flex>
);
};

export const Layout: React.FC<LayoutProps> = (props) => {
return (
<BasicLayout {...props}>
<Outlet />
</BasicLayout>
);
};
6 changes: 3 additions & 3 deletions src/components/Layout/LayoutWithTopbar.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from "react";
import { Layout, LayoutProps } from "./Layout";
import { BasicLayout, LayoutProps } from "./Layout";
import { Toolbar } from "../Toolbar";
import { Outlet } from "react-router";

export const LayoutWithToolbar: React.FC<LayoutProps> = (props) => {
return (
<Layout {...props}>
<BasicLayout {...props}>
<Toolbar />
<Outlet />
</Layout>
</BasicLayout>
);
};
2 changes: 1 addition & 1 deletion src/components/Toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const Toolbar = ({ activeTab }: ToolbarProps) => {
});
} else if (to === "stats") {
// dispatch(push({ name: "statistics page" }));
void navigate("/statistics");
void navigate("statistics");
void sendTelemetryEvent({
scope: `openStats`,
success: true,
Expand Down
83 changes: 41 additions & 42 deletions src/features/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ export interface AppProps {
}

export const InnerApp: React.FC<AppProps> = ({ style }: AppProps) => {
const navigate = useNavigate();
// const navigate = useNavigate();
const dispatch = useAppDispatch();

const pages = useAppSelector(selectPages);
const isStreaming = useAppSelector(selectIsStreaming);

const isPageInHistory = useCallback(
(pageName: string) => {
return pages.some((page) => page.name === pageName);
},
[pages],
);
// const isPageInHistory = useCallback(
// (pageName: string) => {
// return pages.some((page) => page.name === pageName);
// },
// [pages],
// );

const { chatPageChange, setIsChatStreaming, setIsChatReady } =
useEventsBusForIDE();
const tourState = useAppSelector((state: RootState) => state.tour);
const historyState = useAppSelector((state: RootState) => state.history);
// const tourState = useAppSelector((state: RootState) => state.tour);
// const historyState = useAppSelector((state: RootState) => state.history);
// const chatId = useAppSelector(selectChatId);
useEventBusForWeb();
useEventBusForApp();
Expand All @@ -76,40 +76,39 @@ export const InnerApp: React.FC<AppProps> = ({ style }: AppProps) => {

const config = useConfig();

const isLoggedIn =
isPageInHistory("history") ||
isPageInHistory("welcome") ||
isPageInHistory("chat");
// const isLoggedIn =
// isPageInHistory("history") ||
// isPageInHistory("welcome") ||
// isPageInHistory("chat");

useEffect(() => {
if (config.apiKey && config.addressURL && !isLoggedIn) {
if (tourState.type === "in_progress" && tourState.step === 1) {
// dispatch(push({ name: "welcome" }));
void navigate("/welcome");
} else if (Object.keys(historyState).length === 0) {
// dispatch(push({ name: "history" }));
// TODO: /chat defaults to new chat, /chat/:id opens from history
dispatch(newChatAction());
void navigate("/chat");
// dispatch(push({ name: "chat" }));
} else {
// dispatch(push({ name: "history" }));
void navigate("/");
}
}
if (!config.apiKey && !config.addressURL && isLoggedIn) {
// dispatch(popBackTo({ name: "login page" }));
void navigate("/login");
}
}, [
config.apiKey,
config.addressURL,
isLoggedIn,
dispatch,
tourState,
historyState,
navigate,
]);
// useEffect(() => {
// if (config.apiKey && config.addressURL) {
// if (tourState.type === "in_progress" && tourState.step === 1) {
// // dispatch(push({ name: "welcome" }));
// void navigate("/welcome");
// } else if (Object.keys(historyState).length === 0) {
// // dispatch(push({ name: "history" }));
// // TODO: /chat defaults to new chat, /chat/:id opens from history
// // dispatch(newChatAction());
// void navigate("/chat");
// // dispatch(push({ name: "chat" }));
// } else {
// // dispatch(push({ name: "history" }));
// void navigate("/");
// }
// }
// if (!config.apiKey && !config.addressURL) {
// // dispatch(popBackTo({ name: "login page" }));
// void navigate("/login");
// }
// }, [
// config.apiKey,
// config.addressURL,
// dispatch,
// tourState,
// historyState,
// navigate,
// ]);

useEffect(() => {
if (pages.length > 1) {
Expand Down
28 changes: 19 additions & 9 deletions src/features/Chat/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect } from "react";
import type { Config } from "../Config/configSlice";
import { Chat as ChatComponent } from "../../components/Chat";
import { useAppDispatch, useAppSelector } from "../../hooks";
Expand All @@ -7,8 +7,9 @@ import {
restoreChat,
selectChatFromCacheOrHistory,
selectMessages,
selectThread,
} from "./Thread";
import { useParams } from "react-router";
import { useNavigate, useParams } from "react-router";

export type ChatProps = {
host: Config["host"];
Expand All @@ -27,13 +28,22 @@ export const Chat: React.FC<ChatProps> = ({
const messages = useAppSelector(selectMessages);
const maybeChatId = useParams().chatId;
const cached = useAppSelector(selectChatFromCacheOrHistory(maybeChatId));
if (maybeChatId === undefined) {
dispatch(newChatAction());
} else if (cached) {
dispatch(restoreChat(cached));
} else {
dispatch(newChatAction());
}
const thread = useAppSelector(selectThread);
// const navigate = useNavigate();

useEffect(() => {
if (maybeChatId === undefined) {
dispatch(newChatAction());
}
// } else if (thread.id !== maybeChatId && cached) {
// dispatch(restoreChat(cached));
// }
// } else if (thread.id !== maybeChatId) {
// dispatch(newChatAction());
// }
}, [cached, dispatch, maybeChatId, thread.id]);

console.log("chat props", maybeChatId, cached);

// if no chat id make a new chat.
// if chat id check cache for chat id, then check history for chat id, if not found ... maybe make a new one ?
Expand Down

0 comments on commit cd0c9f6

Please sign in to comment.