more progress

This commit is contained in:
FromTheLOLAshes committed 2024-03-26 19:19:40 +07:00
1 parent f4cd2d89e7
commit b3cf41500e
4 files changed
+667 -470

No files matched your search

+9 -1
View File
@@ -15,7 +15,15 @@ export const ClipProvider = ({ children }: Props) => {
const [audioClips, setAudioClips] = useState<AudioClip[]>([]);
useEffect(() => {
setAnimationClips([]);
console.log("eff");
setAnimationClips([
{
id: "ani-id1",
offset: 0,
length: 124,
name: "ani 11",
},
]);
setAudioClips([]);
}, []);
@@ -0,0 +1,80 @@
import { useCallback, useContext, useEffect, useState } from "react";
import { BaseClip } from "~/models/track";
import { ClipContext } from "~/contexts/ClipContext/ClipContext";
interface Props {
clip: BaseClip;
type: "animation" | "audio";
}
export const ClipElement = ({ clip, type }: Props) => {
const { startDrag, dragId, endDrag } = useContext(ClipContext);
const [initPosition, setInitPosition] = useState<{
initX: number;
initY: number;
}>({
initX: 0,
initY: 0,
});
const [currPosition, setCurrPosition] = useState<{
x: number;
y: number;
}>({
x: 0,
y: 0,
});
const { x, y } = currPosition;
const { initX, initY } = initPosition;
useEffect(() => {
const onPointerUp = () => {
if (dragId) {
endDrag();
}
};
const onMouseMove = (event: MouseEvent) => {
if (dragId) {
const deltaX = event.clientX - initX;
const deltaY = event.clientY - initY;
setCurrPosition({ x: deltaX, y: deltaY });
return;
}
};
window.addEventListener("pointerup", onPointerUp);
window.addEventListener("pointermove", onMouseMove);
return () => {
window.removeEventListener("pointerup", onPointerUp);
window.removeEventListener("pointermove", onMouseMove);
};
}, []);
const onPointerDown = useCallback(
(event: React.PointerEvent<HTMLDivElement>) => {
if (event.button === 0) {
startDrag(type, clip.id);
setCurrPosition({
x: 0,
y: 0,
});
setInitPosition({ initY: event.clientY, initX: event.clientX });
}
},
[type, clip.id, startDrag],
);
return (
<div key={clip.id} className="relative h-16 w-16">
<div
id={`ani-clip-${clip.id}`}
className="absolute block h-16 w-16 bg-brand-secondary-700"
style={{ top: y, left: x }}
onPointerDown={onPointerDown}
>
{clip.name}
</div>
</div>
);
};
@@ -1,7 +1,12 @@
import { Tabs } from "~/modules/Tabs";
import { TabStyling } from "./TabStyling";
import { useCallback, useContext, useState } from "react";
import { ClipContext } from "~/contexts/ClipContext/ClipContext";
import { ClipElement } from "~/pages/PageEnigma/comps/SidePanelTabs/ClipElement";
export const SidePanelTabs = () => {
const { animationClips } = useContext(ClipContext);
return (
<Tabs
tabs={[
@@ -9,10 +14,9 @@ export const SidePanelTabs = () => {
header: "Animation",
children: (
<div className="flex flex-wrap">
<div
id="ani-obj-1"
className="block h-16 w-16 bg-brand-secondary-700"
/>
{animationClips.map((clip) => (
<ClipElement key={clip.id} clip={clip} type="animation" />
))}
</div>
),
},
File diff suppressed because it is too large. Load diff