better code

Massimo Melina committed Oct 5, 2024 at 18:50 UTC 5e6b0c9aa62615c38e31978df477dce89ec734b6
3 files changed +9 -8
frontend/src/BrowseFiles.ts
+2 -2
@@ -16,7 +16,7 @@ import _ from 'lodash'
16 import { t, useI18N } from './i18n'
17 import { makeOnClickOpen, openFileMenu } from './fileMenu'
18 import { ClipBar } from './clip'
19 -import { fileShow, getShowType } from './show'
19 +import { fileShow, getShowComponent } from './show'
20
21 export const MISSING_PERM = "Missing permission"
22
@@ -295,7 +295,7 @@ const Entry = ({ entry, midnight, separator }: EntryProps) => {
295 if (ev.altKey || ev.ctrlKey || isMac && ev.metaKey) return
296 ev.preventDefault()
297 const special = isMac ? ev.shiftKey : ev.metaKey
298 - if (special && getShowType(entry))
298 + if (special && getShowComponent(entry))
299 return fileShow(entry, { startPlaying: true })
300 openFileMenu(entry, ev, onlyTruthy([
301 file_menu_on_link && 'open',
frontend/src/fileMenu.ts
+2 -2
@@ -9,7 +9,7 @@ import { getEntryIcon, MISSING_PERM } from './BrowseFiles'
9 import { DirEntry, state } from './state'
10 import { deleteFiles } from './menu'
11 import { Link, LinkProps } from 'react-router-dom'
12 -import { fileShow, getShowType } from './show'
12 +import { fileShow, getShowComponent } from './show'
13 import { alertDialog, promptDialog, toast } from './dialog'
14 import { apiCall, useApi } from '@hfs/shared/api'
15 import { inputComment } from './upload'
@@ -56,7 +56,7 @@ export function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: (Falsy
56 onClick: () => deleteFiles([entry.uri])
57 }
58 if (x === 'show')
59 - return !entry.cantOpen && getShowType(entry) && {
59 + return !entry.cantOpen && getShowComponent(entry) && {
60 id: 'show',
61 label: t`Show`,
62 icon: 'image',
frontend/src/show.ts
+5 -4
@@ -84,7 +84,8 @@ export function fileShow(entry: DirEntry, { startPlaying=false } = {}) {
84 }
85 })
86 const [showNav, setShowNav] = useState(false)
87 - const isAudio = getShowType(cur) === Audio
87 + const component = getShowComponent(cur)
88 + const isAudio = component === Audio
89 useEffect(() => setShowNav(isAudio), [isAudio])
90 const timerRef = useRef(0)
91 const navClass = 'nav' + (showNav ? '' : ' nav-hidden')
@@ -169,7 +170,7 @@ export function fileShow(entry: DirEntry, { startPlaying=false } = {}) {
170 t`Loading failed`
171 ) : h('div', { className: 'showing-container', ref: containerRef },
172 h('div', { className: 'cover ' + (cover ? '' : 'none'), style: { backgroundImage: cover && `url("${cover}")` } }),
172 - h(getShowType(cur) || Fragment, {
173 + h(component || Fragment, {
174 src: cur.uri,
175 className: 'showing',
176 onLoad() {
@@ -245,7 +246,7 @@ export function fileShow(entry: DirEntry, { startPlaying=false } = {}) {
246 goTo(e)
247
248 function anyGood() {
248 - return e && !e.isFolder && getShowType(e)
249 + return e && !e.isFolder && getShowComponent(e)
250 }
251 }
252
@@ -307,7 +308,7 @@ export function fileShow(entry: DirEntry, { startPlaying=false } = {}) {
308 })
309 }
310
310 -export function getShowType(entry: DirEntry) {
311 +export function getShowComponent(entry: DirEntry) {
312 const res = hfsEvent('fileShow', { entry }).find(Boolean)
313 if (res)
314 return res