Files
motr/ui/dash/scripts_templ.go
2025-06-02 12:35:12 -07:00

61 lines
3.9 KiB
Go

// Code generated by templ - DO NOT EDIT.
// templ: version: v0.3.857
package dash
//lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"
var heliaCardScriptHandle = templ.NewOnceHandle()
func ScriptTag() templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
if templ_7745c5c3_Var1 == nil {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Var2 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<script>\n document.addEventListener('DOMContentLoaded', async () => {\n try {\n // Use the globally available instantiateHeliaNode function\n const helia = window.helia = await window.instantiateHeliaNode()\n window.heliaFs = await HeliaUnixfs.unixfs(helia)\n\n helia.libp2p.addEventListener('peer:discovery', (evt) => {\n window.discoveredPeers.set(evt.detail.id.toString(), evt.detail)\n addToLog(`Discovered peer ${evt.detail.id.toString()}`)\n })\n\n helia.libp2p.addEventListener('peer:connect', (evt) => {\n addToLog(`Connected to ${evt.detail.toString()}`)\n })\n \n helia.libp2p.addEventListener('peer:disconnect', (evt) => {\n addToLog(`Disconnected from ${evt.detail.toString()}`)\n })\n\n setInterval(() => {\n const statusValueEl = document.getElementById('statusValue')\n if (statusValueEl) {\n statusValueEl.innerHTML = helia.libp2p.status === 'started' ? 'Online' : 'Offline'\n }\n updateConnectedPeers()\n updateDiscoveredPeers()\n }, 500)\n\n const id = await helia.libp2p.peerId.toString()\n const nodeIdEl = document.getElementById('nodeId')\n if (nodeIdEl) {\n nodeIdEl.innerHTML = id\n }\n addToLog('Helia node initialized successfully')\n } catch (err) {\n addToLog(`Error initializing Helia: ${err.message}`)\n console.error('Error initializing Helia:', err)\n }\n })\n </script>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
templ_7745c5c3_Err = heliaCardScriptHandle.Once().Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
var _ = templruntime.GeneratedTemplate