Skip to content

Add the "compact mode" memo view setting - dictates weather the memos will get compacted by default or not #4705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions web/src/components/MemoContent/index.tsx
Original file line number Diff line number Diff line change
@@ -41,17 +41,16 @@ const MemoContent: React.FC<Props> = (props: Props) => {

// Initial compact mode.
useEffect(() => {
if (!props.compact) {
return;
}
if (!memoContentContainerRef.current) {
return;
}

if ((memoContentContainerRef.current as HTMLDivElement).getBoundingClientRect().height > MAX_DISPLAY_HEIGHT) {
if (props.compact && (memoContentContainerRef.current as HTMLDivElement).getBoundingClientRect().height > MAX_DISPLAY_HEIGHT) {
setShowCompactMode("ALL");
} else if (showCompactMode !== undefined) {
setShowCompactMode("SNIPPET");
}
}, []);
}, [props.compact]);

const onMemoContentClick = async (e: React.MouseEvent) => {
if (onClick) {
16 changes: 15 additions & 1 deletion web/src/components/MemoDisplaySettingMenu.tsx
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ interface Props {

const MemoDisplaySettingMenu = observer(({ className }: Props) => {
const t = useTranslate();
const isApplying = viewStore.state.orderByTimeAsc !== false || viewStore.state.layout !== "LIST";
const isApplying = viewStore.state.orderByTimeAsc !== false || viewStore.state.layout !== "LIST" || viewStore.state.compact !== true;

return (
<Popover>
@@ -51,6 +51,20 @@ const MemoDisplaySettingMenu = observer(({ className }: Props) => {
<Option value={"MASONRY"}>{t("memo.masonry")}</Option>
</Select>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span className="text-sm shrink-0 mr-3">{t("memo.compact")}</span>
<Select
value={viewStore.state.compact}
onChange={(_, value) =>
viewStore.state.setPartial({
compact: Boolean(value),
})
}
>
<Option value={false}>{t("memo.disable")}</Option>
<Option value={true}>{t("memo.enable")}</Option>
</Select>
</div>
</div>
</PopoverContent>
</Popover>
3 changes: 3 additions & 0 deletions web/src/locales/en.json
Original file line number Diff line number Diff line change
@@ -143,6 +143,9 @@
"direction": "Direction",
"direction-asc": "Ascending",
"direction-desc": "Descending",
"compact": "Compact View",
"enable": "Enable",
"disable": "Disable",
"display-time": "Display Time",
"filters": "Filters",
"links": "Links",
6 changes: 4 additions & 2 deletions web/src/pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -46,11 +46,13 @@ const Home = observer(() => {
conditions.push(`tag_search == [${tagSearch.join(", ")}]`);
}
return conditions.join(" && ");
}, [user, memoFilterStore.filters, viewStore.state.orderByTimeAsc]);
}, [user, memoFilterStore.filters, viewStore.state.compact, viewStore.state.orderByTimeAsc]);

return (
<PagedMemoList
renderer={(memo: Memo) => <MemoView key={`${memo.name}-${memo.displayTime}`} memo={memo} showVisibility showPinned compact />}
renderer={(memo: Memo) => (
<MemoView key={`${memo.name}-${memo.displayTime}`} memo={memo} showVisibility showPinned compact={viewStore.state.compact} />
)}
listSort={(memos: Memo[]) =>
memos
.filter((memo) => memo.state === State.NORMAL)
4 changes: 4 additions & 0 deletions web/src/store/v2/view.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ const LOCAL_STORAGE_KEY = "memos-view-setting";
class LocalState {
orderByTimeAsc: boolean = false;
layout: "LIST" | "MASONRY" = "LIST";
compact: boolean = true;

constructor() {
makeAutoObservable(this);
@@ -36,6 +37,9 @@ const viewStore = (() => {
if (Object.hasOwn(cache, "orderByTimeAsc")) {
viewStore.state.setPartial({ orderByTimeAsc: Boolean(cache.orderByTimeAsc) });
}
if (Object.hasOwn(cache, "compact")) {
viewStore.state.setPartial({ compact: Boolean(cache.compact) });
}
if (Object.hasOwn(cache, "layout")) {
if (["LIST", "MASONRY"].includes(cache.layout)) {
viewStore.state.setPartial({ layout: cache.layout });