diff --git a/demo/src/components/Image.tsx b/demo/src/components/Image.tsx index dd7f9311..3a91253b 100644 --- a/demo/src/components/Image.tsx +++ b/demo/src/components/Image.tsx @@ -13,7 +13,7 @@ interface Props extends React.HTMLAttributes { export const Image = ({ src, children, className, id, slide, locatable = true }: Props) => { const { members, self } = useMembers(); - const { handleSelect } = useElementSelect(id); + const { handleSelect } = useElementSelect(id, false); const activeMember = findActiveMember(id, slide, members); const { outlineClasses, stickyLabelClasses } = getOutlineClasses(activeMember); const memberName = getMemberFirstName(activeMember); diff --git a/demo/src/hooks/useElementSelect.ts b/demo/src/hooks/useElementSelect.ts index 4de28cfc..d17f2c5e 100644 --- a/demo/src/hooks/useElementSelect.ts +++ b/demo/src/hooks/useElementSelect.ts @@ -15,18 +15,12 @@ export const useElementSelect = (element?: string, lockable: boolean = true) => const lockId = buildLockId(self.location?.slide, element); const lock = space.locks.get(lockId); - if (lock?.request.status === 'locked' && self.locks.get(lockId)) { - // alert('You are already locking this location'); - } else if (lock?.request.status === 'locked') { - // alert('Location is locked by another user'); - } else { - if (/*window.confirm('Would you like to lock this location?')*/ true) { - await releaseMyLocks(space, self); - await space.locks.acquire(lockId); + if (lock?.request.status !== 'locked') { + await releaseMyLocks(space, self); + await space.locks.acquire(lockId); - // The lock is pending but we enter the location optimistically - space.locations.set({ slide: self.location?.slide, element }); - } + // The lock is pending but we enter the location optimistically + space.locations.set({ slide: self.location?.slide, element }); } } else { await releaseMyLocks(space, self); diff --git a/demo/src/hooks/useLock.ts b/demo/src/hooks/useLock.ts index 847a29f8..6f449274 100644 --- a/demo/src/hooks/useLock.ts +++ b/demo/src/hooks/useLock.ts @@ -6,10 +6,7 @@ import { SpacesContext } from '../components'; import { buildLockId } from '../utils/locking'; import { isMember, useMembers } from '../hooks'; -import { getMemberFirstName } from '../utils'; - import { type Member } from '../utils/types'; -import members from '../../../src/Members.ts'; export const useLock = (slide: string, id: string): { status?: string; member?: Member } => { const space = useContext(SpacesContext); @@ -52,24 +49,6 @@ export const useLock = (slide: string, id: string): { status?: string; member?: return { status, member }; }; -export const useLockLabelCallback = (slide: string, id: string, selfConnectionId?: string) => { - const { member, status } = useLock(slide, id); - const [label, setLabel] = useState(undefined); - - useEffect(() => { - // We're locking this component - if (status === 'locked' && member?.connectionId === selfConnectionId) { - setLabel(`Locked by You`); - } else if (status === 'locked') { - setLabel(`Locked by ${getMemberFirstName(member)}`); - } else if (status === 'unlocked') { - setLabel(undefined); - } - }, [member, status, slide, id, selfConnectionId]); - - return label; -}; - export const useLockStatus = (slide: string, id: string, selfConnectionId?: string) => { const { member, status } = useLock(slide, id); diff --git a/demo/src/utils/locking.ts b/demo/src/utils/locking.ts index c27cc914..e54def97 100644 --- a/demo/src/utils/locking.ts +++ b/demo/src/utils/locking.ts @@ -7,4 +7,5 @@ export const releaseMyLocks = async (space: Space, self: Member) => { } }; -export const buildLockId = (slide: string, element: string | undefined) => `/slide/${slide}/element/${element}`; +export const buildLockId = (slide: string | undefined, element: string | undefined) => + `/slide/${slide}/element/${element}`;