Skip to content

Commit

Permalink
Adjust visibility check for target==page
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-github committed Aug 3, 2024
1 parent ef32232 commit 5f0b2e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/components/ExtraContent/extraContentItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const ExtraContentItem = ({
console.log(useUiContextFn.panels.isVisible(elementsCache.getRootfromId(id)))
}

if (isPaused || !visibilityState[id] || !useUiContextFn.panels.isVisible(elementsCache.getRootfromId(id))) return
if (isPaused || !visibilityState[id] || (target=="panel" && !useUiContextFn.panels.isVisible(elementsCache.getRootfromId(id)))) return
setIsLoading(true)
if (source.startsWith("http")) {
setContentUrl(source)
Expand Down Expand Up @@ -117,16 +117,16 @@ const ExtraContentItem = ({
const listenerId = `listener_${id}`;
const handleUpdateState = (msg) => {
if (msg.id == id) {
//console.log(`Received message for ${id} with listener ${listenerId}`, msg);
console.log(`Received message for ${id} with listener ${listenerId}`, msg);
const element = document.getElementById(id)
if ( 'forceRefresh' in msg && msg.forceRefresh) {
//console.log(`Processing forceRefresh for ${id}`);
console.log(`Processing forceRefresh for ${id}`);
loadContent()
}
if ('isVisible' in msg) {

if (element) {
//console.log("Updating visibility for element " + id + " to " + msg.isVisible)
console.log("Updating visibility for element " + id + " to " + msg.isVisible)
element.style.display = msg.isVisible ? 'block' : 'none';
//is it the same as the current state?
if (visibilityState[id]!= msg.isVisible){
Expand All @@ -152,8 +152,8 @@ const ExtraContentItem = ({

}
if ('position' in msg) {
//console.log("Updating position for element " + id )
//console.log(msg.position)
console.log("Updating position for element " + id )
console.log(msg.position)
const element = document.getElementById(id)
element.style.top = `${msg.position.top}px`;
element.style.left = `${msg.position.left}px`;
Expand All @@ -164,7 +164,7 @@ const ExtraContentItem = ({
}
eventBus.on("updateState", handleUpdateState, listenerId)
return () => {
//console.log(`Removing listener ${listenerId} for ${id}`);
console.log(`Removing listener ${listenerId} for ${id}`);
//eventBus.off("updateState", handleUpdateState, listenerId)
}
}, [id, loadContent])
Expand Down
13 changes: 9 additions & 4 deletions src/components/ExtraContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ const ExtraContent = ({ id, source, refreshtime, label, type, target, icon }) =>
console.log("Extra Content " + id)

const updateContentPosition = () => {
if (!useUiContextFn.panels.isVisible(id)) return
//console.log("Updating position for element " + extra_content_id, "in target", target_id, " of panel ", id)
if (!useUiContextFn.panels.isVisible(id)&& target=="panel") {
console.log("Not updating position for element " + extra_content_id, "in target", target_id, " of panel ", id, " because it is not visible")
return
}
console.log("Updating position for element " + extra_content_id, "in target", target_id, " of panel ", id)
const container = document.getElementById(target_id)
if (container) {
const { top, left, width, height } = container.getBoundingClientRect()
Expand Down Expand Up @@ -83,8 +86,10 @@ const ExtraContent = ({ id, source, refreshtime, label, type, target, icon }) =>
if (!elementsCache.has(extra_content_id)) {
console.error("Error display element " + extra_content_id, " because it doesn't exist")
} else {
//console.log("Updating element " + extra_content_id + " because it already exists")
updateContentPosition()
console.log("Updating element " + extra_content_id + " because it already exists")
if (target=="page"){
updateContentPosition()
}
}

const main = document.getElementById("main")
Expand Down
2 changes: 2 additions & 0 deletions src/contexts/UiContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ const UiContextProvider = ({ children }) => {
}, [panelsList, panelsOrder]);

const isPanelVisible = useCallback((id) => {
console.log("Checking visibility for panel " + id)
console.log(visiblePanelsListRef.current)
return visiblePanelsListRef.current.some((element) => element.id == id);
}, []);

Expand Down

0 comments on commit 5f0b2e9

Please sign in to comment.