feat: add auto collapse feature for all memos issue #1463 (#1550)

* add auto collapse feature

* fix some styles

* pass eslint

---------

Co-authored-by: liyang <liyangg@umich.edu>
This commit is contained in:
Yang 2023-04-17 22:05:36 -04:00 committed by GitHub
parent 0aa7085303
commit 685a23bce8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 57 additions and 20 deletions

3
web/.gitignore vendored
View File

@ -7,4 +7,5 @@ dist-ssr
/test-results/ /test-results/
/playwright-report/ /playwright-report/
/playwright/.cache/ /playwright/.cache/
/playwright-screenshot/ /playwright-screenshot/

View File

@ -1,6 +1,7 @@
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { marked } from "@/labs/marked"; import { marked } from "@/labs/marked";
import { useUserStore } from "@/store/module";
import Icon from "./Icon"; import Icon from "./Icon";
import "@/less/memo-content.less"; import "@/less/memo-content.less";
@ -29,6 +30,10 @@ const MemoContent: React.FC<Props> = (props: Props) => {
}); });
const memoContentContainerRef = useRef<HTMLDivElement>(null); const memoContentContainerRef = useRef<HTMLDivElement>(null);
//variable for auto-collapse
const userStore = useUserStore();
const { localSetting } = userStore.state.user as User;
useEffect(() => { useEffect(() => {
if (showFull) { if (showFull) {
return; return;
@ -67,13 +72,15 @@ const MemoContent: React.FC<Props> = (props: Props) => {
<div className={`memo-content-wrapper ${className || ""}`}> <div className={`memo-content-wrapper ${className || ""}`}>
<div <div
ref={memoContentContainerRef} ref={memoContentContainerRef}
className={`memo-content-text ${state.expandButtonStatus === 0 ? "max-h-64 overflow-y-hidden" : ""}`} className={`memo-content-text ${
localSetting.enableAutoCollapse && state.expandButtonStatus === 0 ? "max-h-64 overflow-y-hidden" : ""
}`}
onClick={handleMemoContentClick} onClick={handleMemoContentClick}
onDoubleClick={handleMemoContentDoubleClick} onDoubleClick={handleMemoContentDoubleClick}
> >
{marked(content)} {marked(content)}
</div> </div>
{state.expandButtonStatus !== -1 && ( {localSetting.enableAutoCollapse && state.expandButtonStatus !== -1 && (
<div className={`expand-btn-container ${state.expandButtonStatus === 0 && "!-mt-7"}`}> <div className={`expand-btn-container ${state.expandButtonStatus === 0 && "!-mt-7"}`}>
<div className="absolute top-0 left-0 w-full h-full blur-lg bg-white dark:bg-zinc-700"></div> <div className="absolute top-0 left-0 w-full h-full blur-lg bg-white dark:bg-zinc-700"></div>
<span className={`btn z-10 ${state.expandButtonStatus === 0 ? "expand-btn" : "fold-btn"}`} onClick={handleExpandBtnClick}> <span className={`btn z-10 ${state.expandButtonStatus === 0 ? "expand-btn" : "fold-btn"}`} onClick={handleExpandBtnClick}>

View File

@ -44,6 +44,11 @@ const PreferencesSection = () => {
userStore.upsertLocalSetting({ ...localSetting, dailyReviewTimeOffset: value }); userStore.upsertLocalSetting({ ...localSetting, dailyReviewTimeOffset: value });
}; };
//enableAutoCollapse
const handleAutoCollapseChanged = (event: React.ChangeEvent<HTMLInputElement>) => {
userStore.upsertLocalSetting({ ...localSetting, enableAutoCollapse: event.target.checked });
};
return ( return (
<div className="section-container preferences-section-container"> <div className="section-container preferences-section-container">
<p className="title-text">{t("common.basic")}</p> <p className="title-text">{t("common.basic")}</p>
@ -108,6 +113,11 @@ const PreferencesSection = () => {
<span className="normal-text">{t("setting.preference-section.enable-double-click")}</span> <span className="normal-text">{t("setting.preference-section.enable-double-click")}</span>
<Switch className="ml-2" checked={localSetting.enableDoubleClickEditing} onChange={handleDoubleClickEnabledChanged} /> <Switch className="ml-2" checked={localSetting.enableDoubleClickEditing} onChange={handleDoubleClickEnabledChanged} />
</label> </label>
<label className="form-label selector">
<span className="normal-text">{t("setting.preference-section.auto-collapse")}</span>
<Switch className="ml-2" checked={localSetting.enableAutoCollapse} onChange={handleAutoCollapseChanged} />
</label>
</div> </div>
); );
}; };

View File

@ -166,7 +166,8 @@
"default-memo-sort-option": "Angezeigter Memo-Zeitpunkt", "default-memo-sort-option": "Angezeigter Memo-Zeitpunkt",
"created_ts": "Erstellungszeitpunkt", "created_ts": "Erstellungszeitpunkt",
"updated_ts": "Änderungszeitpunkt", "updated_ts": "Änderungszeitpunkt",
"enable-double-click": "Enable double-click to edit" "enable-double-click": "Doppelklick zum Bearbeiten aktivieren",
"auto-collapse": "Automatisch reduzieren"
}, },
"member-section": { "member-section": {
"create-a-member": "Mitglied hinzufügen" "create-a-member": "Mitglied hinzufügen"

View File

@ -187,7 +187,8 @@
"default-memo-sort-option": "Memo display time", "default-memo-sort-option": "Memo display time",
"created_ts": "Created Time", "created_ts": "Created Time",
"updated_ts": "Updated Time", "updated_ts": "Updated Time",
"daily-review-time-offset": "Daily Review Time Offset" "daily-review-time-offset": "Daily Review Time Offset",
"auto-collapse": "Auto Collapse"
}, },
"storage-section": { "storage-section": {
"current-storage": "Current storage", "current-storage": "Current storage",

View File

@ -166,7 +166,8 @@
"default-memo-sort-option": "Hora de visualización de la nota", "default-memo-sort-option": "Hora de visualización de la nota",
"created_ts": "Hora de Creación", "created_ts": "Hora de Creación",
"updated_ts": "Hora de Actualización", "updated_ts": "Hora de Actualización",
"enable-double-click": "Habilitar doble clic para editar" "enable-double-click": "Habilitar doble clic para editar",
"auto-collapse": "Colapso automático"
}, },
"member-section": { "member-section": {
"create-a-member": "Crear un miembro" "create-a-member": "Crear un miembro"

View File

@ -166,7 +166,8 @@
"default-memo-sort-option": "Memo display time", "default-memo-sort-option": "Memo display time",
"created_ts": "Heure de création", "created_ts": "Heure de création",
"updated_ts": "Heure de mise à jour", "updated_ts": "Heure de mise à jour",
"enable-double-click": "Enable double-click to edit" "enable-double-click": "Activer le double-clic",
"auto-collapse": "Réduction automatique"
}, },
"member-section": { "member-section": {
"create-a-member": "Créer un membre" "create-a-member": "Créer un membre"

View File

@ -166,7 +166,8 @@
"default-memo-sort-option": "Ordine visualizzazione memo", "default-memo-sort-option": "Ordine visualizzazione memo",
"created_ts": "Data di creazione", "created_ts": "Data di creazione",
"updated_ts": "Ultima modifica", "updated_ts": "Ultima modifica",
"enable-double-click": "Enable double-click to edit" "enable-double-click": "Abilita il doppio clic",
"auto-collapse": "Comprimi automaticamente"
}, },
"member-section": { "member-section": {
"create-a-member": "Crea un membro" "create-a-member": "Crea un membro"

View File

@ -164,7 +164,8 @@
"default-memo-sort-option": "메모에 표시할 시각", "default-memo-sort-option": "메모에 표시할 시각",
"created_ts": "생성된 시각", "created_ts": "생성된 시각",
"updated_ts": "변경된 시각", "updated_ts": "변경된 시각",
"daily-review-time-offset": "날마다 돌아보기 기준 시각" "daily-review-time-offset": "날마다 돌아보기 기준 시각" ,
"auto-collapse": "자동 축소"
}, },
"storage-section": { "storage-section": {
"storage-services-list": "저장소 서비스 목록", "storage-services-list": "저장소 서비스 목록",

View File

@ -166,7 +166,8 @@
"default-memo-sort-option": "Sorteer op tijd van aanmaken/wijziging", "default-memo-sort-option": "Sorteer op tijd van aanmaken/wijziging",
"created_ts": "Tijd van aanmaken", "created_ts": "Tijd van aanmaken",
"updated_ts": "Tijd van wijziging", "updated_ts": "Tijd van wijziging",
"enable-double-click": "Dubbelklik voor bewerken aanzetten" "enable-double-click": "Dubbelklik voor bewerken aanzetten",
"auto-collapse": "Automatisch samenvouwen"
}, },
"member-section": { "member-section": {
"create-a-member": "Lid toevoegen" "create-a-member": "Lid toevoegen"

View File

@ -168,7 +168,8 @@
"mobile-editor-style": "Styl edytora mobilnego", "mobile-editor-style": "Styl edytora mobilnego",
"default-memo-sort-option": "Wyświetlana data notatki", "default-memo-sort-option": "Wyświetlana data notatki",
"created_ts": "Data utworzenia", "created_ts": "Data utworzenia",
"updated_ts": "Data aktualizacji" "updated_ts": "Data aktualizacji",
"auto-collapse": "Automatyczne zwijanie"
}, },
"storage-section": { "storage-section": {
"storage-services-list": "Lista usług przechowywania", "storage-services-list": "Lista usług przechowywania",

View File

@ -187,7 +187,8 @@
"default-memo-sort-option": "Memo display time", "default-memo-sort-option": "Memo display time",
"created_ts": "Hora de criação", "created_ts": "Hora de criação",
"updated_ts": "Hora de atualização", "updated_ts": "Hora de atualização",
"daily-review-time-offset": "Compensação de tempo do Resumo Diário" "daily-review-time-offset": "Compensação de tempo do Resumo Diário",
"auto-collapse": "Recolher automaticamente"
}, },
"storage-section": { "storage-section": {
"current-storage": "Armazenamento atual", "current-storage": "Armazenamento atual",

View File

@ -196,7 +196,8 @@
"created_ts": "Время создания", "created_ts": "Время создания",
"updated_ts": "Время обновления", "updated_ts": "Время обновления",
"enable-double-click": "Разрешить двойной клик для редактирования", "enable-double-click": "Разрешить двойной клик для редактирования",
"daily-review-time-offset": "Смещение времени ежедневного просмотра" "daily-review-time-offset": "Смещение времени ежедневного просмотра",
"auto-collapse": "Автоматическое свертывание"
}, },
"member-section": { "member-section": {
"create-a-member": "Создать пользователя" "create-a-member": "Создать пользователя"

View File

@ -198,7 +198,8 @@
"default-memo-sort-option": "Čas prikaza beležke", "default-memo-sort-option": "Čas prikaza beležke",
"created_ts": "Čas ustvarjanja", "created_ts": "Čas ustvarjanja",
"updated_ts": "Čas posodobitve", "updated_ts": "Čas posodobitve",
"daily-review-time-offset": "Časovni odmik dnevnega pregleda" "daily-review-time-offset": "Časovni odmik dnevnega pregleda",
"auto-collapse":"Samodejno strni"
}, },
"storage-section": { "storage-section": {
"storage-services-list": "Seznam storitev shramb", "storage-services-list": "Seznam storitev shramb",

View File

@ -166,7 +166,8 @@
"default-memo-sort-option": "Anteckning visningstid", "default-memo-sort-option": "Anteckning visningstid",
"created_ts": "Skapade tid", "created_ts": "Skapade tid",
"updated_ts": "Upodaterad tid", "updated_ts": "Upodaterad tid",
"enable-double-click": "Aktivera dubbelklick för att redigera" "enable-double-click": "Aktivera dubbelklick för att redigera",
"auto-collapse": "Autokollaps"
}, },
"member-section": { "member-section": {
"create-a-member": "Skapa en medlem" "create-a-member": "Skapa en medlem"

View File

@ -156,7 +156,8 @@
"default-memo-sort-option": "Yer İşareti Görüntüleme Zamanı", "default-memo-sort-option": "Yer İşareti Görüntüleme Zamanı",
"created_ts": "Oluşturulma zamanı", "created_ts": "Oluşturulma zamanı",
"updated_ts": "Güncelleme zamanı", "updated_ts": "Güncelleme zamanı",
"enable-double-click": "Düzenlemek için çift tıklatmayı etkinleştir" "enable-double-click": "Düzenlemek için çift tıklatmayı etkinleştir",
"auto-collapse": "Otomatik Daralt"
}, },
"member-section": { "member-section": {
"create-a-member": "Kullanıcı oluştur" "create-a-member": "Kullanıcı oluştur"

View File

@ -166,7 +166,8 @@
"default-memo-sort-option": "Час відображення закладки", "default-memo-sort-option": "Час відображення закладки",
"created_ts": "Час створення", "created_ts": "Час створення",
"updated_ts": "Час оновлення", "updated_ts": "Час оновлення",
"enable-double-click": "Enable double-click to edit" "enable-double-click": "Enable double-click to edit",
"auto-collapse": "Автоматичне згортання"
}, },
"member-section": { "member-section": {
"create-a-member": "Створити користувача" "create-a-member": "Створити користувача"

View File

@ -166,7 +166,8 @@
"default-memo-sort-option": "Thời gian hiện ghi chú", "default-memo-sort-option": "Thời gian hiện ghi chú",
"created_ts": "Thời gian tạo", "created_ts": "Thời gian tạo",
"updated_ts": "Thời gian cập nhật", "updated_ts": "Thời gian cập nhật",
"enable-double-click": "Enable double-click to edit" "enable-double-click": "Bật nhấp đúp để chỉnh sửa",
"auto-collapse": "Tự động thu gọn"
}, },
"member-section": { "member-section": {
"create-a-member": "Thêm thành viên" "create-a-member": "Thêm thành viên"

View File

@ -207,7 +207,8 @@
"created_ts": "创建时间", "created_ts": "创建时间",
"updated_ts": "更新时间", "updated_ts": "更新时间",
"daily-review-time-offset": "每日回顾时间偏移", "daily-review-time-offset": "每日回顾时间偏移",
"default-resource-visibility": "默认资源可见性" "default-resource-visibility": "默认资源可见性",
"auto-collapse": "自动折叠"
}, },
"storage-section": { "storage-section": {
"storage-services-list": "存储服务列表", "storage-services-list": "存储服务列表",

View File

@ -207,7 +207,8 @@
"created_ts": "建立時間", "created_ts": "建立時間",
"updated_ts": "更新時間", "updated_ts": "更新時間",
"daily-review-time-offset": "每日回顧時間偏移", "daily-review-time-offset": "每日回顧時間偏移",
"default-resource-visibility": "默認資源可見性" "default-resource-visibility": "默認資源可見性",
"auto-collapse": "自動摺疊"
}, },
"storage-section": { "storage-section": {
"storage-services-list": "存儲服務列表", "storage-services-list": "存儲服務列表",

View File

@ -16,6 +16,7 @@ const defaultSetting: Setting = {
const defaultLocalSetting: LocalSetting = { const defaultLocalSetting: LocalSetting = {
enableDoubleClickEditing: true, enableDoubleClickEditing: true,
dailyReviewTimeOffset: 0, dailyReviewTimeOffset: 0,
enableAutoCollapse: true,
}; };
export const convertResponseModelUser = (user: User): User => { export const convertResponseModelUser = (user: User): User => {

View File

@ -9,6 +9,7 @@ interface Setting {
interface LocalSetting { interface LocalSetting {
enableDoubleClickEditing: boolean; enableDoubleClickEditing: boolean;
dailyReviewTimeOffset: number; dailyReviewTimeOffset: number;
enableAutoCollapse: boolean;
} }
interface UserLocaleSetting { interface UserLocaleSetting {