From d665134d6664f4ad812ce0c167391de5b7283179 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Mon, 18 Feb 2019 16:27:59 -0800 Subject: [PATCH] refactor: refactor dialogs (#1015) --- .../showAccountProfileOptionsDialog.js | 20 +++++++------------ .../dialog/creators/showComposeDialog.js | 12 ++--------- .../dialog/creators/showCopyDialog.js | 16 +++++---------- .../_components/dialog/creators/showDialog.js | 13 ++++++++++++ .../dialog/creators/showEmojiDialog.js | 16 +++++---------- .../dialog/creators/showMediaDialog.js | 16 +++++---------- .../dialog/creators/showMuteDialog.js | 15 ++++---------- .../dialog/creators/showPostPrivacyDialog.js | 16 +++++---------- .../dialog/creators/showShortcutHelpDialog.js | 14 ++++--------- .../creators/showStatusOptionsDialog.js | 16 +++++---------- .../creators/showTextConfirmationDialog.js | 15 ++++---------- 11 files changed, 59 insertions(+), 110 deletions(-) create mode 100644 src/routes/_components/dialog/creators/showDialog.js diff --git a/src/routes/_components/dialog/creators/showAccountProfileOptionsDialog.js b/src/routes/_components/dialog/creators/showAccountProfileOptionsDialog.js index 30958916..35f632cd 100644 --- a/src/routes/_components/dialog/creators/showAccountProfileOptionsDialog.js +++ b/src/routes/_components/dialog/creators/showAccountProfileOptionsDialog.js @@ -1,18 +1,12 @@ import AccountProfileOptionsDialog from '../components/AccountProfileOptionsDialog.html' -import { createDialogElement } from '../helpers/createDialogElement' -import { createDialogId } from '../helpers/createDialogId' +import { showDialog } from './showDialog' export default function showAccountProfileOptionsDialog (account, relationship, verifyCredentials) { - let dialog = new AccountProfileOptionsDialog({ - target: createDialogElement(), - data: { - id: createDialogId(), - label: 'Profile options dialog', - title: '', - account: account, - relationship: relationship, - verifyCredentials: verifyCredentials - } + return showDialog(AccountProfileOptionsDialog, { + label: 'Profile options dialog', + title: '', + account: account, + relationship: relationship, + verifyCredentials: verifyCredentials }) - dialog.show() } diff --git a/src/routes/_components/dialog/creators/showComposeDialog.js b/src/routes/_components/dialog/creators/showComposeDialog.js index da72e295..f775af2b 100644 --- a/src/routes/_components/dialog/creators/showComposeDialog.js +++ b/src/routes/_components/dialog/creators/showComposeDialog.js @@ -1,14 +1,6 @@ import ComposeDialog from '../components/ComposeDialog.html' -import { createDialogElement } from '../helpers/createDialogElement' -import { createDialogId } from '../helpers/createDialogId' +import { showDialog } from './showDialog' export default function showComposeDialog () { - let dialog = new ComposeDialog({ - target: createDialogElement(), - data: { - id: createDialogId(), - label: 'Compose dialog' - } - }) - dialog.show() + return showDialog(ComposeDialog, { label: 'Compose dialog' }) } diff --git a/src/routes/_components/dialog/creators/showCopyDialog.js b/src/routes/_components/dialog/creators/showCopyDialog.js index 9fcc81d5..0c2e8ea6 100644 --- a/src/routes/_components/dialog/creators/showCopyDialog.js +++ b/src/routes/_components/dialog/creators/showCopyDialog.js @@ -1,16 +1,10 @@ import CopyDialog from '../components/CopyDialog.html' -import { createDialogElement } from '../helpers/createDialogElement' -import { createDialogId } from '../helpers/createDialogId' +import { showDialog } from './showDialog' export default function showCopyDialog (text) { - let dialog = new CopyDialog({ - target: createDialogElement(), - data: { - id: createDialogId(), - label: 'Copy dialog', - title: 'Copy link', - text - } + return showDialog(CopyDialog, { + label: 'Copy dialog', + title: 'Copy link', + text }) - dialog.show() } diff --git a/src/routes/_components/dialog/creators/showDialog.js b/src/routes/_components/dialog/creators/showDialog.js new file mode 100644 index 00000000..9f31df6c --- /dev/null +++ b/src/routes/_components/dialog/creators/showDialog.js @@ -0,0 +1,13 @@ +import { createDialogElement } from '../helpers/createDialogElement' +import { createDialogId } from '../helpers/createDialogId' + +export function showDialog (Dialog, data) { + let dialog = new Dialog({ + target: createDialogElement(), + data: Object.assign({ + id: createDialogId() + }, data) + }) + dialog.show() + return dialog +} diff --git a/src/routes/_components/dialog/creators/showEmojiDialog.js b/src/routes/_components/dialog/creators/showEmojiDialog.js index 36520d2e..c88fb621 100644 --- a/src/routes/_components/dialog/creators/showEmojiDialog.js +++ b/src/routes/_components/dialog/creators/showEmojiDialog.js @@ -1,16 +1,10 @@ import EmojiDialog from '../components/EmojiDialog.html' -import { createDialogElement } from '../helpers/createDialogElement' -import { createDialogId } from '../helpers/createDialogId' +import { showDialog } from './showDialog' export default function showEmojiDialog (realm) { - let emojiDialog = new EmojiDialog({ - target: createDialogElement(), - data: { - id: createDialogId(), - label: 'Emoji dialog', - title: 'Emoji', - realm - } + return showDialog(EmojiDialog, { + label: 'Emoji dialog', + title: 'Emoji', + realm }) - emojiDialog.show() } diff --git a/src/routes/_components/dialog/creators/showMediaDialog.js b/src/routes/_components/dialog/creators/showMediaDialog.js index 146fbc6f..5b32d85b 100644 --- a/src/routes/_components/dialog/creators/showMediaDialog.js +++ b/src/routes/_components/dialog/creators/showMediaDialog.js @@ -1,16 +1,10 @@ import MediaDialog from '../components/MediaDialog.html' -import { createDialogElement } from '../helpers/createDialogElement' -import { createDialogId } from '../helpers/createDialogId' +import { showDialog } from './showDialog' export default function showMediaDialog (mediaItems, scrolledItem) { - let dialog = new MediaDialog({ - target: createDialogElement(), - data: { - id: createDialogId(), - label: 'Media dialog', - mediaItems, - scrolledItem - } + return showDialog(MediaDialog, { + label: 'Media dialog', + mediaItems, + scrolledItem }) - dialog.show() } diff --git a/src/routes/_components/dialog/creators/showMuteDialog.js b/src/routes/_components/dialog/creators/showMuteDialog.js index 6911a9fd..69e91772 100644 --- a/src/routes/_components/dialog/creators/showMuteDialog.js +++ b/src/routes/_components/dialog/creators/showMuteDialog.js @@ -1,16 +1,9 @@ import MuteDialog from '../components/MuteDialog.html' -import { createDialogElement } from '../helpers/createDialogElement' -import { createDialogId } from '../helpers/createDialogId' +import { showDialog } from './showDialog' export default function showMuteDialog (account) { - let dialog = new MuteDialog({ - target: createDialogElement(), - data: { - id: createDialogId(), - label: 'Mute dialog', - account - } + return showDialog(MuteDialog, { + label: 'Mute dialog', + account }) - dialog.show() - return dialog } diff --git a/src/routes/_components/dialog/creators/showPostPrivacyDialog.js b/src/routes/_components/dialog/creators/showPostPrivacyDialog.js index 7e7cf580..f5d0fd21 100644 --- a/src/routes/_components/dialog/creators/showPostPrivacyDialog.js +++ b/src/routes/_components/dialog/creators/showPostPrivacyDialog.js @@ -1,16 +1,10 @@ import PostPrivacyDialog from '../components/PostPrivacyDialog.html' -import { createDialogElement } from '../helpers/createDialogElement' -import { createDialogId } from '../helpers/createDialogId' +import { showDialog } from './showDialog' export default function showPostPrivacyDialog (realm) { - let dialog = new PostPrivacyDialog({ - target: createDialogElement(), - data: { - id: createDialogId(), - label: 'Post privacy dialog', - title: 'Post privacy', - realm: realm - } + return showDialog(PostPrivacyDialog, { + label: 'Post privacy dialog', + title: 'Post privacy', + realm: realm }) - dialog.show() } diff --git a/src/routes/_components/dialog/creators/showShortcutHelpDialog.js b/src/routes/_components/dialog/creators/showShortcutHelpDialog.js index 1b7effef..b87fb61f 100644 --- a/src/routes/_components/dialog/creators/showShortcutHelpDialog.js +++ b/src/routes/_components/dialog/creators/showShortcutHelpDialog.js @@ -1,14 +1,8 @@ import ShortcutHelpDialog from '../components/ShortcutHelpDialog.html' -import { createDialogElement } from '../helpers/createDialogElement' -import { createDialogId } from '../helpers/createDialogId' +import { showDialog } from './showDialog' export default function showShortcutHelpDialog (options) { - let dialog = new ShortcutHelpDialog({ - target: createDialogElement(), - data: Object.assign({ - id: createDialogId(), - label: 'shortcut help dialog' - }, options) - }) - dialog.show() + return showDialog(ShortcutHelpDialog, Object.assign({ + label: 'shortcut help dialog' + }, options)) } diff --git a/src/routes/_components/dialog/creators/showStatusOptionsDialog.js b/src/routes/_components/dialog/creators/showStatusOptionsDialog.js index f3c3eac7..ddd7c28a 100644 --- a/src/routes/_components/dialog/creators/showStatusOptionsDialog.js +++ b/src/routes/_components/dialog/creators/showStatusOptionsDialog.js @@ -1,16 +1,10 @@ import StatusOptionsDialog from '../components/StatusOptionsDialog.html' -import { createDialogElement } from '../helpers/createDialogElement' -import { createDialogId } from '../helpers/createDialogId' +import { showDialog } from './showDialog' export default function showStatusOptionsDialog (status) { - let dialog = new StatusOptionsDialog({ - target: createDialogElement(), - data: { - id: createDialogId(), - label: 'Status options dialog', - title: '', - status: status - } + return showDialog(StatusOptionsDialog, { + label: 'Status options dialog', + title: '', + status: status }) - dialog.show() } diff --git a/src/routes/_components/dialog/creators/showTextConfirmationDialog.js b/src/routes/_components/dialog/creators/showTextConfirmationDialog.js index 7c0d6d20..2cc51555 100644 --- a/src/routes/_components/dialog/creators/showTextConfirmationDialog.js +++ b/src/routes/_components/dialog/creators/showTextConfirmationDialog.js @@ -1,15 +1,8 @@ import TextConfirmationDialog from '../components/TextConfirmationDialog.html' -import { createDialogElement } from '../helpers/createDialogElement' -import { createDialogId } from '../helpers/createDialogId' +import { showDialog } from './showDialog' export default function showTextConfirmationDialog (options) { - let dialog = new TextConfirmationDialog({ - target: createDialogElement(), - data: Object.assign({ - id: createDialogId(), - label: 'Confirmation dialog' - }, options) - }) - dialog.show() - return dialog + return showDialog(TextConfirmationDialog, Object.assign({ + label: 'Confirmation dialog' + }, options)) }