Skip to content

Commit

Permalink
reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-hub committed Oct 2, 2023
1 parent 5f5cdcf commit b6218a7
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions src/ui/BibleReferenceSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,25 @@ export class BibleReferenceSettingTab extends PluginSettingTab {
})
)

const getOutgoingLinkPosition = (linkingPostion: string | OutgoingLinkPositionEnum | undefined) => {
let value = linkingPostion
if (!value) {
value = OutgoingLinkPositionEnum.None
} else if (value as any === true) {
value = OutgoingLinkPositionEnum.Header
}
// otherwise no change
return value as string;
}

new Setting(this.expertSettingContainer)
.setName('Add a Book Outgoing Link')
.setDesc('Makes an outgoing link for the book, for example [[John]]')
.addDropdown((dropdown) => {
Object.keys(OutgoingLinkPositionEnum).forEach((name) => {
dropdown.addOption(name, name)
})
const defaultPosition =
(this.plugin.settings?.bookBacklinking as any) === true
? OutgoingLinkPositionEnum.Header
: OutgoingLinkPositionEnum.None
const value: string = (
this.plugin.settings?.bookBacklinking &&
(this.plugin.settings?.bookBacklinking as any) !== true
? this.plugin.settings.bookBacklinking
: defaultPosition
) as string
const value = getOutgoingLinkPosition(this.plugin.settings?.bookBacklinking)
dropdown.setValue(value)
dropdown.onChange(async (value) => {
this.plugin.settings.bookBacklinking =
Expand All @@ -171,16 +173,7 @@ export class BibleReferenceSettingTab extends PluginSettingTab {
Object.keys(OutgoingLinkPositionEnum).forEach((name) => {
dropdown.addOption(name, name)
})
const defaultPosition =
(this.plugin.settings?.chapterBacklinking as any) === true
? OutgoingLinkPositionEnum.Header
: OutgoingLinkPositionEnum.None
const value: string = (
this.plugin.settings?.chapterBacklinking &&
(this.plugin.settings?.chapterBacklinking as any) !== true
? this.plugin.settings.chapterBacklinking
: defaultPosition
) as string
const value = getOutgoingLinkPosition(this.plugin.settings?.chapterBacklinking)
dropdown.setValue(value)
dropdown.onChange(async (value) => {
this.plugin.settings.chapterBacklinking =
Expand Down

0 comments on commit b6218a7

Please sign in to comment.