Skip to content

Commit

Permalink
refactor(flat-pages): disable drop file without drawing permission (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious authored Jun 15, 2023
1 parent 9aee2be commit b9ed469
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/flat-pages/src/components/Whiteboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,16 @@ export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({

const onDragOver = useCallback(
(event: React.DragEvent<HTMLDivElement>) => {
event.preventDefault();
setTipsVisible(true);
const file = event.dataTransfer.files[0];
if (room && file && isSupportedFileExt(file)) {
event.dataTransfer.dropEffect = "copy";
if (whiteboardStore.allowDrawing) {
event.preventDefault();
setTipsVisible(true);
const file = event.dataTransfer.files[0];
if (room && file && isSupportedFileExt(file)) {
event.dataTransfer.dropEffect = "copy";
}
}
},
[room],
[room, whiteboardStore.allowDrawing],
);

const onDragLeave = useCallback(() => {
Expand All @@ -139,6 +141,9 @@ export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({

const onDrop = useCallback(
async (event: React.DragEvent<HTMLDivElement>) => {
if (!whiteboardStore.allowDrawing) {
return;
}
event.preventDefault();
setTipsVisible(false);
const file = event.dataTransfer.files[0];
Expand All @@ -160,7 +165,7 @@ export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({
useEffect(() => {
const pasteHandler = (event: ClipboardEvent): void => {
const file = event.clipboardData?.files[0];
if (room && windowManager && file) {
if (room && windowManager && file && whiteboardStore.allowDrawing) {
const { centerX, centerY } = windowManager.camera;
if (isSupportedImageType(file)) {
const id = format(Date.now(), "yyyy-MM-dd_HH-mm-ss");
Expand Down

0 comments on commit b9ed469

Please sign in to comment.