mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: support audio player (#948)
This commit is contained in:
36
web/src/components/MemoResource.tsx
Normal file
36
web/src/components/MemoResource.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import Icon from "./Icon";
|
||||
|
||||
interface Props {
|
||||
resource: Resource;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const MemoResource: React.FC<Props> = (props: Props) => {
|
||||
const { className, resource } = props;
|
||||
const resourceUrl = `${window.location.origin}/o/r/${resource.id}/${resource.filename}`;
|
||||
|
||||
const handlePreviewBtnClick = () => {
|
||||
window.open(resourceUrl);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={`w-auto flex flex-row justify-start items-center ${className}`}>
|
||||
{resource.type.startsWith("audio") ? (
|
||||
<>
|
||||
<audio className="h-8" src={resourceUrl} controls></audio>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Icon.FileText className="w-4 h-auto mr-1 text-gray-500" />
|
||||
<span className="text-gray-500 text-sm max-w-xs truncate font-mono cursor-pointer" onClick={handlePreviewBtnClick}>
|
||||
{resource.filename}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default MemoResource;
|
@@ -1,7 +1,7 @@
|
||||
import { absolutifyLink } from "../helpers/utils";
|
||||
import Icon from "./Icon";
|
||||
import SquareDiv from "./common/SquareDiv";
|
||||
import showPreviewImageDialog from "./PreviewImageDialog";
|
||||
import MemoResource from "./MemoResource";
|
||||
import "../less/memo-resources.less";
|
||||
|
||||
interface Props {
|
||||
@@ -24,11 +24,6 @@ const MemoResources: React.FC<Props> = (props: Props) => {
|
||||
const availableResourceList = resourceList.filter((resource) => resource.type.startsWith("image") || resource.type.startsWith("video"));
|
||||
const otherResourceList = resourceList.filter((resource) => !availableResourceList.includes(resource));
|
||||
|
||||
const handlePreviewBtnClick = (resource: Resource) => {
|
||||
const resourceUrl = `${window.location.origin}/o/r/${resource.id}/${resource.filename}`;
|
||||
window.open(resourceUrl);
|
||||
};
|
||||
|
||||
const imgUrls = availableResourceList
|
||||
.filter((resource) => resource.type.startsWith("image"))
|
||||
.map((resource) => {
|
||||
@@ -68,16 +63,13 @@ const MemoResources: React.FC<Props> = (props: Props) => {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="other-resource-wrapper">
|
||||
{otherResourceList.length > 0 && (
|
||||
<div className="w-full flex flex-row justify-start flex-wrap mt-2">
|
||||
{otherResourceList.map((resource) => {
|
||||
return (
|
||||
<div className="other-resource-container" key={resource.id} onClick={() => handlePreviewBtnClick(resource)}>
|
||||
<Icon.FileText className="icon-img" />
|
||||
<span className="name-text">{resource.filename}</span>
|
||||
</div>
|
||||
);
|
||||
return <MemoResource key={resource.id} className="my-1 mr-2" resource={resource} />;
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
@@ -17,19 +17,3 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.other-resource-wrapper {
|
||||
@apply w-full flex flex-row justify-start flex-wrap;
|
||||
|
||||
> .other-resource-container {
|
||||
@apply mt-1 mr-1 max-w-full flex flex-row justify-start items-center flex-nowrap bg-gray-100 px-2 py-1 rounded cursor-pointer hover:bg-gray-200;
|
||||
|
||||
> .icon-img {
|
||||
@apply w-4 h-auto mr-1 text-gray-500;
|
||||
}
|
||||
|
||||
> .name-text {
|
||||
@apply text-gray-500 text-sm max-w-xs truncate font-mono;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user