-
-
Notifications
You must be signed in to change notification settings - Fork 541
Expand file tree
/
Copy pathInstallCustomPlugin.tsx
More file actions
81 lines (71 loc) · 2.6 KB
/
Copy pathInstallCustomPlugin.tsx
File metadata and controls
81 lines (71 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import Button from '@/Components/Button/Button'
import DecoratedInput from '@/Components/Input/DecoratedInput'
import { FunctionComponent, useEffect, useRef, useState } from 'react'
import { observer } from 'mobx-react-lite'
import ConfirmCustomPlugin from './ConfirmCustomPlugin'
import PreferencesSegment from '../../../PreferencesComponents/PreferencesSegment'
import { useApplication } from '@/Components/ApplicationProvider'
import { ThirdPartyFeatureDescription } from '@standardnotes/snjs'
type Props = {
className?: string
}
const InstallCustomPlugin: FunctionComponent<Props> = ({ className = '' }) => {
const application = useApplication()
const [customUrl, setCustomUrl] = useState('')
const [confirmablePlugin, setConfirmablePlugin] = useState<ThirdPartyFeatureDescription | undefined>(undefined)
const confirmableEnd = useRef<HTMLDivElement>(null)
const isWebApp = useState(application.isWebApp());
useEffect(() => {
if (confirmablePlugin) {
confirmableEnd.current?.scrollIntoView({ behavior: 'smooth' })
}
}, [confirmablePlugin, confirmableEnd])
const submitPluginUrl = async (url: string) => {
const plugin = await application.pluginsService.getPluginDetailsFromUrl(url)
if (plugin) {
setConfirmablePlugin(plugin)
}
}
const confirmPlugin = async (confirm: boolean) => {
if (confirm && confirmablePlugin) {
await application.pluginsService.installExternalPlugin(confirmablePlugin)
}
setConfirmablePlugin(undefined)
setCustomUrl('')
}
return (
<div className={className}>
<div>
{!confirmablePlugin && (
<PreferencesSegment>
<div>
<DecoratedInput
disabled = {isWebApp}
placeholder={(isWebApp) ? 'Web App External Plugin Downloads Not Supported' : 'Enter Plugin URL'}
value={customUrl}
onChange={(value) => {
setCustomUrl(value)
}}
/>
</div>
<Button
hidden={customUrl.length === 0}
disabled={customUrl.length === 0 || isWebApp}
className="mt-4 min-w-20"
primary
label="Install"
onClick={() => submitPluginUrl(customUrl)}
/>
</PreferencesSegment>
)}
{confirmablePlugin && (
<PreferencesSegment>
<ConfirmCustomPlugin plugin={confirmablePlugin} callback={confirmPlugin} />
<div ref={confirmableEnd} />
</PreferencesSegment>
)}
</div>
</div>
)
}
export default observer(InstallCustomPlugin)