pain and suffering

This commit is contained in:
Stepan Usatiuk
2023-12-30 20:43:21 +01:00
parent d7cd581bff
commit 65e50d9e02
5 changed files with 149 additions and 87 deletions

View File

@@ -8,6 +8,7 @@
"start": "parcel",
"build": "parcel build"
},
"publicUrl": "/app",
"browserslist": "> 0.5%, last 2 versions, not dead",
"dependencies": {
"jwt-decode": "^4.0.0",

View File

@@ -39,95 +39,98 @@ import { Chat } from "./Chat";
import { ChatEdit } from "./ChatEdit";
import { Haters } from "./Haters";
const router = createBrowserRouter([
{
path: "/",
loader: async () => {
if (getToken() == null) {
return redirect("/login");
} else {
return redirect("/home");
}
const router = createBrowserRouter(
[
{
path: "/",
loader: async () => {
if (getToken() == null) {
return redirect("/login");
} else {
return redirect("/home");
}
},
},
},
{
path: "/home",
loader: homeLoader,
action: homeAction,
element: <Home />,
children: [
{ path: "feed", element: <Feed />, loader: feedLoader },
// { path: "messages", element: <Messages /> },
{
path: "messages/chats",
element: <Chats />,
loader: chatListLoader,
},
{
path: "messages/chats/new",
element: <ChatCreate />,
loader: newChatLoader,
action: newChatAction,
},
{
path: "messages/chat/:id",
element: <Chat />,
loader: chatLoader,
action: chatAction,
},
{
path: "messages/chat/:id/edit",
element: <ChatEdit />,
loader: editChatLoader,
action: editChatAction,
},
{
path: "users",
element: <UserList />,
loader: userListLoader,
action: userListAction,
},
{
path: "profile",
loader: profileLoader,
action: profileSelfAction,
element: <Profile self={true} />,
},
{
path: "profile/:username",
loader: profileLoader,
// action: profileSelfAction,
element: <Profile self={false} />,
},
{
path: "haters",
element: <Haters />,
},
],
},
{
path: "/login",
element: <Login />,
loader: async () => {
if (getToken()) {
return redirect("/");
}
return null;
{
path: "/home",
loader: homeLoader,
action: homeAction,
element: <Home />,
children: [
{ path: "feed", element: <Feed />, loader: feedLoader },
// { path: "messages", element: <Messages /> },
{
path: "messages/chats",
element: <Chats />,
loader: chatListLoader,
},
{
path: "messages/chats/new",
element: <ChatCreate />,
loader: newChatLoader,
action: newChatAction,
},
{
path: "messages/chat/:id",
element: <Chat />,
loader: chatLoader,
action: chatAction,
},
{
path: "messages/chat/:id/edit",
element: <ChatEdit />,
loader: editChatLoader,
action: editChatAction,
},
{
path: "users",
element: <UserList />,
loader: userListLoader,
action: userListAction,
},
{
path: "profile",
loader: profileLoader,
action: profileSelfAction,
element: <Profile self={true} />,
},
{
path: "profile/:username",
loader: profileLoader,
// action: profileSelfAction,
element: <Profile self={false} />,
},
{
path: "haters",
element: <Haters />,
},
],
},
action: loginAction,
},
{
path: "/signup",
element: <Signup />,
loader: async () => {
if (getToken()) {
return redirect("/");
}
return null;
{
path: "/login",
element: <Login />,
loader: async () => {
if (getToken()) {
return redirect("/");
}
return null;
},
action: loginAction,
},
action: signupAction,
},
]);
{
path: "/signup",
element: <Signup />,
loader: async () => {
if (getToken()) {
return redirect("/");
}
return null;
},
action: signupAction,
},
],
{ basename: "/app" },
);
export function App() {
return (

View File

@@ -3,7 +3,14 @@
import { jwtDecode } from "jwt-decode";
import { isError } from "./dto";
const apiRoot: string = "http://localhost:8080";
declare const process: {
env: {
NODE_ENV: string;
};
};
const apiRoot: string =
process.env.NODE_ENV == "production" ? "/" : "http://localhost:8080";
let token: string | null;