Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
chore: update signin button in visitor mode
boojack58e68f8f80de
diff --git a/web/src/App.tsx b/web/src/App.tsxindex 50d83d6a1..19bd2a616 100644--- a/web/src/App.tsx+++ b/web/src/App.tsx@@ -1,10 +1,21 @@+import { useEffect, useState } from "react";import { appRouterSwitch } from "./routers";+import { locationService } from "./services";import { useAppSelector } from "./store";function App() {const pathname = useAppSelector((state) => state.location.pathname);+ const [isLoading, setLoading] = useState(true);- return <>{appRouterSwitch(pathname)}</>;+ useEffect(() => {+ locationService.updateStateWithLocation();+ window.onpopstate = () => {+ locationService.updateStateWithLocation();+ };+ setLoading(false);+ }, []);++ return <>{isLoading ? null : appRouterSwitch(pathname)}</>;}export default App;diff --git a/web/src/components/MemoList.tsx b/web/src/components/MemoList.tsxindex f184c1735..c681ff90c 100644--- a/web/src/components/MemoList.tsx+++ b/web/src/components/MemoList.tsx@@ -83,7 +83,6 @@ const MemoList: React.FC<Props> = () => {.fetchAllMemos().then(() => {setFetchStatus(false);- memoService.updateTagsState();}).catch(() => {toastHelper.error("π Fetching failed, please try again later.");diff --git a/web/src/components/Sidebar.tsx b/web/src/components/Sidebar.tsxindex a8155d86c..1052aa0f6 100644--- a/web/src/components/Sidebar.tsx+++ b/web/src/components/Sidebar.tsx@@ -1,5 +1,4 @@import { userService } from "../services";-import { useAppSelector } from "../store";import Only from "./common/OnlyWhen";import showDailyReviewDialog from "./DailyReviewDialog";import showSettingDialog from "./SettingDialog";@@ -13,8 +12,6 @@ import "../less/siderbar.less";interface Props {}const Sidebar: React.FC<Props> = () => {- const user = useAppSelector((state) => state.user.user);-const handleMyAccountBtnClick = () => {showSettingDialog();};@@ -44,17 +41,6 @@ const Sidebar: React.FC<Props> = () => {<button className="btn action-btn" onClick={handleArchivedBtnClick}><span className="icon">π</span> Archived</button>- <Only when={userService.isVisitorMode()}>- {user ? (- <button className="btn action-btn" onClick={() => (window.location.href = "/")}>- <span className="icon">π </span> Back to Home- </button>- ) : (- <button className="btn action-btn" onClick={() => (window.location.href = "/signin")}>- <span className="icon">π</span> Sign in- </button>- )}- </Only></div><Only when={!userService.isVisitorMode()}><ShortcutList />diff --git a/web/src/components/TagList.tsx b/web/src/components/TagList.tsxindex 74a8354a9..a764bfe09 100644--- a/web/src/components/TagList.tsx+++ b/web/src/components/TagList.tsx@@ -20,7 +20,9 @@ const TagList: React.FC<Props> = () => {const [tags, setTags] = useState<Tag[]>([]);useEffect(() => {- memoService.updateTagsState();+ if (memos.length > 0) {+ memoService.updateTagsState();+ }}, [memos]);useEffect(() => {diff --git a/web/src/less/home.less b/web/src/less/home.lessindex db3746d7e..57e965fc0 100644--- a/web/src/less/home.less+++ b/web/src/less/home.less@@ -18,6 +18,18 @@@apply sticky top-0 w-full h-full flex flex-col justify-start items-start z-10;background-color: #f6f5f4;}++ > .addtion-btn-container {+ @apply fixed bottom-12 left-1/2 -translate-x-1/2;++ > .btn {+ @apply bg-blue-600 text-white px-4 py-2 rounded-3xl shadow-2xl hover:opacity-80;++ > .icon {+ @apply text-lg mr-1;+ }+ }+ }}}}diff --git a/web/src/main.tsx b/web/src/main.tsxindex c2d46193d..5451f08c6 100644--- a/web/src/main.tsx+++ b/web/src/main.tsx@@ -1,10 +1,9 @@import { createRoot } from "react-dom/client";import { Provider } from "react-redux";import store from "./store";-import { updateStateWithLocation } from "./store/modules/location";import App from "./App";-import "./less/global.less";import "./helpers/polyfill";+import "./less/global.less";import "./css/index.css";const container = document.getElementById("root");@@ -14,10 +13,3 @@ root.render(<App /></Provider>);--window.onload = () => {- store.dispatch(updateStateWithLocation());- window.onpopstate = () => {- store.dispatch(updateStateWithLocation());- };-};diff --git a/web/src/pages/Home.tsx b/web/src/pages/Home.tsxindex 5b8a1f982..b0406c2ea 100644--- a/web/src/pages/Home.tsx+++ b/web/src/pages/Home.tsx@@ -12,6 +12,7 @@ import toastHelper from "../components/Toast";import "../less/home.less";function Home() {+ const user = useAppSelector((state) => state.user.user);const location = useAppSelector((state) => state.location);const loadingState = useLoading();@@ -53,6 +54,19 @@ function Home() {<MemoFilter /></div><MemoList />+ <Only when={userService.isVisitorMode()}>+ <div className="addtion-btn-container">+ {user ? (+ <button className="btn" onClick={() => (window.location.href = "/")}>+ <span className="icon">π </span> Back to Home+ </button>+ ) : (+ <button className="btn" onClick={() => (window.location.href = "/signin")}>+ <span className="icon">π</span> Sign in+ </button>+ )}+ </div>+ </Only></main></div>)}diff --git a/web/src/services/locationService.ts b/web/src/services/locationService.tsindex 58e5eec03..6e75d5cdc 100644--- a/web/src/services/locationService.ts+++ b/web/src/services/locationService.ts@@ -1,6 +1,6 @@import { stringify } from "qs";import store from "../store";-import { setQuery, setPathname, Query } from "../store/modules/location";+import { setQuery, setPathname, Query, updateStateWithLocation } from "../store/modules/location";const updateLocationUrl = (method: "replace" | "push" = "replace") => {const { query, pathname, hash } = store.getState().location;@@ -23,6 +23,10 @@ const locationService = {return store.getState().location;},+ updateStateWithLocation: () => {+ store.dispatch(updateStateWithLocation());+ },+setPathname: (pathname: string) => {store.dispatch(setPathname(pathname));updateLocationUrl();diff --git a/web/src/store/modules/location.ts b/web/src/store/modules/location.tsindex ad3e83b61..ec5073cb8 100644--- a/web/src/store/modules/location.ts+++ b/web/src/store/modules/location.ts@@ -64,12 +64,20 @@ const locationSlice = createSlice({return getStateFromLocation();},setPathname: (state, action: PayloadAction<string>) => {+ if (state.pathname === action.payload) {+ return state;+ }+return {...state,pathname: action.payload,};},setQuery: (state, action: PayloadAction<Partial<Query>>) => {+ if (JSON.stringify(action.payload) === state.query) {+ return state;+ }+return {...state,query: {