mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update detail styles
This commit is contained in:
@ -7,6 +7,7 @@ import * as storage from "./helpers/storage";
|
|||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const { setLocale } = useI18n();
|
const { setLocale } = useI18n();
|
||||||
|
const user = useAppSelector((state) => state.user.user);
|
||||||
const global = useAppSelector((state) => state.global);
|
const global = useAppSelector((state) => state.global);
|
||||||
const pathname = useAppSelector((state) => state.location.pathname);
|
const pathname = useAppSelector((state) => state.location.pathname);
|
||||||
const [isLoading, setLoading] = useState(true);
|
const [isLoading, setLoading] = useState(true);
|
||||||
@ -21,12 +22,18 @@ function App() {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (user?.setting.locale) {
|
||||||
|
globalService.setLocale(user.setting.locale);
|
||||||
|
}
|
||||||
|
}, [user?.setting.locale]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLocale(global.locale);
|
setLocale(global.locale);
|
||||||
storage.set({
|
storage.set({
|
||||||
locale: global.locale,
|
locale: global.locale,
|
||||||
});
|
});
|
||||||
}, [global]);
|
}, [global.locale]);
|
||||||
|
|
||||||
return <>{isLoading ? null : appRouterSwitch(pathname)}</>;
|
return <>{isLoading ? null : appRouterSwitch(pathname)}</>;
|
||||||
}
|
}
|
||||||
|
@ -45,15 +45,16 @@ const Memo: React.FC<Props> = (props: Props) => {
|
|||||||
});
|
});
|
||||||
const [createdAtStr, setCreatedAtStr] = useState<string>(getFormatedMemoCreatedAtStr(memo.createdTs, locale));
|
const [createdAtStr, setCreatedAtStr] = useState<string>(getFormatedMemoCreatedAtStr(memo.createdTs, locale));
|
||||||
const memoContainerRef = useRef<HTMLDivElement>(null);
|
const memoContainerRef = useRef<HTMLDivElement>(null);
|
||||||
|
const memoContentContainerRef = useRef<HTMLDivElement>(null);
|
||||||
const imageUrls = Array.from(memo.content.match(IMAGE_URL_REG) ?? []).map((s) => s.replace(IMAGE_URL_REG, "$1"));
|
const imageUrls = Array.from(memo.content.match(IMAGE_URL_REG) ?? []).map((s) => s.replace(IMAGE_URL_REG, "$1"));
|
||||||
const isVisitorMode = userService.isVisitorMode();
|
const isVisitorMode = userService.isVisitorMode();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!memoContainerRef) {
|
if (!memoContentContainerRef) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Number(memoContainerRef.current?.clientHeight) > MAX_MEMO_CONTAINER_HEIGHT) {
|
if (Number(memoContentContainerRef.current?.clientHeight) > MAX_MEMO_CONTAINER_HEIGHT) {
|
||||||
setState({
|
setState({
|
||||||
...state,
|
...state,
|
||||||
expandButtonStatus: 0,
|
expandButtonStatus: 0,
|
||||||
@ -143,7 +144,7 @@ const Memo: React.FC<Props> = (props: Props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const status = targetEl.dataset?.value;
|
const status = targetEl.dataset?.value;
|
||||||
const todoElementList = [...(memoContainerRef.current?.querySelectorAll(`span.todo-block[data-value=${status}]`) ?? [])];
|
const todoElementList = [...(memoContentContainerRef.current?.querySelectorAll(`span.todo-block[data-value=${status}]`) ?? [])];
|
||||||
for (const element of todoElementList) {
|
for (const element of todoElementList) {
|
||||||
if (element === targetEl) {
|
if (element === targetEl) {
|
||||||
const index = indexOf(todoElementList, element);
|
const index = indexOf(todoElementList, element);
|
||||||
@ -172,13 +173,18 @@ const Memo: React.FC<Props> = (props: Props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleExpandBtnClick = () => {
|
const handleExpandBtnClick = () => {
|
||||||
|
const expandButtonStatus = Boolean(!state.expandButtonStatus);
|
||||||
|
if (!expandButtonStatus) {
|
||||||
|
memoContainerRef.current?.scrollIntoView();
|
||||||
|
}
|
||||||
|
|
||||||
setState({
|
setState({
|
||||||
expandButtonStatus: Number(Boolean(!state.expandButtonStatus)) as ExpandButtonStatus,
|
expandButtonStatus: Number(expandButtonStatus) as ExpandButtonStatus,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`memo-wrapper ${"memos-" + memo.id} ${memo.pinned ? "pinned" : ""}`}>
|
<div className={`memo-wrapper ${"memos-" + memo.id} ${memo.pinned ? "pinned" : ""}`} ref={memoContainerRef}>
|
||||||
<div className="memo-top-wrapper">
|
<div className="memo-top-wrapper">
|
||||||
<div className="status-text-container" onClick={handleShowMemoStoryDialog}>
|
<div className="status-text-container" onClick={handleShowMemoStoryDialog}>
|
||||||
<span className="time-text">{createdAtStr}</span>
|
<span className="time-text">{createdAtStr}</span>
|
||||||
@ -220,7 +226,7 @@ const Memo: React.FC<Props> = (props: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
ref={memoContainerRef}
|
ref={memoContentContainerRef}
|
||||||
className={`memo-content-text ${state.expandButtonStatus === 0 ? "expanded" : ""}`}
|
className={`memo-content-text ${state.expandButtonStatus === 0 ? "expanded" : ""}`}
|
||||||
onClick={handleMemoContentClick}
|
onClick={handleMemoContentClick}
|
||||||
dangerouslySetInnerHTML={{ __html: formatMemoContent(memo.content) }}
|
dangerouslySetInnerHTML={{ __html: formatMemoContent(memo.content) }}
|
||||||
|
@ -1,19 +1,21 @@
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { memoService, shortcutService } from "../services";
|
import { memoService, shortcutService } from "../services";
|
||||||
|
import useI18n from "../hooks/useI18n";
|
||||||
import { useAppSelector } from "../store";
|
import { useAppSelector } from "../store";
|
||||||
import { IMAGE_URL_REG, LINK_URL_REG, MEMO_LINK_REG, TAG_REG } from "../helpers/consts";
|
import { IMAGE_URL_REG, LINK_URL_REG, MEMO_LINK_REG, TAG_REG } from "../helpers/consts";
|
||||||
import * as utils from "../helpers/utils";
|
import * as utils from "../helpers/utils";
|
||||||
import { checkShouldShowMemoWithFilters } from "../helpers/filter";
|
import { checkShouldShowMemoWithFilters } from "../helpers/filter";
|
||||||
import toastHelper from "./Toast";
|
import toastHelper from "./Toast";
|
||||||
|
import Only from "./common/OnlyWhen";
|
||||||
import Memo from "./Memo";
|
import Memo from "./Memo";
|
||||||
import "../less/memo-list.less";
|
import "../less/memo-list.less";
|
||||||
|
|
||||||
interface Props {}
|
interface Props {}
|
||||||
|
|
||||||
const MemoList: React.FC<Props> = () => {
|
const MemoList: React.FC<Props> = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
const query = useAppSelector((state) => state.location.query);
|
const query = useAppSelector((state) => state.location.query);
|
||||||
const memos = useAppSelector((state) => state.memo.memos);
|
const { memos, isFetching } = useAppSelector((state) => state.memo);
|
||||||
const [isFetching, setFetchStatus] = useState(true);
|
|
||||||
const wrapperElement = useRef<HTMLDivElement>(null);
|
const wrapperElement = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const { tag: tagQuery, duration, type: memoType, text: textQuery, shortcutId } = query ?? {};
|
const { tag: tagQuery, duration, type: memoType, text: textQuery, shortcutId } = query ?? {};
|
||||||
@ -82,7 +84,7 @@ const MemoList: React.FC<Props> = () => {
|
|||||||
memoService
|
memoService
|
||||||
.fetchAllMemos()
|
.fetchAllMemos()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
setFetchStatus(false);
|
// do nth
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -91,19 +93,26 @@ const MemoList: React.FC<Props> = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
wrapperElement.current?.scrollTo({ top: 0 });
|
wrapperElement.current?.scrollTo({
|
||||||
|
top: 0,
|
||||||
|
});
|
||||||
}, [query]);
|
}, [query]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`memo-list-container ${isFetching ? "" : "completed"}`} ref={wrapperElement}>
|
<div className={`memo-list-container ${isFetching ? "" : "completed"}`} ref={wrapperElement}>
|
||||||
|
<Only when={isFetching}>
|
||||||
|
<div className="status-text-container fetching-tip">
|
||||||
|
<p className="status-text">{t("memo-list.fetching-data")}</p>
|
||||||
|
</div>
|
||||||
|
</Only>
|
||||||
{sortedMemos.map((memo) => (
|
{sortedMemos.map((memo) => (
|
||||||
<Memo key={`${memo.id}-${memo.createdTs}-${memo.updatedTs}`} memo={memo} />
|
<Memo key={`${memo.id}-${memo.createdTs}-${memo.updatedTs}`} memo={memo} />
|
||||||
))}
|
))}
|
||||||
<div className="status-text-container">
|
<Only when={!isFetching}>
|
||||||
<p className="status-text">
|
<div className="status-text-container">
|
||||||
{isFetching ? "Fetching data..." : sortedMemos.length === 0 ? "No memos 🌃" : showMemoFilter ? "" : "All memos are ready 🎉"}
|
<p className="status-text">{sortedMemos.length === 0 ? "no memos 🌃" : showMemoFilter ? "" : "all memos are ready 🎉"}</p>
|
||||||
</p>
|
</div>
|
||||||
</div>
|
</Only>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -29,7 +29,7 @@ const MemosHeader: React.FC<Props> = () => {
|
|||||||
|
|
||||||
const handleTitleTextClick = useCallback(() => {
|
const handleTitleTextClick = useCallback(() => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (now - prevRequestTimestamp > 10 * 1000) {
|
if (now - prevRequestTimestamp > 1 * 1000) {
|
||||||
prevRequestTimestamp = now;
|
prevRequestTimestamp = now;
|
||||||
memoService.fetchAllMemos().catch(() => {
|
memoService.fetchAllMemos().catch(() => {
|
||||||
// do nth
|
// do nth
|
||||||
|
@ -35,8 +35,8 @@ const PreferencesSection: React.FC<Props> = () => {
|
|||||||
const { setting } = useAppSelector((state) => state.user.user as User);
|
const { setting } = useAppSelector((state) => state.user.user as User);
|
||||||
|
|
||||||
const handleLocaleChanged = async (value: string) => {
|
const handleLocaleChanged = async (value: string) => {
|
||||||
globalService.setLocale(value as Locale);
|
|
||||||
await userService.upsertUserSetting("locale", value);
|
await userService.upsertUserSetting("locale", value);
|
||||||
|
globalService.setLocale(value as Locale);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDefaultMemoVisibilityChanged = async (value: string) => {
|
const handleDefaultMemoVisibilityChanged = async (value: string) => {
|
||||||
@ -49,16 +49,17 @@ const PreferencesSection: React.FC<Props> = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="section-container preferences-section-container">
|
<div className="section-container preferences-section-container">
|
||||||
<p className="title-text">{t("common.language")}</p>
|
<p className="title-text">{t("common.basic")}</p>
|
||||||
<label className="form-label selector">
|
<label className="form-label selector">
|
||||||
<span className="normal-text">
|
<span className="normal-text">
|
||||||
{t("common.language")}: <BetaBadge className="ml-2" />
|
{t("common.language")}
|
||||||
|
<BetaBadge className="ml-2" />
|
||||||
</span>
|
</span>
|
||||||
<Selector className="ml-2 w-28" value={setting.locale} dataSource={localeSelectorItems} handleValueChanged={handleLocaleChanged} />
|
<Selector className="ml-2 w-32" value={setting.locale} dataSource={localeSelectorItems} handleValueChanged={handleLocaleChanged} />
|
||||||
</label>
|
</label>
|
||||||
<p className="title-text">{t("setting.preference")}</p>
|
<p className="title-text">{t("setting.preference")}</p>
|
||||||
<label className="form-label selector">
|
<label className="form-label selector">
|
||||||
<span className="normal-text">{t("setting.preference-section.default-memo-visibility")}:</span>
|
<span className="normal-text">{t("setting.preference-section.default-memo-visibility")}</span>
|
||||||
<Selector
|
<Selector
|
||||||
className="ml-2 w-32"
|
className="ml-2 w-32"
|
||||||
value={setting.memoVisibility}
|
value={setting.memoVisibility}
|
||||||
@ -67,7 +68,7 @@ const PreferencesSection: React.FC<Props> = () => {
|
|||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<label className="form-label selector">
|
<label className="form-label selector">
|
||||||
<span className="normal-text">{t("setting.preference-section.editor-font-style")}:</span>
|
<span className="normal-text">{t("setting.preference-section.editor-font-style")}</span>
|
||||||
<Selector
|
<Selector
|
||||||
className="ml-2 w-32"
|
className="ml-2 w-32"
|
||||||
value={setting.editorFontStyle}
|
value={setting.editorFontStyle}
|
||||||
|
@ -77,7 +77,7 @@
|
|||||||
@apply w-full inline-block float-right text-sm mt-4 text-gray-500 text-right whitespace-pre-wrap;
|
@apply w-full inline-block float-right text-sm mt-4 text-gray-500 text-right whitespace-pre-wrap;
|
||||||
|
|
||||||
&.host-tip {
|
&.host-tip {
|
||||||
@apply bg-blue-500 text-white px-2 py-1 rounded;
|
@apply text-blue-600;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
.beta-badge {
|
.beta-badge {
|
||||||
@apply px-2 text-xs border rounded-lg text-gray-400;
|
@apply px-2 py-1 text-xs border rounded-full text-gray-500;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
@import "../mixin.less";
|
@import "../mixin.less";
|
||||||
|
|
||||||
.selector-wrapper {
|
.selector-wrapper {
|
||||||
@apply flex flex-col justify-start items-start relative h-7;
|
@apply flex flex-col justify-start items-start relative h-8;
|
||||||
|
|
||||||
> .current-value-container {
|
> .current-value-container {
|
||||||
@apply flex flex-row justify-between items-center w-full h-full rounded px-2 pr-1 bg-white border cursor-pointer select-none;
|
@apply flex flex-row justify-between items-center w-full h-full rounded px-2 pr-1 bg-white border cursor-pointer select-none;
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
> .status-text-container {
|
> .status-text-container {
|
||||||
@apply flex flex-col justify-start items-center w-full my-6;
|
@apply flex flex-col justify-start items-center w-full my-6;
|
||||||
|
|
||||||
&.completed {
|
&.fetching-tip {
|
||||||
@apply mb-16;
|
@apply mt-2 mb-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
> .status-text {
|
> .status-text {
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
@apply w-full sm:w-44 h-auto sm:h-full shrink-0 rounded-t-lg sm:rounded-none sm:rounded-l-lg p-4 border-r bg-gray-100 flex flex-col justify-start items-start;
|
@apply w-full sm:w-44 h-auto sm:h-full shrink-0 rounded-t-lg sm:rounded-none sm:rounded-l-lg p-4 border-r bg-gray-100 flex flex-col justify-start items-start;
|
||||||
|
|
||||||
> .section-title {
|
> .section-title {
|
||||||
@apply text-sm mt-2 sm:mt-4 first:mt-3 mb-1 font-mono text-gray-400;
|
@apply text-sm mt-2 sm:mt-4 first:mt-4 mb-1 font-mono text-gray-400;
|
||||||
}
|
}
|
||||||
|
|
||||||
> .section-items-container {
|
> .section-items-container {
|
||||||
@ -46,7 +46,7 @@
|
|||||||
@apply flex flex-col justify-start items-start w-full my-2;
|
@apply flex flex-col justify-start items-start w-full my-2;
|
||||||
|
|
||||||
> .title-text {
|
> .title-text {
|
||||||
@apply text-sm mb-3 font-mono text-gray-500;
|
@apply text-sm mt-4 first:mt-2 mb-3 font-mono text-gray-500;
|
||||||
}
|
}
|
||||||
|
|
||||||
> .form-label {
|
> .form-label {
|
||||||
|
@ -46,6 +46,9 @@
|
|||||||
"memo": {
|
"memo": {
|
||||||
"view-story": "View Story"
|
"view-story": "View Story"
|
||||||
},
|
},
|
||||||
|
"memo-list": {
|
||||||
|
"fetching-data": "fetching data..."
|
||||||
|
},
|
||||||
"tag-list": {
|
"tag-list": {
|
||||||
"tip-text": "Enter `#tag ` to create"
|
"tip-text": "Enter `#tag ` to create"
|
||||||
},
|
},
|
||||||
|
@ -46,6 +46,9 @@
|
|||||||
"memo": {
|
"memo": {
|
||||||
"view-story": "查看详情"
|
"view-story": "查看详情"
|
||||||
},
|
},
|
||||||
|
"memo-list": {
|
||||||
|
"fetching-data": "请求数据中..."
|
||||||
|
},
|
||||||
"tag-list": {
|
"tag-list": {
|
||||||
"tip-text": "输入`#tag `来创建标签"
|
"tip-text": "输入`#tag `来创建标签"
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as api from "../helpers/api";
|
import * as api from "../helpers/api";
|
||||||
import { createMemo, patchMemo, setMemos, setTags } from "../store/modules/memo";
|
import { createMemo, patchMemo, setIsFetching, setMemos, setTags } from "../store/modules/memo";
|
||||||
import store from "../store";
|
import store from "../store";
|
||||||
import userService from "./userService";
|
import userService from "./userService";
|
||||||
|
|
||||||
@ -17,6 +17,9 @@ const memoService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
fetchAllMemos: async () => {
|
fetchAllMemos: async () => {
|
||||||
|
const timeoutIndex = setTimeout(() => {
|
||||||
|
store.dispatch(setIsFetching(true));
|
||||||
|
}, 1000);
|
||||||
const memoFind: MemoFind = {};
|
const memoFind: MemoFind = {};
|
||||||
if (userService.isVisitorMode()) {
|
if (userService.isVisitorMode()) {
|
||||||
memoFind.creatorId = userService.getUserIdFromPath();
|
memoFind.creatorId = userService.getUserIdFromPath();
|
||||||
@ -24,6 +27,8 @@ const memoService = {
|
|||||||
const { data } = (await api.getMemoList(memoFind)).data;
|
const { data } = (await api.getMemoList(memoFind)).data;
|
||||||
const memos = data.filter((m) => m.rowStatus !== "ARCHIVED").map((m) => convertResponseModelMemo(m));
|
const memos = data.filter((m) => m.rowStatus !== "ARCHIVED").map((m) => convertResponseModelMemo(m));
|
||||||
store.dispatch(setMemos(memos));
|
store.dispatch(setMemos(memos));
|
||||||
|
clearTimeout(timeoutIndex);
|
||||||
|
store.dispatch(setIsFetching(false));
|
||||||
|
|
||||||
return memos;
|
return memos;
|
||||||
},
|
},
|
||||||
|
@ -3,6 +3,7 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
|||||||
interface State {
|
interface State {
|
||||||
memos: Memo[];
|
memos: Memo[];
|
||||||
tags: string[];
|
tags: string[];
|
||||||
|
isFetching: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const memoSlice = createSlice({
|
const memoSlice = createSlice({
|
||||||
@ -10,6 +11,7 @@ const memoSlice = createSlice({
|
|||||||
initialState: {
|
initialState: {
|
||||||
memos: [],
|
memos: [],
|
||||||
tags: [],
|
tags: [],
|
||||||
|
isFetching: false,
|
||||||
} as State,
|
} as State,
|
||||||
reducers: {
|
reducers: {
|
||||||
setMemos: (state, action: PayloadAction<Memo[]>) => {
|
setMemos: (state, action: PayloadAction<Memo[]>) => {
|
||||||
@ -47,9 +49,15 @@ const memoSlice = createSlice({
|
|||||||
tags: action.payload,
|
tags: action.payload,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
setIsFetching: (state, action: PayloadAction<boolean>) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isFetching: action.payload,
|
||||||
|
};
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const { setMemos, setTags, createMemo, patchMemo } = memoSlice.actions;
|
export const { setMemos, createMemo, patchMemo, setTags, setIsFetching } = memoSlice.actions;
|
||||||
|
|
||||||
export default memoSlice.reducer;
|
export default memoSlice.reducer;
|
||||||
|
Reference in New Issue
Block a user