FluentReader/src/components/settings/service.tsx

134 lines
4.4 KiB
TypeScript
Raw Normal View History

2020-07-31 12:45:25 +02:00
import * as React from "react"
import intl from "react-intl-universal"
import { ServiceConfigs, SyncService } from "../../schema-types"
import { Stack, Icon, Link, Dropdown, IDropdownOption } from "@fluentui/react"
2020-08-02 06:59:49 +02:00
import FeverConfigsTab from "./services/fever"
2020-08-15 04:57:49 +02:00
import FeedbinConfigsTab from "./services/feedbin"
2020-12-25 13:47:21 +01:00
import GReaderConfigsTab from "./services/greader"
import InoreaderConfigsTab from "./services/inoreader"
2020-07-31 12:45:25 +02:00
2020-08-02 06:59:49 +02:00
type ServiceTabProps = {
2020-07-31 12:45:25 +02:00
configs: ServiceConfigs
2020-08-02 06:59:49 +02:00
save: (configs: ServiceConfigs) => void
sync: () => Promise<void>
remove: () => Promise<void>
blockActions: () => void
authenticate: (configs: ServiceConfigs) => Promise<boolean>
2020-12-25 13:47:21 +01:00
reauthenticate: (configs: ServiceConfigs) => Promise<ServiceConfigs>
2020-08-02 06:59:49 +02:00
}
export type ServiceConfigsTabProps = ServiceTabProps & {
exit: () => void
2020-07-31 12:45:25 +02:00
}
type ServiceTabState = {
type: SyncService
}
2021-08-21 23:49:56 +02:00
export class ServiceTab extends React.Component<
ServiceTabProps,
ServiceTabState
> {
2020-07-31 12:45:25 +02:00
constructor(props: ServiceTabProps) {
super(props)
this.state = {
2021-08-21 23:49:56 +02:00
type: props.configs.type,
2020-07-31 12:45:25 +02:00
}
}
serviceOptions = (): IDropdownOption[] => [
{ key: SyncService.Fever, text: "Fever API" },
2020-08-15 04:57:49 +02:00
{ key: SyncService.Feedbin, text: "Feedbin" },
2020-12-25 13:47:21 +01:00
{ key: SyncService.GReader, text: "Google Reader API (Beta)" },
{ key: SyncService.Inoreader, text: "Inoreader" },
2020-07-31 12:45:25 +02:00
{ key: -1, text: intl.get("service.suggest") },
]
onServiceOptionChange = (_, option: IDropdownOption) => {
if (option.key === -1) {
2021-08-21 23:49:56 +02:00
window.utils.openExternal(
"https://github.com/yang991178/fluent-reader/issues/23"
)
2020-07-31 12:45:25 +02:00
} else {
2020-08-02 06:59:49 +02:00
this.setState({ type: option.key as number })
2020-07-31 12:45:25 +02:00
}
}
2020-08-02 06:59:49 +02:00
exitConfigsTab = () => {
this.setState({ type: SyncService.None })
}
2020-08-15 04:57:49 +02:00
getConfigsTab = () => {
switch (this.state.type) {
2021-08-21 23:49:56 +02:00
case SyncService.Fever:
return (
<FeverConfigsTab
{...this.props}
exit={this.exitConfigsTab}
/>
)
case SyncService.Feedbin:
return (
<FeedbinConfigsTab
{...this.props}
exit={this.exitConfigsTab}
/>
)
case SyncService.GReader:
return (
<GReaderConfigsTab
{...this.props}
exit={this.exitConfigsTab}
/>
)
case SyncService.Inoreader:
return (
<InoreaderConfigsTab
{...this.props}
exit={this.exitConfigsTab}
/>
)
default:
return null
2020-08-15 04:57:49 +02:00
}
}
2020-07-31 12:45:25 +02:00
render = () => (
<div className="tab-body">
2021-08-21 23:49:56 +02:00
{this.state.type === SyncService.None ? (
<Stack horizontalAlign="center" style={{ marginTop: 64 }}>
<Stack
className="settings-rules-icons"
horizontal
tokens={{ childrenGap: 12 }}>
2020-07-31 12:45:25 +02:00
<Icon iconName="ThisPC" />
<Icon iconName="Sync" />
<Icon iconName="Cloud" />
</Stack>
<span className="settings-hint">
{intl.get("service.intro")}
2021-08-21 23:49:56 +02:00
<Link
onClick={() =>
window.utils.openExternal(
"https://github.com/yang991178/fluent-reader/wiki/Support#services"
)
}
style={{ marginLeft: 6 }}>
2020-07-31 12:45:25 +02:00
{intl.get("rules.help")}
</Link>
</span>
<Dropdown
placeHolder={intl.get("service.select")}
options={this.serviceOptions()}
selectedKey={null}
onChange={this.onServiceOptionChange}
2021-08-21 23:49:56 +02:00
style={{ marginTop: 32, width: 180 }}
/>
2020-07-31 12:45:25 +02:00
</Stack>
2021-08-21 23:49:56 +02:00
) : (
this.getConfigsTab()
)}
2020-07-31 12:45:25 +02:00
</div>
)
2021-08-21 23:49:56 +02:00
}