@samitouri / QOSami-HFS / commits / 6a440852

better code

Massimo Melina committed Apr 12, 2024 at 11:51 UTC 6a4408523ac0860cda8aefa7cbbbd2b0e97014cb
1 file changed +33 -29
admin/src/VfsMenuBar.ts
+33 -29
@@ -16,8 +16,6 @@ import { formatDiskSpace } from './FilePicker'
16 import { getDiskSpaces } from '../../src/util-os'
17
18 export default function VfsMenuBar({ statusApi }: { statusApi: ApiObject }) {
19 - const isWindows = statusApi.data?.platform === 'win32'
20 - const { data: integrated, reload } = useApi(isWindows && 'windows_integrated')
19 return h(Flex, {
20 mb: 2,
21 zIndex: 2,
@@ -40,33 +38,7 @@ export default function VfsMenuBar({ statusApi }: { statusApi: ApiObject }) {
38 .then(() => false), // no success-animation for IconBtn
39 alertDialog)
40 }),
43 - isWindows && h(Btn, {
44 - icon: Microsoft,
45 - variant: 'outlined',
46 - doneMessage: true,
47 - ...(!integrated?.is ? {
48 - children: "System integration",
49 - async onClick() {
50 - const msg = h(Box, {}, "We are going to add a command in the right-click of Windows File Manager",
51 - h('img', { src: 'win-shell.png', style: {
52 - display: 'block',
53 - width: 'min(30em, 80vw)',
54 - marginTop: '1em',
55 - } }),
56 - h(Alert, { severity: 'info' }, "It will also automatically copy the URL, ready to paste!"),
57 - )
58 - const parent = await promptDialog(msg, {
59 - field: { comp: VfsPathField, label: "Add to this folder", placeholder: "home" },
60 - form: { saveOnEnter: false }
61 - })
62 - return typeof parent === 'string' && apiCall('windows_integration', { parent }).then(reload)
63 - }
64 - } : {
65 - confirm: true,
66 - children: "Remove integration",
67 - onClick: () => apiCall('windows_remove').then(reload),
68 - })
69 - }),
41 + h(SystemIntegrationButton, statusApi.data)
42 )
43
44 function roots() {
@@ -104,3 +76,35 @@ export default function VfsMenuBar({ statusApi }: { statusApi: ApiObject }) {
76 })
77 }
78 }
79 +
80 +function SystemIntegrationButton({ platform }: { platform: string | undefined }) {
81 + const isWindows = platform === 'win32'
82 + const { data: integrated, reload } = useApi(isWindows && 'windows_integrated')
83 + return !isWindows ? null : h(Btn, {
84 + icon: Microsoft,
85 + variant: 'outlined',
86 + doneMessage: true,
87 + ...(!integrated?.is ? {
88 + children: "System integration",
89 + async onClick() {
90 + const msg = h(Box, {}, "We are going to add a command in the right-click of Windows File Manager",
91 + h('img', { src: 'win-shell.png', style: {
92 + display: 'block',
93 + width: 'min(30em, 80vw)',
94 + marginTop: '1em',
95 + } }),
96 + h(Alert, { severity: 'info' }, "It will also automatically copy the URL, ready to paste!"),
97 + )
98 + const parent = await promptDialog(msg, {
99 + field: { comp: VfsPathField, label: "Add to this folder", placeholder: "home" },
100 + form: { saveOnEnter: false }
101 + })
102 + return typeof parent === 'string' && apiCall('windows_integration', { parent }).then(reload)
103 + }
104 + } : {
105 + confirm: true,
106 + children: "Remove integration",
107 + onClick: () => apiCall('windows_remove').then(reload),
108 + })
109 + })
110 +}
\ No newline at end of file