Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make extra Content persistent #398

Merged
merged 28 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c68cf0e
split container and content for better readibility - WIP - POC
luc-github Jul 28, 2024
75b16e5
Adjust buttons with target container - WIP - POC
luc-github Jul 29, 2024
80ddf57
Add support for local url
luc-github Jul 29, 2024
9386552
Update index.js
luc-github Jul 29, 2024
531ae02
do some z-index consistency
luc-github Jul 29, 2024
4545ed6
Refactorize the cache creation using Preact way instead of js vanilla…
luc-github Jul 30, 2024
278dc1e
Code base of eventBus
luc-github Jul 31, 2024
da294fc
Make extracontent panels header same size a others panels
luc-github Jul 31, 2024
0b8ff48
Rewrite FullScreenButton
luc-github Jul 31, 2024
517f092
Rewrite CloseButton
luc-github Jul 31, 2024
e3be6b0
code cleaning on extra pages
luc-github Jul 31, 2024
cb4c371
Fix css
luc-github Jul 31, 2024
764f17c
code cleaning
luc-github Aug 1, 2024
d4314f3
maximize image/camera while keeping proportion and keep space for but…
luc-github Aug 1, 2024
637f574
Add capture image
luc-github Aug 1, 2024
bc80a4a
Add Autorefresh + play/pause for image and
luc-github Aug 1, 2024
ab286b9
Code cleanup
luc-github Aug 1, 2024
930e55c
Remove ref and use node
luc-github Aug 1, 2024
c812f7b
Update UiContext.js
luc-github Aug 2, 2024
d908554
Remove useless functions
luc-github Aug 2, 2024
b2e7975
Sanitify eventsBus
luc-github Aug 2, 2024
a16320f
put handleScrollAndResize in a callback
luc-github Aug 3, 2024
a70bf18
Fix extracontent does not show is not enabled at start
luc-github Aug 3, 2024
87d104e
Update gcodeViewer.html
luc-github Aug 3, 2024
f577d34
clean comments
luc-github Aug 3, 2024
ef32232
Fix duplicate call for unmount
luc-github Aug 3, 2024
5f0b2e9
Adjust visibility check for target==page
luc-github Aug 3, 2024
1a98c68
package gcodeviewer extension
luc-github Aug 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added extensions/gcodeViewer/dist/gcodeViewer.html.gz
Binary file not shown.
50 changes: 0 additions & 50 deletions extensions/gcodeViewer/dist/gcodeViewer.html/gcodeViewer.html

This file was deleted.

850 changes: 568 additions & 282 deletions extensions/gcodeViewer/src/gcodeViewer.html

Large diffs are not rendered by default.

102 changes: 102 additions & 0 deletions src/areas/elementsCache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
elementsCache.js - ESP3D WebUI MainPage file

Copyright (c) 2020 Luc Lebosse. All rights reserved.
Original code inspiration : 2021 Alexandre Aussourd

This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with This code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
import { h, render } from "preact"
import { useState, useEffect, useMemo } from "preact/hooks"
import { ExtraContentItem } from "../components/ExtraContent"
import { useUiContext,useUiContextFn, useSettingsContext } from "../contexts"
import { eventBus } from "../hooks/eventBus"

const ElementsCache = () => {
const { ui } = useUiContext()
const { interfaceSettings } = useSettingsContext()
const [content, setContent] = useState([])

const extractValues = (entry) => {
const result = { id: "extra_content_" + entry.id };
entry.value.forEach(param => {
result[param.name] = param.value;
});
return result;
};
console.log("ElementsCache is rendering")
useEffect(() => {
if (ui.ready && interfaceSettings.current?.settings?.extracontents) {
//console.log("ElementsCache can now be created")
const isEnabled = useUiContextFn.getValue("showextracontents")
if (!isEnabled) {
console.log("ExtraContent are disabled")
return
}
const isVisibleOnStart = useUiContextFn.getValue("openextrapanelsonstart")
const extraContentSettings = interfaceSettings.current.settings.extracontents;
const extraContentsEntry = extraContentSettings.find(entry => entry.id === 'extracontents');

if (extraContentsEntry?.value?.length > 0) {
const newContent = extraContentsEntry.value.map(entry => {
const item = extractValues(entry)
// console.log(item)
return <ExtraContentItem key={item.id} {...item} isVisibleOnStart={isVisibleOnStart} />
});
setContent(newContent);
}
}
}, [ui.ready, interfaceSettings]);

const memoizedContent = useMemo(() => content, [content]);

return (
<div style="position: fixed; top: 0; left: 0; width: 0; height: 0; overflow: visible;" id="elementsCache">
{memoizedContent}
</div>
)
}

export default ElementsCache;

const elementsCache = {

isExtraContent: (id) => {
const itemid = "extra_content_" + id
return elementsCache.has(itemid)
},

getRootfromId: (id) => {
return id.replace("extra_content_", "")
},

getIdFromRoot: (id) => {
return "extra_content_" + id
},

has: (id) => {
const cacheHost = document.getElementById("elementsCache")
if (!cacheHost) return false
return cacheHost.querySelector('#' + id) !== null
},

get: (id) => {
const cacheHost = document.getElementById("elementsCache")
if (!cacheHost) return null
return cacheHost.querySelector('#' + id)
}
}

export { ElementsCache, elementsCache }
9 changes: 5 additions & 4 deletions src/components/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,23 @@ import {
WsContextProvider,
} from "../../contexts"
import { TargetContextProvider } from "../../targets"
import { ToastsContainer } from "../Toast"
import { ModalContainer } from "../Modal"
import { ContainerHelper } from "../Controls"
import { ContentContainer } from "../../areas"
import { ElementsCache } from "../../areas/elementsCache"

const App = () => {
return (
<div id="app">

<DatasContextProvider>
<TargetContextProvider>
<RouterContextProvider>
<UiContextProvider>
<HttpQueueContextProvider>
<SettingsContextProvider>
<WsContextProvider>
<ToastsContainer id="top_toasts_container"/>
<ModalContainer id="top_modals_container"/>
<ContainerHelper id="top_container" active={true}/>
<ElementsCache />
<ContentContainer />
</WsContextProvider>
</SettingsContextProvider>
Expand Down
48 changes: 30 additions & 18 deletions src/components/Controls/CloseButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,57 @@
*/
import { h } from "preact"
import { useState, useEffect } from "preact/hooks"

import { useUiContext, useUiContextFn } from "../../contexts"
import { eventBus } from "../../hooks/eventBus"
import { elementsCache } from "../../areas/elementsCache"

const isFullScreen = (element) => {
return document.fullscreenElement === element
}

const CloseButton = ({ panelRef, panelId, hideOnFullScreen, callbackfn }) => {
const CloseButton = ({elementId, hideOnFullScreen, onclick }) => {
const { panels } = useUiContext()
const [isFullScreenMode, setIsFullScreenMode] = useState(false)

//at each render, check if the element is fullscreen
useEffect(() => {
const handleFullscreenChange = () => {
setIsFullScreenMode(isFullScreen(panelRef.current))
//Handle fullscreen change event
const handleFullScreenChange = () => {
const element =document.getElementById(elementId)
if ( document.getElementById(elementId)) {
//console.log("Button close Fullscreen state changed for " + elementId)
setIsFullScreenMode(document.fullscreenElement==element)
}
}

document.addEventListener("fullscreenchange", handleFullscreenChange)

//Add event listener to handle fullscreen change
document.addEventListener("fullscreenchange", handleFullScreenChange)
//Remove event listener on unmount
return () => {
document.removeEventListener(
"fullscreenchange",
handleFullscreenChange
handleFullScreenChange
)
}
}, [panelRef])

})
//Hide the button if fullscreen mode is active and hideOnFullScreen is true
if (hideOnFullScreen && isFullScreenMode) {
return null
}

//display the button according to the props
return (
<span
class="btn btn-clear btn-close m-1"
aria-label="Close"
onclick={(e) => {
useUiContextFn.haptic()
panels.hide(panelId)
if (callbackfn) {
callbackfn()
panels.hide(elementId)
console.log("Close button clicked for element " + elementId)
if (elementsCache.isExtraContent(elementId)) {
console.log("emit for root element " + elementsCache.getIdFromRoot(elementId), " isVisible: false")
eventBus.emit('updateState', {id: elementsCache.getIdFromRoot(elementId), isVisible: false, from: "closeButton"})
} else {
console.log("emit for element " + elementId, " isVisible: false")
eventBus.emit('updateState', {id: elementId, isVisible: false, from: "closeButton"})

}
if (onclick) {
onclick()
}
}}
/>
Expand Down
53 changes: 35 additions & 18 deletions src/components/Controls/ContainerHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,46 @@ ContainerHelper.js - ESP3D WebUI component file
*/

import { Fragment, h } from "preact"
import { getFullscreenElement } from "../Helpers"
import { ModalContainer } from "../Modal"
import { ToastsContainer } from "../Toast"
import { useState, useEffect, } from "preact/hooks"
import { eventBus } from "../../hooks/eventBus"

const ContainerHelper = (props) => {
const { id } = props
//console.log("ContainerHelper id", id)
const fullScreenElement = getFullscreenElement()
if (!fullScreenElement) {
//console.log("No fullscreen element")
return null
} else {
//console.log("Fullscreen element", fullScreenElement.id)
}
//console.log("ContainerHelper id ", id, " vs fullscreen element id ", fullScreenElement.id)
if (fullScreenElement.id != id) {
return null
}
return (
const ContainerHelper = ({id, active=false}) => {

const [enabled, setEnabled] = useState(active)
//console.log("ContainerHelper id", id ,"active", active)
const listenerId = `listener_containerhelper_${id}`;
useEffect(() => {
const handleUpdateState = (msg) => {
if ('isFullScreen' in msg) {
if (msg.isFullScreen) {
if (id==msg.id) {
setEnabled(true)
} else {
setEnabled(false)
}
} else {
if (id==="top_container") {
setEnabled(true)
} else {
setEnabled(false)
}
}
}
}
eventBus.on("updateState", handleUpdateState, listenerId)
return () => {
//eventBus.off("updateState", handleUpdateState,listenerId)
}})


if (enabled)return (
<Fragment>
<ModalContainer id={"modal_" + id} />
<ToastsContainer id={"toast_" + id} />
<ModalContainer />
<ToastsContainer />
</Fragment>
)
return null
}
export default ContainerHelper
Loading
Loading