nice routing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"plugins": ["@typescript-eslint", "react-hooks"],
|
||||
"extends": [
|
||||
"next/core-web-vitals",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
@@ -10,7 +10,14 @@
|
||||
// I suggest you add those two rules:
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"@typescript-eslint/no-explicit-any": "error",
|
||||
"prefer-const": "error"
|
||||
"prefer-const": "error",
|
||||
"react-hooks/rules-of-hooks": "error",
|
||||
"react-hooks/exhaustive-deps": [
|
||||
"warn",
|
||||
{
|
||||
"additionalHooks": "(useRecoilCallback|useRecoilTransaction_UNSTABLE)"
|
||||
}
|
||||
]
|
||||
},
|
||||
"parser": "@typescript-eslint/parser"
|
||||
}
|
||||
|
||||
@@ -15,11 +15,13 @@ import {
|
||||
} from "react-icons/fa";
|
||||
import { HiSpeakerphone } from "react-icons/hi";
|
||||
import Routes from "@nirvana/common/helpers/routes";
|
||||
import Link from "next/link";
|
||||
import { useRecoilValue } from "recoil";
|
||||
import { currPagePath } from "../../recoil/main";
|
||||
|
||||
function Sidebar() {
|
||||
const router = useRouter();
|
||||
const currPage = router.pathname;
|
||||
|
||||
const currPage = useRecoilValue(currPagePath);
|
||||
|
||||
const handleRoute = (route: Routes) => {
|
||||
router.push(route);
|
||||
@@ -35,11 +37,6 @@ function Sidebar() {
|
||||
|
||||
{/* navigation items */}
|
||||
<div className="flex flex-col my-5 space-y-5 w-full">
|
||||
<Link href={Routes.convos}>{Routes.convos}</Link>
|
||||
<Link href={Routes.later}>{Routes.later}</Link>
|
||||
<Link href={Routes.done}>{Routes.done}</Link>
|
||||
<Link href={Routes.drawer}>{Routes.drawer}</Link>
|
||||
|
||||
<span
|
||||
onClick={() => handleRoute(Routes.convos)}
|
||||
className="flex flex-row items-center hover:cursor-pointer transition-all group"
|
||||
|
||||
@@ -4,6 +4,8 @@ import { AuthProvider } from "../contexts/authContext";
|
||||
import SiteLayout from "../components/Layouts/SiteLayout";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
|
||||
import { RecoilRoot } from "recoil";
|
||||
|
||||
import type { NextPage } from "next";
|
||||
import type { AppProps } from "next/app";
|
||||
|
||||
@@ -24,11 +26,13 @@ function MyApp({ Component, pageProps }: AppPropsWithLayout) {
|
||||
const getLayout = Component.getLayout ?? ((page) => page);
|
||||
|
||||
return (
|
||||
<SiteLayout>
|
||||
<AuthProvider>{getLayout(<Component {...pageProps} />)}</AuthProvider>
|
||||
<RecoilRoot>
|
||||
<SiteLayout>
|
||||
<AuthProvider>{getLayout(<Component {...pageProps} />)}</AuthProvider>
|
||||
|
||||
<Toaster position="top-center" />
|
||||
</SiteLayout>
|
||||
<Toaster position="top-center" />
|
||||
</SiteLayout>
|
||||
</RecoilRoot>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
import Routes from "@nirvana/common/helpers/routes";
|
||||
import { useRouter } from "next/router";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, { useEffect } from "react";
|
||||
import { useRecoilState } from "recoil";
|
||||
import Conversations from "../../components/v2/Conversations";
|
||||
import Done from "../../components/v2/done";
|
||||
import Drawer from "../../components/v2/drawer";
|
||||
import Done from "../../components/v2/Done";
|
||||
import Drawer from "../../components/v2/Drawer";
|
||||
import Header from "../../components/v2/Header";
|
||||
import Later from "../../components/v2/later";
|
||||
import Later from "../../components/v2/Later";
|
||||
import Sidebar from "../../components/v2/Sidebar";
|
||||
import { currPagePath } from "../../recoil/main";
|
||||
|
||||
export default function Me() {
|
||||
// figure out what content to render from here
|
||||
const router = useRouter();
|
||||
const [currRoute, setCurrRoute] = useState<string>(router.pathname);
|
||||
const [currRoute, setCurrRoute] = useRecoilState(currPagePath);
|
||||
|
||||
useEffect(() => {
|
||||
const onHashChangeStart = (url) => {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { atom } from "recoil";
|
||||
|
||||
export enum RecoilActions {
|
||||
CURR_PAGE_PATH = "CURR_PAGE_PATH",
|
||||
}
|
||||
|
||||
export const currPagePath = atom({
|
||||
key: RecoilActions.CURR_PAGE_PATH, // unique ID (with respect to other atoms/selectors)
|
||||
default: "/s", // default value (aka initial value)
|
||||
});
|
||||
Reference in New Issue
Block a user