mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-04 14:30:29 +03:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { useCallback } from 'react';
|
|
import { useAtomValue, useSetAtom } from 'jotai';
|
|
import { Position, RectCords } from 'folds';
|
|
import { userRoomProfileAtom, UserRoomProfileState } from '../userRoomProfile';
|
|
|
|
export const useUserRoomProfileState = (): UserRoomProfileState | undefined => {
|
|
const data = useAtomValue(userRoomProfileAtom);
|
|
|
|
return data;
|
|
};
|
|
|
|
type CloseCallback = () => void;
|
|
export const useCloseUserRoomProfile = (): CloseCallback => {
|
|
const setUserRoomProfile = useSetAtom(userRoomProfileAtom);
|
|
|
|
const close: CloseCallback = useCallback(() => {
|
|
setUserRoomProfile(undefined);
|
|
}, [setUserRoomProfile]);
|
|
|
|
return close;
|
|
};
|
|
|
|
type OpenCallback = (
|
|
roomId: string,
|
|
spaceId: string | undefined,
|
|
userId: string,
|
|
cords: RectCords,
|
|
position?: Position
|
|
) => void;
|
|
export const useOpenUserRoomProfile = (): OpenCallback => {
|
|
const setUserRoomProfile = useSetAtom(userRoomProfileAtom);
|
|
|
|
const open: OpenCallback = useCallback(
|
|
(roomId, spaceId, userId, cords, position) => {
|
|
setUserRoomProfile({ roomId, spaceId, userId, cords, position });
|
|
},
|
|
[setUserRoomProfile]
|
|
);
|
|
|
|
return open;
|
|
};
|