From 6a8c559e8ca607bc16cf47d8274c739158948ca5 Mon Sep 17 00:00:00 2001 From: boojack Date: Sat, 9 Jul 2022 12:00:26 +0800 Subject: [PATCH] chore: update visitor view buttons --- server/basic_auth.go | 2 +- server/memo.go | 2 +- server/shortcut.go | 2 +- server/tag.go | 9 +++++++- store/db/seed/10002__memo.sql | 6 ++--- web/src/components/MemoList.tsx | 8 +------ web/src/components/MenuBtnsPopup.tsx | 15 +++--------- web/src/components/Sidebar.tsx | 34 ++++++++++++++++++++-------- web/src/less/memo-list.less | 21 ++++------------- web/src/pages/Home.tsx | 1 - 10 files changed, 47 insertions(+), 53 deletions(-) diff --git a/server/basic_auth.go b/server/basic_auth.go index a3925aa2..05f844f5 100644 --- a/server/basic_auth.go +++ b/server/basic_auth.go @@ -55,7 +55,7 @@ func removeUserSession(c echo.Context) error { func BasicAuthMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc { return func(c echo.Context) error { // Skip auth for some paths. - if common.HasPrefixes(c.Path(), "/api/auth", "/api/ping", "/api/status", "/api/user/:id/") { + if common.HasPrefixes(c.Path(), "/api/auth", "/api/ping", "/api/status", "/api/user/:userId") { return next(c) } diff --git a/server/memo.go b/server/memo.go index da940b03..babe1ce2 100644 --- a/server/memo.go +++ b/server/memo.go @@ -70,7 +70,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) { } else { userID, ok := c.Get(getUserIDContextKey()).(int) if !ok { - return echo.NewHTTPError(http.StatusBadRequest, "Missing creatorId to find memo") + return echo.NewHTTPError(http.StatusBadRequest, "Missing user id to find memo") } memoFind.CreatorID = &userID diff --git a/server/shortcut.go b/server/shortcut.go index 0adbffa9..3a8acb05 100644 --- a/server/shortcut.go +++ b/server/shortcut.go @@ -66,7 +66,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) { } else { userID, ok := c.Get(getUserIDContextKey()).(int) if !ok { - return echo.NewHTTPError(http.StatusBadRequest, "Missing creatorId to find shortcut") + return echo.NewHTTPError(http.StatusBadRequest, "Missing user id to find shortcut") } shortcutFind.CreatorID = &userID diff --git a/server/tag.go b/server/tag.go index a79b6105..0737d674 100644 --- a/server/tag.go +++ b/server/tag.go @@ -26,12 +26,19 @@ func (s *Server) registerTagRoutes(g *echo.Group) { } else { userID, ok := c.Get(getUserIDContextKey()).(int) if !ok { - return echo.NewHTTPError(http.StatusBadRequest, "Missing creatorId to find shortcut") + return echo.NewHTTPError(http.StatusBadRequest, "Missing user id to find tag") } memoFind.CreatorID = &userID } + // Only can get PUBLIC memos in visitor mode + _, ok := c.Get(getUserIDContextKey()).(int) + if !ok { + publicVisibility := api.Public + memoFind.Visibility = &publicVisibility + } + memoList, err := s.Store.FindMemoList(&memoFind) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find memo list").SetInternal(err) diff --git a/store/db/seed/10002__memo.sql b/store/db/seed/10002__memo.sql index 352c8e91..b0897323 100644 --- a/store/db/seed/10002__memo.sql +++ b/store/db/seed/10002__memo.sql @@ -7,8 +7,7 @@ INSERT INTO VALUES ( 101, - '#Hello 👋 Welcome to memos -![](https://api.star-history.com/svg?repos=usememos/memos&type=Date&size=mobile)', + '#Hello 👋 Welcome to memos', 101 ); @@ -25,8 +24,7 @@ VALUES - [ ] Take more photos about **🌄 sunset**; - [x] Clean the room; - [x] Read *📖 The Little Prince*; -(👆 click to toggle status) -', +(👆 click to toggle status)', 101 ); diff --git a/web/src/components/MemoList.tsx b/web/src/components/MemoList.tsx index ed4a83b4..40ce0649 100644 --- a/web/src/components/MemoList.tsx +++ b/web/src/components/MemoList.tsx @@ -101,13 +101,7 @@ const MemoList: React.FC = () => { ))}

- {isFetching - ? "Fetching data..." - : sortedMemos.length === 0 - ? "Oops, there is nothing" - : showMemoFilter - ? "" - : "Fetching completed 🎉"} + {isFetching ? "Fetching data..." : sortedMemos.length === 0 ? "No memos 🌃" : showMemoFilter ? "" : "All memos are ready 🎉"}

diff --git a/web/src/components/MenuBtnsPopup.tsx b/web/src/components/MenuBtnsPopup.tsx index 410986fb..53fa806b 100644 --- a/web/src/components/MenuBtnsPopup.tsx +++ b/web/src/components/MenuBtnsPopup.tsx @@ -1,8 +1,8 @@ import { useEffect, useRef } from "react"; import * as api from "../helpers/api"; import { locationService, userService } from "../services"; -import { useAppSelector } from "../store"; import toastHelper from "./Toast"; +import Only from "./common/OnlyWhen"; import showAboutSiteDialog from "./AboutSiteDialog"; import "../less/menu-btns-popup.less"; @@ -13,7 +13,6 @@ interface Props { const MenuBtnsPopup: React.FC = (props: Props) => { const { shownStatus, setShownStatus } = props; - const user = useAppSelector((state) => state.user.user); const popupElRef = useRef(null); useEffect(() => { @@ -65,19 +64,11 @@ const MenuBtnsPopup: React.FC = (props: Props) => { - {!userService.isVisitorMode() ? ( + - ) : user ? ( - - ) : ( - - )} + ); }; diff --git a/web/src/components/Sidebar.tsx b/web/src/components/Sidebar.tsx index bd2a83b5..f9a236fb 100644 --- a/web/src/components/Sidebar.tsx +++ b/web/src/components/Sidebar.tsx @@ -1,4 +1,5 @@ import { userService } from "../services"; +import { useAppSelector } from "../store"; import Only from "./common/OnlyWhen"; import showDailyReviewDialog from "./DailyReviewDialog"; import showSettingDialog from "./SettingDialog"; @@ -12,6 +13,8 @@ import "../less/siderbar.less"; interface Props {} const Sidebar: React.FC = () => { + const user = useAppSelector((state) => state.user.user); + const handleMyAccountBtnClick = () => { showSettingDialog(); }; @@ -29,18 +32,31 @@ const Sidebar: React.FC = () => { - -
- +
+ + - -
+ + + + {user ? ( + + ) : ( + + )} + +
+ diff --git a/web/src/less/memo-list.less b/web/src/less/memo-list.less index 1172f0e4..ec85e19f 100644 --- a/web/src/less/memo-list.less +++ b/web/src/less/memo-list.less @@ -1,33 +1,22 @@ @import "./mixin.less"; .memo-list-container { - .flex(column, flex-start, flex-start); - width: 100%; - max-width: 100%; - overflow-y: scroll; + @apply flex flex-col justify-start items-start w-full max-w-full overflow-y-scroll; .hide-scroll-bar(); > .status-text-container { - .flex(column, flex-start, center); - width: 100%; - margin-top: 16px; - margin-bottom: 16px; + @apply flex flex-col justify-start items-center w-full my-6; &.completed { - margin-bottom: 64px; - } - - &.invisible { - visibility: hidden; + @apply mb-16; } > .status-text { - font-size: 13px; - color: gray; + @apply text-sm text-gray-400 italic; } } &.completed { - @apply pb-40; + @apply pb-16; } } diff --git a/web/src/pages/Home.tsx b/web/src/pages/Home.tsx index 8c5d2dea..e7de74a4 100644 --- a/web/src/pages/Home.tsx +++ b/web/src/pages/Home.tsx @@ -1,6 +1,5 @@ import { useEffect } from "react"; import { locationService, userService } from "../services"; -import * as api from "../helpers/api"; import useLoading from "../hooks/useLoading"; import Only from "../components/common/OnlyWhen"; import Sidebar from "../components/Sidebar";