feat: patch resource filename (#360)

* feat: resource filename rename

* update: resource filename rename

* update: resource filename rename

* update: validation about the filename

Co-authored-by: boojack <stevenlgtm@gmail.com>
This commit is contained in:
Zeng1998
2022-10-29 15:40:09 +08:00
committed by GitHub
parent 95376f78f6
commit e85d368f87
15 changed files with 379 additions and 15 deletions

View File

@ -11,11 +11,12 @@ import Icon from "./Icon";
import toastHelper from "./Toast";
import "../less/resources-dialog.less";
import * as utils from "../helpers/utils";
import showChangeResourceFilenameDialog from "./ChangeResourceFilenameDialog";
import { useAppSelector } from "../store";
type Props = DialogProps;
interface State {
resources: Resource[];
isUploadingResource: boolean;
}
@ -23,11 +24,10 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
const { destroy } = props;
const { t } = useTranslation();
const loadingState = useLoading();
const { resources } = useAppSelector((state) => state.resource);
const [state, setState] = useState<State>({
resources: [],
isUploadingResource: false,
});
useEffect(() => {
fetchResources()
.catch((error) => {
@ -41,10 +41,6 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
const fetchResources = async () => {
const data = await resourceService.getResourceList();
setState({
...state,
resources: data,
});
};
const handleUploadFileBtnClick = async () => {
@ -99,6 +95,10 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
}
};
const handleRenameBtnClick = (resource: Resource) => {
showChangeResourceFilenameDialog(resource.id, resource.filename);
};
const handleCopyResourceLinkBtnClick = (resource: Resource) => {
copy(`${window.location.origin}/o/r/${resource.id}/${resource.filename}`);
toastHelper.success("Succeed to copy resource link to clipboard");
@ -165,10 +165,10 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
<span className="field-text type-text">TYPE</span>
<span></span>
</div>
{state.resources.length === 0 ? (
{resources.length === 0 ? (
<p className="tip-text">{t("resources.no-resources")}</p>
) : (
state.resources.map((resource) => (
resources.map((resource) => (
<div key={resource.id} className="resource-container">
<span className="field-text id-text">{resource.id}</span>
<span className="field-text name-text">
@ -198,6 +198,12 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
>
{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"
onClick={() => handleRenameBtnClick(resource)}
>
{t("resources.rename")}
</button>
<button
className="w-full text-left text-sm leading-6 py-1 px-3 cursor-pointer rounded hover:bg-gray-100"
onClick={() => handleCopyResourceLinkBtnClick(resource)}