parent
e2ebff9c5d
commit
f424cf8a8d
|
@ -1,3 +1,4 @@
|
|||
import { ErrorView } from '@views/ErrorView'
|
||||
import { Notice, Plugin } from 'obsidian'
|
||||
import { MicroPluginContainerInterface, MicroPluginContainer } from '@base/MicroPluginContainer'
|
||||
import { MicroPluginSettingsView } from '@views/MicroPluginSettingsView'
|
||||
|
@ -32,12 +33,18 @@ export default class MicroPlugin extends Plugin {
|
|||
id: 'microblog-publish-command',
|
||||
name: 'Post to Micro.blog',
|
||||
editorCallback: (editor, markdownView) => {
|
||||
new PublishView(
|
||||
this.viewModelFactory.makePublishViewModel(
|
||||
markdownView.file.basename,
|
||||
editor.getValue()
|
||||
)
|
||||
).open()
|
||||
if (editor.getValue().trim().length == 0) {
|
||||
new ErrorView(
|
||||
this.viewModelFactory.makeEmptyPostErrorViewModel()
|
||||
).open()
|
||||
} else {
|
||||
new PublishView(
|
||||
this.viewModelFactory.makePublishViewModel(
|
||||
markdownView.file.basename,
|
||||
editor.getValue()
|
||||
)
|
||||
).open()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { MicroPluginSettingsViewModel } from '@views/MicroPluginSettingsViewModel'
|
||||
import { PublishViewModel } from '@views/PublishViewModel'
|
||||
import { TagSuggestionViewModel, TagSuggestionDelegate } from '@views/TagSuggestionViewModel'
|
||||
import { ErrorViewModel } from '@views/ErrorViewModel'
|
||||
import { MicroPluginContainerInterface } from '@base/MicroPluginContainer'
|
||||
|
||||
export interface ViewModelFactoryInterface {
|
||||
|
@ -21,6 +22,9 @@ export interface ViewModelFactoryInterface {
|
|||
excluding: Array<string>,
|
||||
delegate?: TagSuggestionDelegate
|
||||
): TagSuggestionViewModel
|
||||
|
||||
// Builds the Empty Post Error View Model.
|
||||
makeEmptyPostErrorViewModel(): ErrorViewModel
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -87,4 +91,11 @@ export class ViewModelFactory implements ViewModelFactoryInterface {
|
|||
|
||||
return viewModel
|
||||
}
|
||||
}
|
||||
|
||||
public makeEmptyPostErrorViewModel(): ErrorViewModel {
|
||||
return new ErrorViewModel(
|
||||
"Oops",
|
||||
"Micro.blog doesn't support blank posts. Write something first and try again."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
import { Modal } from 'obsidian'
|
||||
import { ErrorViewModel } from '@views/ErrorViewModel'
|
||||
|
||||
/*
|
||||
* Error View subclasses Modal.
|
||||
*/
|
||||
export class ErrorView extends Modal {
|
||||
|
||||
// Properties
|
||||
|
||||
private viewModel: ErrorViewModel
|
||||
|
||||
// Life cycle
|
||||
|
||||
constructor(
|
||||
viewModel: ErrorViewModel
|
||||
) {
|
||||
super(app)
|
||||
|
||||
this.viewModel = viewModel
|
||||
}
|
||||
|
||||
// Public
|
||||
|
||||
public onOpen() {
|
||||
super.onOpen()
|
||||
|
||||
const { contentEl } = this
|
||||
|
||||
contentEl.empty()
|
||||
contentEl.createEl('h2', { text: this.viewModel.title })
|
||||
contentEl.createEl('p', { text: this.viewModel.message })
|
||||
}
|
||||
|
||||
public onClose() {
|
||||
super.onClose()
|
||||
|
||||
const { contentEl } = this
|
||||
|
||||
contentEl.empty()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* This view model drives the content and interactions with the
|
||||
* error view.
|
||||
*/
|
||||
export class ErrorViewModel {
|
||||
|
||||
// Properties
|
||||
|
||||
readonly title: string
|
||||
readonly message: string
|
||||
|
||||
// Life cycle
|
||||
|
||||
constructor(
|
||||
title: string,
|
||||
message: string
|
||||
) {
|
||||
this.title = title
|
||||
this.message = message
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue