* feat ui: login flow for spot extension * spot list, store and service created * some fixing for header * start work on single spot * spot player start * header for player, comments, icons, etc * split stuff into compoennts, create player state manager * player controls, activity panel etc etc * comments, empty page, rename and stuff * interval buttons etc * access modal * pubkey support * fix tooltip * limit 10 -> 9 * hls lib instead of videojs * some warnings * fix date display for exp * change public links * display more client data * fix cleaning, init comment * map network to replay player network ev * stream support, console panel, close panels on X * fixing streaming, destroy on leave * fix autoplay * show notification on spot login * fix spot login * backup player added, fix audio issue * show thumbnail when no video, add spot roles * add poster thumbnail * some fixes to video check * fix events jump * fix play btn * try catch over pubkey * icons * spot login pinging * move spot login flow to login comp, use separate spot login path for unique jwt * invalidate spot jwt on logout * add visual data on page load event * typo fix * issue to copy change * share spot url f
85 lines
1.8 KiB
TypeScript
85 lines
1.8 KiB
TypeScript
import React, { memo, useEffect } from 'react';
|
|
import type { CSSProperties, FC } from 'react'
|
|
import { useDragLayer, XYCoord } from "react-dnd";
|
|
import Circle from './Circle'
|
|
|
|
const layerStyles: CSSProperties = {
|
|
position: "fixed",
|
|
pointerEvents: "none",
|
|
zIndex: 100,
|
|
left: 0,
|
|
top: 0,
|
|
width: "100%",
|
|
height: "100%"
|
|
}
|
|
|
|
|
|
function getItemStyles(
|
|
initialOffset: XYCoord | null,
|
|
currentOffset: XYCoord | null,
|
|
maxX: number,
|
|
minX: number,
|
|
) {
|
|
if (!initialOffset || !currentOffset) {
|
|
return {
|
|
display: "none"
|
|
}
|
|
}
|
|
let { x } = currentOffset;
|
|
if (x > maxX) {
|
|
x = maxX;
|
|
}
|
|
|
|
if (x < minX) {
|
|
x = minX;
|
|
}
|
|
const transform = `translate(${x}px, ${initialOffset.y}px)`;
|
|
return {
|
|
transition: 'transform 0.1s ease-out',
|
|
transform,
|
|
WebkitTransform: transform
|
|
}
|
|
}
|
|
|
|
export type OnDragCallback = (offset: XYCoord) => void
|
|
|
|
interface Props {
|
|
onDrag: OnDragCallback
|
|
maxX: number
|
|
minX: number
|
|
}
|
|
|
|
const CustomDragLayer: FC<Props> = memo(function CustomDragLayer({ maxX, minX, onDrag }) {
|
|
const {
|
|
isDragging,
|
|
initialOffset,
|
|
currentOffset, // might be null (why is it not captured by types?)
|
|
} = useDragLayer((monitor) => ({
|
|
initialOffset: monitor.getInitialSourceClientOffset(),
|
|
currentOffset: monitor.getSourceClientOffset(),
|
|
isDragging: monitor.isDragging(),
|
|
}))
|
|
|
|
useEffect(() => {
|
|
if (!isDragging || !currentOffset?.x) {
|
|
return
|
|
}
|
|
onDrag(currentOffset)
|
|
}, [isDragging, currentOffset])
|
|
|
|
if (!isDragging || !currentOffset) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<div id={"drag-layer"} style={layerStyles}>
|
|
<div
|
|
style={getItemStyles(initialOffset, currentOffset, maxX, minX)}
|
|
>
|
|
<Circle />
|
|
</div>
|
|
</div>
|
|
)
|
|
})
|
|
|
|
export default CustomDragLayer;
|