feat: trigger socket event to display datime-local picker
This commit is contained in:
@@ -6,6 +6,7 @@ import { useActionContext } from '../../context/browserActions';
|
|||||||
import DatePicker from './DatePicker';
|
import DatePicker from './DatePicker';
|
||||||
import Dropdown from './Dropdown';
|
import Dropdown from './Dropdown';
|
||||||
import TimePicker from './TimePicker';
|
import TimePicker from './TimePicker';
|
||||||
|
import DateTimeLocalPicker from './DateTimeLocalPicker';
|
||||||
|
|
||||||
interface CreateRefCallback {
|
interface CreateRefCallback {
|
||||||
(ref: React.RefObject<HTMLCanvasElement>): void;
|
(ref: React.RefObject<HTMLCanvasElement>): void;
|
||||||
@@ -55,6 +56,11 @@ const Canvas = ({ width, height, onCreateRef }: CanvasProps) => {
|
|||||||
selector: string;
|
selector: string;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
|
||||||
|
const [dateTimeLocalInfo, setDateTimeLocalInfo] = React.useState<{
|
||||||
|
coordinates: Coordinates;
|
||||||
|
selector: string;
|
||||||
|
} | null>(null);
|
||||||
|
|
||||||
const notifyLastAction = (action: string) => {
|
const notifyLastAction = (action: string) => {
|
||||||
if (lastAction !== action) {
|
if (lastAction !== action) {
|
||||||
setLastAction(action);
|
setLastAction(action);
|
||||||
@@ -91,9 +97,15 @@ const Canvas = ({ width, height, onCreateRef }: CanvasProps) => {
|
|||||||
setTimePickerInfo(info);
|
setTimePickerInfo(info);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('showDateTimePicker', (info: {coordinates: Coordinates, selector: string}) => {
|
||||||
|
setDateTimeLocalInfo(info);
|
||||||
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.off('showDatePicker');
|
socket.off('showDatePicker');
|
||||||
socket.off('showDropdown');
|
socket.off('showDropdown');
|
||||||
|
socket.off('showTimePicker');
|
||||||
|
socket.off('showDateTimePicker');
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, [socket]);
|
}, [socket]);
|
||||||
@@ -222,6 +234,13 @@ const Canvas = ({ width, height, onCreateRef }: CanvasProps) => {
|
|||||||
onClose={() => setTimePickerInfo(null)}
|
onClose={() => setTimePickerInfo(null)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{dateTimeLocalInfo && (
|
||||||
|
<DateTimeLocalPicker
|
||||||
|
coordinates={dateTimeLocalInfo.coordinates}
|
||||||
|
selector={dateTimeLocalInfo.selector}
|
||||||
|
onClose={() => setDateTimeLocalInfo(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user