mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: add upload resource button
This commit is contained in:
@ -48,7 +48,7 @@ const ArchivedMemoDialog: React.FC<Props> = (props: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
) : archivedMemos.length === 0 ? (
|
) : archivedMemos.length === 0 ? (
|
||||||
<div className="tip-text-container">
|
<div className="tip-text-container">
|
||||||
<p className="tip-text">Here is No Zettels.</p>
|
<p className="tip-text">No archived memos.</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="archived-memos-container">
|
<div className="archived-memos-container">
|
||||||
|
@ -11,10 +11,18 @@ import "../less/resources-dialog.less";
|
|||||||
|
|
||||||
interface Props extends DialogProps {}
|
interface Props extends DialogProps {}
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
resources: Resource[];
|
||||||
|
isUploadingResource: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
const ResourcesDialog: React.FC<Props> = (props: Props) => {
|
const ResourcesDialog: React.FC<Props> = (props: Props) => {
|
||||||
const { destroy } = props;
|
const { destroy } = props;
|
||||||
const loadingState = useLoading();
|
const loadingState = useLoading();
|
||||||
const [resources, setResources] = useState<Resource[]>([]);
|
const [state, setState] = useState<State>({
|
||||||
|
resources: [],
|
||||||
|
isUploadingResource: false,
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchResources()
|
fetchResources()
|
||||||
@ -28,7 +36,45 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
|
|||||||
|
|
||||||
const fetchResources = async () => {
|
const fetchResources = async () => {
|
||||||
const data = await resourceService.getResourceList();
|
const data = await resourceService.getResourceList();
|
||||||
setResources(data);
|
setState({
|
||||||
|
...state,
|
||||||
|
resources: data,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUploadFileBtnClick = async () => {
|
||||||
|
if (state.isUploadingResource) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputEl = document.createElement("input");
|
||||||
|
inputEl.type = "file";
|
||||||
|
inputEl.multiple = false;
|
||||||
|
inputEl.accept = "image/png, image/gif, image/jpeg";
|
||||||
|
inputEl.onchange = async () => {
|
||||||
|
if (!inputEl.files || inputEl.files.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState({
|
||||||
|
...state,
|
||||||
|
isUploadingResource: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const file = inputEl.files[0];
|
||||||
|
try {
|
||||||
|
await resourceService.upload(file);
|
||||||
|
} catch (error: any) {
|
||||||
|
toastHelper.error("Failed to upload resource\n" + JSON.stringify(error, null, 4));
|
||||||
|
} finally {
|
||||||
|
setState({
|
||||||
|
...state,
|
||||||
|
isUploadingResource: false,
|
||||||
|
});
|
||||||
|
await fetchResources();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
inputEl.click();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCopyResourceLinkBtnClick = (resource: Resource) => {
|
const handleCopyResourceLinkBtnClick = (resource: Resource) => {
|
||||||
@ -61,7 +107,12 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="dialog-content-container">
|
<div className="dialog-content-container">
|
||||||
<div className="tip-text-container">(👨💻WIP) View your static resources in memos. e.g. images</div>
|
<div className="tip-text-container">(👨💻WIP) View your static resources in memos. e.g. images</div>
|
||||||
<div className="actions-container"></div>
|
<div className="upload-resource-container" onClick={() => handleUploadFileBtnClick()}>
|
||||||
|
<div className="upload-resource-btn">
|
||||||
|
<Icon.File className="icon-img" />
|
||||||
|
<span>Upload</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{loadingState.isLoading ? (
|
{loadingState.isLoading ? (
|
||||||
<div className="loading-text-container">
|
<div className="loading-text-container">
|
||||||
<p className="tip-text">fetching data...</p>
|
<p className="tip-text">fetching data...</p>
|
||||||
@ -74,21 +125,25 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
|
|||||||
<span className="field-text">TYPE</span>
|
<span className="field-text">TYPE</span>
|
||||||
<span></span>
|
<span></span>
|
||||||
</div>
|
</div>
|
||||||
{resources.map((resource) => (
|
{state.resources.length === 0 ? (
|
||||||
<div key={resource.id} className="resource-container">
|
<p className="tip-text">No resource.</p>
|
||||||
<span className="field-text">{resource.id}</span>
|
) : (
|
||||||
<span className="field-text name-text">{resource.filename}</span>
|
state.resources.map((resource) => (
|
||||||
<span className="field-text">{resource.type}</span>
|
<div key={resource.id} className="resource-container">
|
||||||
<div className="buttons-container">
|
<span className="field-text">{resource.id}</span>
|
||||||
<Dropdown className="actions-dropdown">
|
<span className="field-text name-text">{resource.filename}</span>
|
||||||
<button onClick={() => handleCopyResourceLinkBtnClick(resource)}>Copy Link</button>
|
<span className="field-text">{resource.type}</span>
|
||||||
<button className="delete-btn" onClick={() => handleDeleteResourceBtnClick(resource)}>
|
<div className="buttons-container">
|
||||||
Delete
|
<Dropdown className="actions-dropdown">
|
||||||
</button>
|
<button onClick={() => handleCopyResourceLinkBtnClick(resource)}>Copy Link</button>
|
||||||
</Dropdown>
|
<button className="delete-btn" onClick={() => handleDeleteResourceBtnClick(resource)}>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</Dropdown>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
))
|
||||||
))}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -13,6 +13,18 @@
|
|||||||
@apply w-full flex flex-row justify-start items-start border border-yellow-600 rounded px-2 py-1 mb-2 text-yellow-600 bg-yellow-50 text-sm;
|
@apply w-full flex flex-row justify-start items-start border border-yellow-600 rounded px-2 py-1 mb-2 text-yellow-600 bg-yellow-50 text-sm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
> .upload-resource-container {
|
||||||
|
@apply mt-2 mb-4 w-full rounded flex flex-row justify-start items-center;
|
||||||
|
|
||||||
|
> .upload-resource-btn {
|
||||||
|
@apply px-3 py-1 rounded cursor-pointer flex flex-row justify-center items-center border border-dashed border-blue-600 text-blue-600 bg-blue-50 hover:opacity-80;
|
||||||
|
|
||||||
|
> .icon-img {
|
||||||
|
@apply w-4 h-auto mr-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
> .loading-text-container {
|
> .loading-text-container {
|
||||||
@apply flex flex-col justify-center items-center w-full h-32;
|
@apply flex flex-col justify-center items-center w-full h-32;
|
||||||
}
|
}
|
||||||
@ -28,6 +40,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
> .tip-text {
|
||||||
|
@apply w-full text-center text-base my-6 mt-8;
|
||||||
|
}
|
||||||
|
|
||||||
> .resource-container {
|
> .resource-container {
|
||||||
@apply px-2 py-2 w-full grid grid-cols-5;
|
@apply px-2 py-2 w-full grid grid-cols-5;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user