mirror of https://github.com/usememos/memos
feat: add list style for resource dashboard (#1389)
* stash: file upload * feat: add style button * feat: add style of list * feat: add checkbox for list * feat: support file upload by drag * feat: beautify the ui * feat: support file upload * stash * fix: the resource is incorrectly when upload multiple files * feat: beautify the ui * chore: reduce unused line * stash * chore: deleted unused line * chore: deleted unused line * chore * chore: change the function declare * feat: support to prompt file is too large * feat:drop prompt to cover all element * fix: eslint * fix: the name of i18n * chore: refactor the import deps * feat: beautify the ui * feat: support the style of button * feat: beautify the switch ui * chore: refactor the component * chore: refactor the resource item dropdown * feat: use memo to reduce unused computing in drop * feat: use memo to reduce the calc of resource list * chore:change name * Update web/src/locales/en.json Co-authored-by: boojack <stevenlgtm@gmail.com> * chore: the import of deps * fix: the window size of fecting data * feat: support to save the state of style * remove pnpm-lock * merge main * chore: simpify the statement * fix: delete conflict marker * feat: add i18n for select * feat:support dark mode * eslint * feat: delete the storage of resource style --------- Co-authored-by: boojack <stevenlgtm@gmail.com>pull/1415/head
parent
e84d562146
commit
7d89fcc892
@ -0,0 +1,46 @@
|
||||
import { useState } from "react";
|
||||
import ResourceItemDropdown from "./ResourceItemDropdown";
|
||||
|
||||
const ResourceItem = ({
|
||||
resource,
|
||||
handleCheckClick,
|
||||
handleUncheckClick,
|
||||
handlePreviewBtnClick,
|
||||
handleCopyResourceLinkBtnClick,
|
||||
handleRenameBtnClick,
|
||||
handleDeleteResourceBtnClick,
|
||||
}: ResourceItemType) => {
|
||||
const [isSelected, setIsSelected] = useState<boolean>(false);
|
||||
|
||||
const handleSelectBtnClick = () => {
|
||||
if (isSelected) {
|
||||
handleUncheckClick();
|
||||
} else {
|
||||
handleCheckClick();
|
||||
}
|
||||
setIsSelected(!isSelected);
|
||||
};
|
||||
|
||||
return (
|
||||
<div key={resource.id} className="px-2 py-2 w-full grid grid-cols-7">
|
||||
<span className="w-full m-auto truncate col-span-1 justify-center">
|
||||
<input type="checkbox" onClick={handleSelectBtnClick}></input>
|
||||
</span>
|
||||
<span className="w-full m-auto truncate text-base pr-2 last:pr-0 col-span-1">{resource.id}</span>
|
||||
<span className="w-full m-auto truncate text-base pr-2 last:pr-0 col-span-4" onClick={() => handleRenameBtnClick(resource)}>
|
||||
{resource.filename}
|
||||
</span>
|
||||
<div className="w-full flex flex-row justify-between items-center mb-2">
|
||||
<ResourceItemDropdown
|
||||
resource={resource}
|
||||
handleCopyResourceLinkBtnClick={handleCopyResourceLinkBtnClick}
|
||||
handleDeleteResourceBtnClick={handleDeleteResourceBtnClick}
|
||||
handlePreviewBtnClick={handlePreviewBtnClick}
|
||||
handleRenameBtnClick={handleRenameBtnClick}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ResourceItem;
|
@ -0,0 +1,59 @@
|
||||
import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import Dropdown from "./base/Dropdown";
|
||||
import Icon from "./Icon";
|
||||
|
||||
interface ResourceItemDropdown {
|
||||
resource: Resource;
|
||||
handleRenameBtnClick: (resource: Resource) => void;
|
||||
handleDeleteResourceBtnClick: (resource: Resource) => void;
|
||||
handlePreviewBtnClick: (resource: Resource) => void;
|
||||
handleCopyResourceLinkBtnClick: (resource: Resource) => void;
|
||||
}
|
||||
|
||||
const ResourceItemDropdown = ({
|
||||
resource,
|
||||
handlePreviewBtnClick,
|
||||
handleCopyResourceLinkBtnClick,
|
||||
handleRenameBtnClick,
|
||||
handleDeleteResourceBtnClick,
|
||||
}: ResourceItemDropdown) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
actionsClassName="!w-28"
|
||||
trigger={<Icon.MoreVertical className="w-4 h-auto hover:opacity-80 cursor-pointer" />}
|
||||
actions={
|
||||
<>
|
||||
<button
|
||||
className="w-full text-left text-sm leading-6 py-1 px-3 cursor-pointer rounded hover:bg-gray-100 dark:hover:bg-zinc-600"
|
||||
onClick={() => handlePreviewBtnClick(resource)}
|
||||
>
|
||||
{t("resources.preview")}
|
||||
</button>
|
||||
<button
|
||||
className="w-full text-left text-sm leading-6 py-1 px-3 cursor-pointer rounded hover:bg-gray-100 dark:hover:bg-zinc-600"
|
||||
onClick={() => handleCopyResourceLinkBtnClick(resource)}
|
||||
>
|
||||
{t("resources.copy-link")}
|
||||
</button>
|
||||
<button
|
||||
className="w-full text-left text-sm leading-6 py-1 px-3 cursor-pointer rounded hover:bg-gray-100 dark:hover:bg-zinc-600"
|
||||
onClick={() => handleRenameBtnClick(resource)}
|
||||
>
|
||||
{t("resources.rename")}
|
||||
</button>
|
||||
<button
|
||||
className="w-full text-left text-sm leading-6 py-1 px-3 cursor-pointer rounded text-red-600 hover:bg-gray-100 dark:hover:bg-zinc-600"
|
||||
onClick={() => handleDeleteResourceBtnClick(resource)}
|
||||
>
|
||||
{t("common.delete")}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default React.memo(ResourceItemDropdown);
|
@ -0,0 +1,17 @@
|
||||
import { useState } from "react";
|
||||
|
||||
const useListStyle = () => {
|
||||
// true is Table Style, false is Grid Style
|
||||
const [listStyle, setListStyle] = useState(false);
|
||||
|
||||
return {
|
||||
listStyle: listStyle,
|
||||
setToTableStyle: () => {
|
||||
setListStyle(true);
|
||||
},
|
||||
setToGridStyle: () => {
|
||||
setListStyle(false);
|
||||
},
|
||||
};
|
||||
};
|
||||
export default useListStyle;
|
@ -0,0 +1,11 @@
|
||||
interface ResourceProps {
|
||||
resource: Resource;
|
||||
handleCheckClick: () => void;
|
||||
handleUncheckClick: () => void;
|
||||
handleRenameBtnClick: (resource: Resource) => void;
|
||||
handleDeleteResourceBtnClick: (resource: Resource) => void;
|
||||
handlePreviewBtnClick: (resource: Resource) => void;
|
||||
handleCopyResourceLinkBtnClick: (resource: Resource) => void;
|
||||
}
|
||||
|
||||
type ResourceItemType = ResourceProps;
|
Loading…
Reference in New Issue