better code: misplaced component

Massimo Melina committed Jan 15, 2022 at 17:41 UTC ec18e7da8e6177d5462c55cc8af4ee118675bac9
3 files changed +11 -11
frontend/src/BrowseFiles.ts
+2 -2
@@ -1,7 +1,7 @@
1 import { Link, useLocation } from 'react-router-dom'
2 import { createContext, createElement as h, Fragment, useContext, useEffect, useMemo, useState } from 'react'
3 -import { formatBytes, hError, hIcon, Html, hfsEvent } from './misc'
4 -import { Spinner } from './components'
3 +import { formatBytes, hError, hIcon, hfsEvent } from './misc'
4 +import { Html, Spinner } from './components'
5 import { Head } from './Head'
6 import { state, useSnapState } from './state'
7 import _ from 'lodash'
frontend/src/components.ts
+8 -1
@@ -1,5 +1,5 @@
1 import { hIcon } from './misc'
2 -import { createElement as h, ReactNode } from 'react'
2 +import { createElement as h, HTMLAttributes, ReactNode, useMemo } from 'react'
3
4 export function Spinner() {
5 return hIcon('spinner', { className:'spinner' })
@@ -43,3 +43,10 @@ export function Select({ onChange, value, options, ...props }:SelectProps) {
43 ...props,
44 }, options.map(({ value, label }) => h('option', { key:value, value }, label)))
45 }
46 +
47 +export function Html({ code, ...rest }:{ code:string } & HTMLAttributes<any>) {
48 + const o = useMemo(() => ({ __html: code }), [code])
49 + if (!code)
50 + return null
51 + return h('span', { ...rest, dangerouslySetInnerHTML: o })
52 +}
frontend/src/misc.ts
+1 -8
@@ -1,4 +1,4 @@
1 -import { createElement as h, HTMLAttributes, useCallback, useMemo, useState } from 'react'
1 +import { createElement as h, useCallback, useState } from 'react'
2 import { Spinner } from './components'
3 import { newDialog } from './dialog'
4 import { Icon } from './icons'
@@ -94,13 +94,6 @@ export function getCookie(name: string) {
94 return ''
95 }
96
97 -export function Html({ code, ...rest }:{ code:string } & HTMLAttributes<any>) {
98 - const o = useMemo(() => ({ __html: code }), [code])
99 - if (!code)
100 - return null
101 - return h('span', { ...rest, dangerouslySetInnerHTML: o })
102 -}
103 -
97 export function hfsEvent(name: string, params?:Dict) {
98 const output: any[] = []
99 document.dispatchEvent(new CustomEvent('hfs.'+name, { detail:{ params, output } }))