Skip to content

Commit

Permalink
Merge pull request #6291 from mozilla:object-list-fixes
Browse files Browse the repository at this point in the history
Object list fixes
  • Loading branch information
keianhzo authored Sep 27, 2023
2 parents ff9b049 + 8edce43 commit 2b999e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/react-components/room/object-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { rotateInPlaceAroundWorldUp, affixToWorldUp } from "../../utils/three-ut
import { getPromotionTokenForFile } from "../../utils/media-utils";
import { hasComponent } from "bitecs";
import { isPinned as getPinnedState } from "../../bit-systems/networking";
import { MediaInfo, Static } from "../../bit-components";
import { AEntity, MediaInfo, Static } from "../../bit-components";
import { deleteTheDeletableAncestor } from "../../bit-systems/delete-entity-system";
import { isAEntityPinned } from "../../systems/hold-system";

export function isMe(object) {
return object.id === "avatar-rig";
Expand Down Expand Up @@ -39,8 +40,16 @@ export function getObjectUrl(object) {
return null;
}

function isObjectPinned(world, eid) {
if (hasComponent(world, AEntity, eid)) {
return isAEntityPinned(APP.world, eid);
} else {
return getPinnedState(eid);
}
}

export function usePinObject(hubChannel, scene, object) {
const [isPinned, setIsPinned] = useState(getPinnedState(object.eid));
const [isPinned, setIsPinned] = useState(isObjectPinned(APP.world, object.eid));

const pinObject = useCallback(() => {
const el = object.el;
Expand Down Expand Up @@ -71,11 +80,11 @@ export function usePinObject(hubChannel, scene, object) {
const el = object.el;

function onPinStateChanged() {
setIsPinned(getPinnedState(el.eid));
setIsPinned(isObjectPinned(APP.world, object.eid));
}
el.addEventListener("pinned", onPinStateChanged);
el.addEventListener("unpinned", onPinStateChanged);
setIsPinned(getPinnedState(el.eid));
setIsPinned(isObjectPinned(APP.world, object.eid));
return () => {
el.removeEventListener("pinned", onPinStateChanged);
el.removeEventListener("unpinned", onPinStateChanged);
Expand Down Expand Up @@ -148,7 +157,7 @@ export function useRemoveObject(hubChannel, scene, object) {
const canRemoveObject = !!(
scene.is("entered") &&
!isPlayer(object) &&
!getPinnedState(eid) &&
!isObjectPinned(APP.world, object.eid) &&
!hasComponent(APP.world, Static, eid) &&
hubChannel.can("spawn_and_move_media")
);
Expand Down
2 changes: 1 addition & 1 deletion src/systems/hold-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function hasPermissionToGrab(world, eid) {
return canMove(world.eid2obj.get(eid).el);
}

function isAEntityPinned(world, eid) {
export function isAEntityPinned(world, eid) {
if (hasComponent(world, AEntity, eid)) {
const el = world.eid2obj.get(eid).el;
return !!el.components?.pinnable?.data?.pinned;
Expand Down

0 comments on commit 2b999e9

Please sign in to comment.