- {parseInt(refreshtime) === 0 && target === "page" && (
+ const toggleFullScreen = () =>
+ elementsCache.updateState(id, { isFullScreen: !isFullScreen })
+ const toggleRefreshPause = () =>
+ elementsCache.updateState(id, { refreshPaused: !refreshPaused })
+ console.log("type", type)
+ const RenderControls = () => (
+
)
-*/
- const contentStyle = {
- position: 'absolute',
- top: 0,
- left: 0,
- width: '100%',
- height: '100%',
- zIndex: isFullScreen ? '9999' : 'auto',
- display: isVisible ? 'block' : 'none',
+
+ let content = []
+ const onErrorLoading = () => {
+ console.log("Error loading content for " + id)
+ error_loading = true
}
- let content
if (type === "camera" || type === "image") {
- content =
+ )
} else {
- content = (
+ content.push(
)
}
- console.log("ExtraContentItem rendering for " + id, "is in cache: " + elementsCache.has(id))
- return (
-
+
+ content.push(
+
+
+ return (
+
- )*/
+ )
}
-export { ExtraContentItem }
\ No newline at end of file
+export { ExtraContentItem }
diff --git a/src/components/ExtraContent/index.js b/src/components/ExtraContent/index.js
index b9a4cfc2..0115aa4a 100644
--- a/src/components/ExtraContent/index.js
+++ b/src/components/ExtraContent/index.js
@@ -52,7 +52,7 @@ const ExtraContent = ({ id, source, refreshtime, label, type, target, icon }) =>
updateContentPosition()
useEffect(() => {
if (!elementsCache.has(extra_content_id)) {
- console.log("Creating element " + extra_content_id," because it doesn't exist")
+ //console.log("Creating element " + extra_content_id," because it doesn't exist")
elementsCache.create(extra_content_id, {
id,
source,
@@ -64,7 +64,7 @@ const ExtraContent = ({ id, source, refreshtime, label, type, target, icon }) =>
isVisible: true
})
} else {
- console.log("Updating element " + extra_content_id + " because it already exists")
+ //console.log("Updating element " + extra_content_id + " because it already exists")
elementsCache.updateState(extra_content_id, { isVisible: true})
}
@@ -87,8 +87,8 @@ const ExtraContent = ({ id, source, refreshtime, label, type, target, icon }) =>
main.removeEventListener('resize', handleScrollAndResize)
}
window.removeEventListener('resize', handleScrollAndResize)
- console.log("Hiding element " + extra_content_id)
- //elementsCache.updateState(extra_content_id, { isVisible: false })
+ //console.log("Hiding element " + extra_content_id)
+ elementsCache.updateState(extra_content_id, { isVisible: false })
}
}, [])
@@ -105,7 +105,7 @@ const ExtraContent = ({ id, source, refreshtime, label, type, target, icon }) =>
elementsCache.updateState(extra_content_id, { isFullScreen: !isFullScreen })
}
- const renderControls = () => (
+ const PanelRenderControls = () => (
panelId={extra_content_id}
onclick={handleFullScreen}
/>
- elementsCache.updateState(extra_content_id, { isVisible: false })}
/>
)
+ const PageRenderControls = () => (
+
+ }
+ onclick={handleRefresh}
+ />
+
+
+
+
+ )
+
if (target === "page") {
console.log("Rendering page element " + extra_content_id)
return (
-
-
- {renderControls()}
+
+
+ {/* content should fit this container */}
+
+
)
}
@@ -151,17 +170,12 @@ const ExtraContent = ({ id, source, refreshtime, label, type, target, icon }) =>
{T(label)}
- {renderControls()}
+ {PanelRenderControls()}
-
- {/* Host content */}
+
+ {/* content should fit this container */}
- {parseInt(refreshtime) > 0 && type !== "extension" && (
-
- )}
diff --git a/src/style/components/_app.scss b/src/style/components/_app.scss
index bc4de2b2..486331c3 100644
--- a/src/style/components/_app.scss
+++ b/src/style/components/_app.scss
@@ -19,10 +19,7 @@ body {
height: 100vh;
}
-.menu-container,
-.information-container {
- flex: 0 1 auto;
-}
+
.flex-row-between {
display: flex;
@@ -59,7 +56,7 @@ body {
}
.footer-container {
- height: 3rem;
+ height: 1rem;
}
.no-box {
@@ -115,13 +112,4 @@ body {
display: flex;
flex-direction: column;
}
-.extra-content-container {
- height: 100%;
- width: 100%;
- position:absolute;
- background-color: red!important;
- color: white!important;
- border: 1px solid red!important;
- z-index: 99999;
- opacity: 1;
-}
\ No newline at end of file
+
diff --git a/src/style/components/_control.scss b/src/style/components/_control.scss
index 6a892afa..7c10f306 100644
--- a/src/style/components/_control.scss
+++ b/src/style/components/_control.scss
@@ -316,11 +316,6 @@ span.input-group-addon {
border-radius: $border-radius;
}
-.image-container,
-.camera-container {
- border: none;
- width: 100%;
-}
.m-05 {
margin: 0.05rem !important;
@@ -334,11 +329,46 @@ span.input-group-addon {
}
.content-container,
-.extensionContainer {
+.extensionContainer ,
+.cameraContainer,
+.imageContainer {
border: none;
+ width: 100%;
+ height: 100%;
+}
+
+
+.page-container {
+ display:flex;
+ flex-direction: column;
+ height: calc(100% - 1rem);
+
+}
+.extra-content-container {
height: 100%;
width: 100%;
+ position:absolute;
+ background-color: red!important;
+ color: white!important;
+ border: 1px solid red!important;
+ z-index: 99999;
+ opacity: 1;
+ display: block;
}
+.fallback-content {
+ display: none;
+ text-align: center; font-size: 1.5rem; background-color: red; color: white; margin-top: 0.5rem;
+}
+
+.page-target-container {
+ flex:1;
+ z-index: 1;
+}
+
+.panel-target-container {
+ z-index: 1;
+}
+
.body-extension {
overflow-y: auto !important;
diff --git a/src/style/components/_menu.scss b/src/style/components/_menu.scss
index 9ff9ddf2..8893384e 100644
--- a/src/style/components/_menu.scss
+++ b/src/style/components/_menu.scss
@@ -37,6 +37,12 @@
color: #5755d9;
}
+.menu-container,
+.information-container {
+ flex: 0 1 auto;
+ z-index: auto;
+}
+
.menu-item-panel{
pointer-events: none!important;
}
From 80ddf570f07019e4503f3db64f1dc610ac68f421 Mon Sep 17 00:00:00 2001
From: Luc <8822552+luc-github@users.noreply.github.com>
Date: Mon, 29 Jul 2024 17:52:40 +0800
Subject: [PATCH 03/28] Add support for local url
Clean up code
Adjust CSS
---
.../ExtraContent/extraContentItem.js | 183 +++++++++---------
src/style/components/_control.scss | 22 ++-
2 files changed, 110 insertions(+), 95 deletions(-)
diff --git a/src/components/ExtraContent/extraContentItem.js b/src/components/ExtraContent/extraContentItem.js
index 39c2d22b..e843a74d 100644
--- a/src/components/ExtraContent/extraContentItem.js
+++ b/src/components/ExtraContent/extraContentItem.js
@@ -18,12 +18,12 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
import { Fragment, h } from "preact"
-import { useState, useEffect, useCallback } from "preact/hooks"
+import { useState, useEffect, useCallback, useRef } from "preact/hooks"
import { espHttpURL } from "../Helpers"
import { useHttpFn } from "../../hooks"
import { ButtonImg, ContainerHelper } from "../Controls"
import { T } from "../Translations"
-import { Play, Pause, Aperture, RefreshCcw } from "preact-feather"
+import { Play, Pause, Aperture } from "preact-feather"
import { elementsCache } from "../../areas/elementsCache"
const ExtraContentItem = ({
@@ -38,30 +38,11 @@ const ExtraContentItem = ({
refreshPaused = false,
}) => {
const [contentUrl, setContentUrl] = useState("")
+ const [hasError, setHasError] = useState(false)
+ const [isLoading, setIsLoading] = useState(true)
const { createNewRequest } = useHttpFn
- console.log(id)
const element_id = id.replace("extra_content_", type)
- let error_loading = false
- //console.log("ExtraContentItem rendering for " + id, "is in cache: " + elementsCache.has(id))
- /*const loadContent = useCallback((forceReload = false) => {
- if ( elementsCache.has(id) && !forceReload) {
- console.log("Content already loaded for " + id)
- return
- }
- if (source.startsWith("http") || forceReload) {
- setContentUrl(source)
- } else {
- const idquery = type === "content" ? type + id : "download" + id
- createNewRequest(
- espHttpURL(source),
- { method: "GET", id: idquery, max: 2 },
- {
- onSuccess: handleContentSuccess,
- onFail: handleContentError,
- }
- )
- }
- }, [id, source, type, createNewRequest])
+ const iframeRef = useRef(null)
const handleContentSuccess = useCallback((result) => {
let blob
@@ -79,39 +60,71 @@ const ExtraContentItem = ({
}
const url = URL.createObjectURL(blob)
setContentUrl(url)
+ setHasError(false)
+ setIsLoading(false)
}, [type])
const handleContentError = useCallback((error) => {
console.error(`Error loading content for ${id}:`, error)
- const errorContent = `
`
- const errorBlob = new Blob([errorContent], { type: "text/html" })
- setContentUrl(URL.createObjectURL(errorBlob))
+ setHasError(true)
+ setIsLoading(false)
}, [id])
- useEffect(() => {
- loadContent()
- }, [loadContent()])
-*/
- useEffect(() => {
- if (error_loading) {
- const fallback = document.getElementById("fallback_" + element_id)
- const element = document.getElementById(element_id)
- if (fallback) {
- fallback.style.display = "block"
- if (element) {
- element.style.display = "none"
+ const loadContent = useCallback((forceReload = false) => {
+ console.log("Loading content for " + id)
+ setIsLoading(true)
+ if (source.startsWith("http") || forceReload) {
+ console.log("Loading URL " + source)
+ setContentUrl(source)
+ setHasError(false)
+ setIsLoading(false)
+ } else {
+ const idquery = type === "content" ? type + id : "download" + id
+ createNewRequest(
+ espHttpURL(source),
+ { method: "GET", id: idquery, max: 2 },
+ {
+ onSuccess: handleContentSuccess,
+ onFail: handleContentError,
}
- }
+ )
}
- }, [])
- const handleRefresh = () => loadContent(true)
+ }, [id, source, type, createNewRequest, handleContentSuccess, handleContentError])
+
+ useEffect(() => {
+ loadContent()
+ }, [loadContent])
+
+ const handleError = () => {
+ console.log("Error loading content for " + id)
+ setHasError(true)
+ setIsLoading(false)
+ }
+
+ const handleLoad = () => {
+ console.log("Load done for " + id)
+ setHasError(false)
+ setIsLoading(false)
+
+ if (type === "extension" && iframeRef.current) {
+ const iframe = iframeRef.current
+ const doc = iframe.contentWindow.document
+ const body = doc.querySelector("body")
+ body.classList.add("body-extension")
+ const css = document.querySelectorAll("style")
+ css.forEach((csstag) => {
+ doc.head.appendChild(csstag.cloneNode(true))
+ })
+ }
+ }
+
const toggleFullScreen = () =>
elementsCache.updateState(id, { isFullScreen: !isFullScreen })
const toggleRefreshPause = () =>
elementsCache.updateState(id, { refreshPaused: !refreshPaused })
- console.log("type", type)
+
const RenderControls = () => (
-