-
-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make extra Content persistent (#398)
* split container and content for better readibility * package gcodeviewer extension
- Loading branch information
1 parent
8f7e11b
commit aeeacd9
Showing
39 changed files
with
1,588 additions
and
944 deletions.
There are no files selected for viewing
Binary file not shown.
50 changes: 0 additions & 50 deletions
50
extensions/gcodeViewer/dist/gcodeViewer.html/gcodeViewer.html
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.