Skip to content

Commit

Permalink
feat: support audio player (usememos#948)
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack authored Jan 13, 2023
1 parent aacaf3f commit 4cfd000
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
36 changes: 36 additions & 0 deletions web/src/components/MemoResource.tsx
Original file line number Diff line number Diff line change
@@ -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;
24 changes: 8 additions & 16 deletions web/src/components/MemoResources.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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) => {
Expand Down Expand Up @@ -68,16 +63,13 @@ const MemoResources: React.FC<Props> = (props: Props) => {
</div>
)}
</div>
<div className="other-resource-wrapper">
{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>
);
})}
</div>
{otherResourceList.length > 0 && (
<div className="w-full flex flex-row justify-start flex-wrap mt-2">
{otherResourceList.map((resource) => {
return <MemoResource key={resource.id} className="my-1 mr-2" resource={resource} />;
})}
</div>
)}
</>
);
};
Expand Down
16 changes: 0 additions & 16 deletions web/src/less/memo-resources.less
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit 4cfd000

Please sign in to comment.