Skip to content
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

feat: new share dialog #618

Merged
merged 5 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
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
69 changes: 59 additions & 10 deletions web/src/components/ShareMemoImageDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { useEffect, useRef, useState } from "react";
import React, { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { userService } from "../services";
import copy from "copy-to-clipboard";
import { toLower } from "lodash";
import toImage from "../labs/html2image";
import { ANIMATION_DURATION } from "../helpers/consts";
import { ANIMATION_DURATION, VISIBILITY_SELECTOR_ITEMS } from "../helpers/consts";
import * as utils from "../helpers/utils";
import { getMemoStats } from "../helpers/api";
import { memoService, userService } from "../services";
import useLoading from "../hooks/useLoading";
import Icon from "./Icon";
import { generateDialog } from "./Dialog";
import toastHelper from "./Toast";
import MemoContent from "./MemoContent";
import MemoResources from "./MemoResources";
import Selector from "./common/Selector";
import "../less/share-memo-image-dialog.less";

interface Props extends DialogProps {
Expand All @@ -19,6 +23,7 @@ interface Props extends DialogProps {
interface State {
memoAmount: number;
shortcutImgUrl: string;
memoVisibility: string;
}

const ShareMemoImageDialog: React.FC<Props> = (props: Props) => {
Expand All @@ -28,6 +33,7 @@ const ShareMemoImageDialog: React.FC<Props> = (props: Props) => {
const [state, setState] = useState<State>({
memoAmount: 0,
shortcutImgUrl: "",
memoVisibility: propsMemo.visibility,
});
const loadingState = useLoading();
const memoElRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -64,7 +70,7 @@ const ShareMemoImageDialog: React.FC<Props> = (props: Props) => {
}

toImage(memoElRef.current, {
backgroundColor: "#eaeaea",
backgroundColor: "#f4f4f5",
pixelRatio: window.devicePixelRatio * 2,
})
.then((url) => {
Expand Down Expand Up @@ -92,6 +98,30 @@ const ShareMemoImageDialog: React.FC<Props> = (props: Props) => {
a.click();
};

const handleCopyLinkBtnClick = () => {
copy(`${window.location.origin}/m/${memo.id}`);
toastHelper.success(t("message.succeed-copy-content"));
};

const memoVisibilityOptionSelectorItems = VISIBILITY_SELECTOR_ITEMS.map((item) => {
return {
value: item.value,
text: t(`memo.visibility.${toLower(item.value)}`),
};
});

const handleMemoVisibilityOptionChanged = async (value: string) => {
const visibilityValue = value as Visibility;
setState({
...state,
memoVisibility: visibilityValue,
});
await memoService.patchMemo({
id: memo.id,
visibility: visibilityValue,
});
};

return (
<>
<div className="dialog-header-container">
Expand All @@ -104,13 +134,8 @@ const ShareMemoImageDialog: React.FC<Props> = (props: Props) => {
</button>
</div>
<div className="dialog-content-container">
<div className={`tip-words-container ${state.shortcutImgUrl ? "finish" : "loading"}`}>
<p className="tip-text">
{state.shortcutImgUrl ? t("message.click-to-save-the-image") + " 👇" : t("message.generating-the-screenshot")}
</p>
</div>
<div className="memo-container" ref={memoElRef}>
{state.shortcutImgUrl !== "" && <img className="memo-shortcut-img" onClick={handleDownloadBtnClick} src={state.shortcutImgUrl} />}
{state.shortcutImgUrl !== "" && <img className="memo-shortcut-img" src={state.shortcutImgUrl} />}
<span className="time-text">{memo.createdAtStr}</span>
<div className="memo-content-wrapper">
<MemoContent content={memo.content} displayConfig={{ enableExpand: false }} />
Expand All @@ -126,6 +151,30 @@ const ShareMemoImageDialog: React.FC<Props> = (props: Props) => {
<img className="logo-img" src="/logo.webp" alt="" />
</div>
</div>
<div className="share-actions-container">
<div className="visibility-selector">
<Selector
className="visibility-selector"
value={state.memoVisibility}
dataSource={memoVisibilityOptionSelectorItems}
handleValueChanged={handleMemoVisibilityOptionChanged}
/>
</div>
<div className="share-btns-container">
<div className="buttons-wrapper">
<div className="share-btn share-image-btn" onClick={handleDownloadBtnClick}>
<Icon.Download className="icon-img" />
<span>{t("common.image")}</span>
</div>
</div>
<div className="buttons-wrapper">
<div className="share-btn share-link-btn" onClick={handleCopyLinkBtnClick}>
<Icon.Link className="icon-img" />
<span>{t("common.link")}</span>
</div>
</div>
</div>
</div>
</div>
</>
);
Expand Down
36 changes: 34 additions & 2 deletions web/src/less/share-memo-image-dialog.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.share-memo-image-dialog {
> .dialog-container {
@apply w-96 p-0 bg-gray-200;
@apply w-96 p-0 bg-zinc-100;

> .dialog-header-container {
@apply py-2 pt-4 px-4 pl-6 mb-0 bg-white rounded-t-lg;
Expand Down Expand Up @@ -58,7 +58,7 @@
}

> .watermark-container {
@apply flex flex-row justify-between items-center w-full py-3 px-6;
@apply flex flex-row justify-between items-center w-full py-2 px-6;

> .normal-text {
@apply w-full flex flex-row justify-start items-center text-sm leading-6 text-gray-500;
Expand All @@ -85,6 +85,38 @@
}
}
}

.share-actions-container{
@apply flex justify-between px-4 py-3 mb-0 bg-white w-full rounded-b-lg border-t;

> .visibility-selector{
@apply w-36;

> .selector-wrapper{
@apply h-10;
}
}

> .share-btns-container{
@apply flex justify-end;

> .buttons-wrapper {
@apply flex flex-row justify-start items-center;

> .share-btn{
@apply text-sm cursor-pointer px-3 py-2 rounded flex flex-row justify-center items-center border bg-gray-50 hover:bg-gray-100;

> .icon-img {
@apply w-4 h-auto mr-1;
}
}

> .share-image-btn {
@apply mr-3;
}
}
}
}
}
}
}
5 changes: 4 additions & 1 deletion web/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"changed": "changed",
"update-on": "Update on",
"fold": "Fold",
"expand": "Expand"
"expand": "Expand",
"image": "Image",
"link": "Link"
},
"slogan": "An open-source, self-hosted memo hub for knowledge management and collaboration.",
"auth": {
Expand Down Expand Up @@ -191,6 +193,7 @@
"private-only": "This memo is private only.",
"copied": "Copied",
"succeed-copy-content": "Succeed to copy content to clipboard.",
"succeed-copy-link": "Succeed to copy link to clipboard.",
"change-resource-filename": "Change resource filename",
"resource-filename-updated": "Resource filename changed.",
"invalid-resource-filename": "Invalid filename.",
Expand Down
5 changes: 4 additions & 1 deletion web/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"changed": "modifié",
"update-on": "Mise à jour sur",
"fold": "Plier",
"expand": "Développer"
"expand": "Développer",
"image": "Image",
"link": "Link"
},
"slogan": "Un hub de mémos open source et auto-hébergé pour la gestion des connaissances et la collaboration.",
"auth": {
Expand Down Expand Up @@ -186,6 +188,7 @@
"private-only": "Ce mémo est uniquement privé.",
"copied": "Copié",
"succeed-copy-content": "La copie dans le presse-papiers a été effectuée avec succès",
"succeed-copy-link": "Succeed to copy link to clipboard.",
"change-resource-filename": "Changer le nom du fichier de ressources",
"resource-filename-updated": "Le nom de fichier de la ressource a changé.",
"invalid-resource-filename": "Nom de fichier invalide.",
Expand Down
5 changes: 4 additions & 1 deletion web/src/locales/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"changed": "đã thay đổi",
"update-on": "Cập nhật",
"fold": "Fold",
"expand": "Expand"
"expand": "Expand",
"image": "Image",
"link": "Link"
},
"slogan": "An open-source, self-hosted memo hub for knowledge management and collaboration.",
"auth": {
Expand Down Expand Up @@ -185,6 +187,7 @@
"private-only": "Memo này có trạng thái riêng tư.",
"copied": "Đã sao chép",
"succeed-copy-content": "Đã sao chép nội dung memo thành công.",
"succeed-copy-link": "Succeed to copy link to clipboard.",
"change-resource-filename": "Thay đổi tên tệp tài nguyên",
"resource-filename-updated": "Tên tệp tài nguyên đã thay đổi.",
"invalid-resource-filename": "Tên tệp không hợp lệ.",
Expand Down
5 changes: 4 additions & 1 deletion web/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"changed": "已更改",
"update-on": "更新于",
"fold": "折叠",
"expand": "展开"
"expand": "展开",
"image": "图片",
"link": "链接"
},
"slogan": "An open-source, self-hosted memo hub for knowledge management and collaboration.",
"auth": {
Expand Down Expand Up @@ -191,6 +193,7 @@
"private-only": "此 Memo 仅自己可见",
"copied": "已复制",
"succeed-copy-content": "复制内容到剪贴板成功。",
"succeed-copy-link": "复制链接到剪贴板成功。",
"change-resource-filename": "更改资源文件名",
"resource-filename-updated": "资源文件名更改成功。",
"invalid-resource-filename": "无效的资源文件名",
Expand Down