Skip to content

Commit

Permalink
chore(build): cleanup code visibility handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mwfarb committed Jul 3, 2024
1 parent e77ecca commit 89a0ed0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
16 changes: 13 additions & 3 deletions build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,19 @@ window.addEventListener('onauth', async (e) => {
});
};

// we indicate this function as the visibility edit handler to persist
const visObject = async function (obj) {
// obj is already updated with minor updates for visibility
/**
* The visibility edit handler to persist. Update visible property, publish, refresh list.
* @param {Object} refObj The object referenced in the list, used for 1 param update.
* @param {boolean} visible If the object should be visible.
*/
const visObject = async function (refObj, visible) {
const obj = {
object_id: refObj.object_id,
action: 'update',
persist: true,
type: refObj.type,
data: { visible },
};
const scene = `${namespaceinput.value}/${sceneinput.value}`;
PersistObjects.performActionArgObjList('update', scene, [obj], false);
setTimeout(async () => {
Expand Down
26 changes: 10 additions & 16 deletions build/persist-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ export async function fetchSceneObjects(scene) {
return sceneObjs;
}

export function updateListItemVisibility(visible, li, iconVis) {
iconVis.className = visible ? 'icon-eye-open' : 'icon-eye-close';
li.style.color = visible ? 'black' : 'gray';
}

export async function populateObjectList(scene, filter, objTypeFilter, focusObjectId = undefined) {
clearObjectList();

Expand Down Expand Up @@ -344,29 +349,18 @@ export async function populateObjectList(scene, filter, objTypeFilter, focusObje

// add visibility convenience "button"
let visible = Object.hasOwn(sceneObjs[i].attributes, 'visible') ? sceneObjs[i].attributes.visible : true;
// console.log(sceneObjs[i].object_id, sceneObjs[i].attributes.visible);
const visspan = document.createElement('span');
const ielemvis = document.createElement('i');
ielemvis.className = visible ? 'icon-eye-open' : 'icon-eye-close';
li.style.color = visible ? 'black' : 'gray';
const iconVis = document.createElement('i');
updateListItemVisibility(visible, li, iconVis);
visspan.className = 'visible';
visspan.title = 'Toggle Visible';
visspan.appendChild(ielemvis);
visspan.appendChild(iconVis);
li.appendChild(visspan);

visspan.onclick = function () {
visible = !visible;
ielemvis.className = visible ? 'icon-eye-open' : 'icon-eye-close';
li.style.color = visible ? 'black' : 'gray';
const obj = {
object_id: sceneObjs[i].object_id,
action: 'update',
persist: true,
type: sceneObjs[i].type,
data: { visible },
};

persist.visObjHandler(obj);
updateListItemVisibility(visible, li, iconVis);
persist.visObjHandler(sceneObjs[i], visible);
};

persist.objList.appendChild(li);
Expand Down

0 comments on commit 89a0ed0

Please sign in to comment.