chore: update visitor view buttons

This commit is contained in:
boojack 2022-07-09 12:00:26 +08:00
parent 7418d2965d
commit 6a8c559e8c
10 changed files with 47 additions and 53 deletions

View File

@ -55,7 +55,7 @@ func removeUserSession(c echo.Context) error {
func BasicAuthMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc { func BasicAuthMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error { return func(c echo.Context) error {
// Skip auth for some paths. // 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) return next(c)
} }

View File

@ -70,7 +70,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
} else { } else {
userID, ok := c.Get(getUserIDContextKey()).(int) userID, ok := c.Get(getUserIDContextKey()).(int)
if !ok { 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 memoFind.CreatorID = &userID

View File

@ -66,7 +66,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
} else { } else {
userID, ok := c.Get(getUserIDContextKey()).(int) userID, ok := c.Get(getUserIDContextKey()).(int)
if !ok { 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 shortcutFind.CreatorID = &userID

View File

@ -26,12 +26,19 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
} else { } else {
userID, ok := c.Get(getUserIDContextKey()).(int) userID, ok := c.Get(getUserIDContextKey()).(int)
if !ok { 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 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) memoList, err := s.Store.FindMemoList(&memoFind)
if err != nil { if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find memo list").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find memo list").SetInternal(err)

View File

@ -7,8 +7,7 @@ INSERT INTO
VALUES VALUES
( (
101, 101,
'#Hello 👋 Welcome to memos '#Hello 👋 Welcome to memos',
![](https://api.star-history.com/svg?repos=usememos/memos&type=Date&size=mobile)',
101 101
); );
@ -25,8 +24,7 @@ VALUES
- [ ] Take more photos about **🌄 sunset**; - [ ] Take more photos about **🌄 sunset**;
- [x] Clean the room; - [x] Clean the room;
- [x] Read *📖 The Little Prince*; - [x] Read *📖 The Little Prince*;
(👆 click to toggle status) (👆 click to toggle status)',
',
101 101
); );

View File

@ -101,13 +101,7 @@ const MemoList: React.FC<Props> = () => {
))} ))}
<div className="status-text-container"> <div className="status-text-container">
<p className="status-text"> <p className="status-text">
{isFetching {isFetching ? "Fetching data..." : sortedMemos.length === 0 ? "No memos 🌃" : showMemoFilter ? "" : "All memos are ready 🎉"}
? "Fetching data..."
: sortedMemos.length === 0
? "Oops, there is nothing"
: showMemoFilter
? ""
: "Fetching completed 🎉"}
</p> </p>
</div> </div>
</div> </div>

View File

@ -1,8 +1,8 @@
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
import * as api from "../helpers/api"; import * as api from "../helpers/api";
import { locationService, userService } from "../services"; import { locationService, userService } from "../services";
import { useAppSelector } from "../store";
import toastHelper from "./Toast"; import toastHelper from "./Toast";
import Only from "./common/OnlyWhen";
import showAboutSiteDialog from "./AboutSiteDialog"; import showAboutSiteDialog from "./AboutSiteDialog";
import "../less/menu-btns-popup.less"; import "../less/menu-btns-popup.less";
@ -13,7 +13,6 @@ interface Props {
const MenuBtnsPopup: React.FC<Props> = (props: Props) => { const MenuBtnsPopup: React.FC<Props> = (props: Props) => {
const { shownStatus, setShownStatus } = props; const { shownStatus, setShownStatus } = props;
const user = useAppSelector((state) => state.user.user);
const popupElRef = useRef<HTMLDivElement>(null); const popupElRef = useRef<HTMLDivElement>(null);
useEffect(() => { useEffect(() => {
@ -65,19 +64,11 @@ const MenuBtnsPopup: React.FC<Props> = (props: Props) => {
<button className="btn action-btn" onClick={handlePingBtnClick}> <button className="btn action-btn" onClick={handlePingBtnClick}>
<span className="icon">🎯</span> Ping <span className="icon">🎯</span> Ping
</button> </button>
{!userService.isVisitorMode() ? ( <Only when={!userService.isVisitorMode()}>
<button className="btn action-btn" onClick={handleSignOutBtnClick}> <button className="btn action-btn" onClick={handleSignOutBtnClick}>
<span className="icon">👋</span> Sign out <span className="icon">👋</span> Sign out
</button> </button>
) : user ? ( </Only>
<button className="btn action-btn" onClick={() => (window.location.href = "/")}>
<span className="icon">🏠</span> Go Back
</button>
) : (
<button className="btn action-btn" onClick={() => (window.location.href = "/signin")}>
<span className="icon">👉</span> Sign in
</button>
)}
</div> </div>
); );
}; };

View File

@ -1,4 +1,5 @@
import { userService } from "../services"; import { userService } from "../services";
import { useAppSelector } from "../store";
import Only from "./common/OnlyWhen"; import Only from "./common/OnlyWhen";
import showDailyReviewDialog from "./DailyReviewDialog"; import showDailyReviewDialog from "./DailyReviewDialog";
import showSettingDialog from "./SettingDialog"; import showSettingDialog from "./SettingDialog";
@ -12,6 +13,8 @@ import "../less/siderbar.less";
interface Props {} interface Props {}
const Sidebar: React.FC<Props> = () => { const Sidebar: React.FC<Props> = () => {
const user = useAppSelector((state) => state.user.user);
const handleMyAccountBtnClick = () => { const handleMyAccountBtnClick = () => {
showSettingDialog(); showSettingDialog();
}; };
@ -29,18 +32,31 @@ const Sidebar: React.FC<Props> = () => {
</div> </div>
<UserBanner /> <UserBanner />
<UsageHeatMap /> <UsageHeatMap />
<Only when={!userService.isVisitorMode()}> <div className="action-btns-container">
<div className="action-btns-container"> <button className="btn action-btn" onClick={() => showDailyReviewDialog()}>
<button className="btn action-btn" onClick={() => showDailyReviewDialog()}> <span className="icon">📅</span> Daily Review
<span className="icon">📅</span> Daily Review </button>
</button> <Only when={!userService.isVisitorMode()}>
<button className="btn action-btn" onClick={handleMyAccountBtnClick}> <button className="btn action-btn" onClick={handleMyAccountBtnClick}>
<span className="icon"></span> Setting <span className="icon"></span> Setting
</button> </button>
<button className="btn action-btn" onClick={handleArchivedBtnClick}> </Only>
<span className="icon">🗂</span> Archived <button className="btn action-btn" onClick={handleArchivedBtnClick}>
</button> <span className="icon">🗂</span> Archived
</div> </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 /> <ShortcutList />
</Only> </Only>
<TagList /> <TagList />

View File

@ -1,33 +1,22 @@
@import "./mixin.less"; @import "./mixin.less";
.memo-list-container { .memo-list-container {
.flex(column, flex-start, flex-start); @apply flex flex-col justify-start items-start w-full max-w-full overflow-y-scroll;
width: 100%;
max-width: 100%;
overflow-y: scroll;
.hide-scroll-bar(); .hide-scroll-bar();
> .status-text-container { > .status-text-container {
.flex(column, flex-start, center); @apply flex flex-col justify-start items-center w-full my-6;
width: 100%;
margin-top: 16px;
margin-bottom: 16px;
&.completed { &.completed {
margin-bottom: 64px; @apply mb-16;
}
&.invisible {
visibility: hidden;
} }
> .status-text { > .status-text {
font-size: 13px; @apply text-sm text-gray-400 italic;
color: gray;
} }
} }
&.completed { &.completed {
@apply pb-40; @apply pb-16;
} }
} }

View File

@ -1,6 +1,5 @@
import { useEffect } from "react"; import { useEffect } from "react";
import { locationService, userService } from "../services"; import { locationService, userService } from "../services";
import * as api from "../helpers/api";
import useLoading from "../hooks/useLoading"; import useLoading from "../hooks/useLoading";
import Only from "../components/common/OnlyWhen"; import Only from "../components/common/OnlyWhen";
import Sidebar from "../components/Sidebar"; import Sidebar from "../components/Sidebar";