2024-08-05 22:36:05 +05:30
|
|
|
import { useEffect, useMemo, useRef } from "react"
|
2024-09-15 19:22:32 +05:30
|
|
|
import Draggable from "./utils/draggableDnd"
|
2024-08-05 22:36:05 +05:30
|
|
|
|
|
|
|
|
import { FileImageOutlined, GithubOutlined, GitlabOutlined, LinkOutlined,
|
|
|
|
|
AudioOutlined, VideoCameraOutlined,
|
|
|
|
|
FileTextOutlined} from "@ant-design/icons"
|
2024-09-16 12:23:15 +05:30
|
|
|
import DraggableWrapper from "./draggable/draggable"
|
2024-09-22 12:39:03 +05:30
|
|
|
import { useDragContext } from "./draggable/draggableContext"
|
2024-08-05 22:36:05 +05:30
|
|
|
|
|
|
|
|
|
2024-09-22 12:39:03 +05:30
|
|
|
export function SidebarWidgetCard({ name, img, url, widgetClass, innerRef}){
|
2024-08-05 22:36:05 +05:30
|
|
|
|
|
|
|
|
const urlIcon = useMemo(() => {
|
|
|
|
|
if (url){
|
|
|
|
|
const host = new URL(url).hostname.toLowerCase()
|
|
|
|
|
|
|
|
|
|
if (host === "github.com"){
|
|
|
|
|
return <GithubOutlined />
|
|
|
|
|
}else if(host === "gitlab.com"){
|
|
|
|
|
return <GitlabOutlined />
|
|
|
|
|
}else{
|
|
|
|
|
return <LinkOutlined />
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, [url])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2024-09-15 19:22:32 +05:30
|
|
|
// <Draggable className="tw-cursor-pointer" id={name}>
|
2024-09-21 22:47:47 +05:30
|
|
|
<DraggableWrapper data-container={"sidebar"}
|
2024-09-23 12:31:01 +05:30
|
|
|
dragElementType={widgetClass.widgetType}
|
2024-09-22 12:39:03 +05:30
|
|
|
dragWidgetClass={widgetClass}
|
2024-09-21 22:47:47 +05:30
|
|
|
className="tw-cursor-pointer tw-w-fit tw-h-fit">
|
2024-09-16 12:23:15 +05:30
|
|
|
|
2024-09-17 18:32:33 +05:30
|
|
|
<div ref={innerRef} className="tw-select-none tw-h-[200px] tw-w-[230px] tw-flex tw-flex-col
|
2024-09-15 19:22:32 +05:30
|
|
|
tw-rounded-md tw-overflow-hidden
|
|
|
|
|
tw-gap-2 tw-text-gray-600 tw-bg-[#ffffff44] tw-border-solid tw-border-[1px]
|
|
|
|
|
tw-border-[#888] ">
|
2024-09-16 22:04:24 +05:30
|
|
|
<div className="tw-h-[200px] tw-pointer-events-none tw-w-full tw-overflow-hidden">
|
2024-09-15 19:22:32 +05:30
|
|
|
<img src={img} alt={name} className="tw-object-contain tw-h-full tw-w-full tw-select-none" />
|
|
|
|
|
</div>
|
|
|
|
|
<span className="tw-text-xl tw-text-center">{name}</span>
|
|
|
|
|
<div className="tw-flex tw-text-lg tw-place tw-px-4">
|
|
|
|
|
|
|
|
|
|
<a href={url} className="tw-text-black" target="_blank" rel="noopener noreferrer">
|
|
|
|
|
{urlIcon}
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
2024-09-16 12:23:15 +05:30
|
|
|
|
2024-08-05 22:36:05 +05:30
|
|
|
</div>
|
2024-09-15 19:22:32 +05:30
|
|
|
</DraggableWrapper>
|
|
|
|
|
// </Draggable>
|
2024-08-05 22:36:05 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function DraggableAssetCard({file}){
|
|
|
|
|
|
|
|
|
|
const videoRef = useRef()
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
|
|
function playOnMouseEnter(){
|
|
|
|
|
videoRef.current.play()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function pauseOnMouseEnter(){
|
|
|
|
|
videoRef.current.pause()
|
|
|
|
|
videoRef.current.currentTime = 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (videoRef.current){
|
|
|
|
|
videoRef.current.addEventListener("mouseenter", playOnMouseEnter)
|
|
|
|
|
videoRef.current.addEventListener("mouseleave", pauseOnMouseEnter)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
if (videoRef.current){
|
|
|
|
|
videoRef.current.removeEventListener("mouseenter", playOnMouseEnter)
|
|
|
|
|
videoRef.current.removeEventListener("mouseleave", pauseOnMouseEnter)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, [videoRef])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Draggable className="tw-cursor-pointer">
|
2024-09-22 12:39:03 +05:30
|
|
|
<div className="tw-w-full tw-h-[240px] tw-p-1 tw-flex tw-flex-col tw-rounded-md tw-overflow-hidden
|
2024-08-05 22:36:05 +05:30
|
|
|
tw-gap-2 tw-text-gray-600 tw-bg-[#ffffff44] tw-border-solid tw-border-[1px] tw-border-[#888] ">
|
|
|
|
|
<div className="tw-h-[200px] tw-w-full tw-flex tw-place-content-center tw-p-1 tw-text-3xl tw-overflow-hidden">
|
|
|
|
|
{ file.fileType === "image" &&
|
|
|
|
|
<img src={file.previewUrl} alt={file.name} className="tw-object-contain tw-h-full tw-w-full tw-select-none" />
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
file.fileType === "video" &&
|
|
|
|
|
<video className="tw-w-full tw-object-contain" ref={videoRef} muted>
|
|
|
|
|
<source src={file.previewUrl} type={`${file.type || "video/mp4"}`} />
|
|
|
|
|
Your browser does not support the video tag.
|
|
|
|
|
</video>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
file.fileType === "audio" &&
|
|
|
|
|
<AudioOutlined />
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
file.fileType === "others" &&
|
|
|
|
|
<FileTextOutlined />
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</div>
|
2024-09-22 12:39:03 +05:30
|
|
|
<span className="tw-text-base">{file.name}</span>
|
2024-08-05 22:36:05 +05:30
|
|
|
</div>
|
|
|
|
|
</Draggable>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
}
|