From 18dab36e52dd9493ca105534613924c5fc932676 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Tue, 27 Feb 2018 23:18:07 -0800 Subject: [PATCH] add custom emoji modal --- routes/_actions/addInstance.js | 6 +- routes/_actions/emoji.js | 21 +++++ routes/_api/emoji.js | 7 ++ routes/_components/IconButton.html | 17 ++-- routes/_components/compose/ComposeInput.html | 19 +++++ .../_components/compose/ComposeToolbar.html | 18 +++- routes/_components/dialog/EmojiDialog.html | 82 +++++++++++++++++++ routes/_components/dialog/ModalDialog.html | 33 ++++++-- routes/_components/dialog/dialogs.js | 1 + routes/_components/dialog/showEmojiDialog.js | 12 +++ routes/_database/meta.js | 8 ++ routes/_store/instanceComputations.js | 5 ++ routes/_store/store.js | 3 +- 13 files changed, 211 insertions(+), 21 deletions(-) create mode 100644 routes/_actions/emoji.js create mode 100644 routes/_api/emoji.js create mode 100644 routes/_components/dialog/EmojiDialog.html create mode 100644 routes/_components/dialog/showEmojiDialog.js diff --git a/routes/_actions/addInstance.js b/routes/_actions/addInstance.js index 1802dfd..fd5a1ee 100644 --- a/routes/_actions/addInstance.js +++ b/routes/_actions/addInstance.js @@ -5,6 +5,7 @@ import { switchToTheme } from '../_utils/themeEngine' import { database } from '../_database/database' import { store } from '../_store/store' import { updateVerifyCredentialsForInstance } from './instances' +import { updateCustomEmojiForInstance } from './emoji' const REDIRECT_URI = (typeof location !== 'undefined' ? location.origin : 'https://pinafore.social') + '/settings/instances/add' @@ -85,8 +86,9 @@ async function registerNewInstance (code) { }) store.save() switchToTheme('default') - // fire off request for account so it's cached - updateVerifyCredentialsForInstance(currentRegisteredInstanceName) + // fire off these requests so they're cached + /* no await */ updateVerifyCredentialsForInstance(currentRegisteredInstanceName) + /* no await */ updateCustomEmojiForInstance(currentRegisteredInstanceName) goto('/') } diff --git a/routes/_actions/emoji.js b/routes/_actions/emoji.js new file mode 100644 index 0000000..becd51a --- /dev/null +++ b/routes/_actions/emoji.js @@ -0,0 +1,21 @@ +import { cacheFirstUpdateAfter } from '../_utils/sync' +import { database } from '../_database/database' +import { getCustomEmoji } from '../_api/emoji' +import { store } from '../_store/store' + +export async function updateCustomEmojiForInstance (instanceName) { + await cacheFirstUpdateAfter( + () => getCustomEmoji(instanceName), + () => database.getCustomEmoji(instanceName), + emoji => database.setCustomEmoji(instanceName, emoji), + emoji => { + let customEmoji = store.get('customEmoji') + customEmoji[instanceName] = emoji + store.set({customEmoji: customEmoji}) + } + ) +} + +export function insertEmoji (emoji) { + store.set({emojiToInsert: emoji}) +} diff --git a/routes/_api/emoji.js b/routes/_api/emoji.js new file mode 100644 index 0000000..c848ed5 --- /dev/null +++ b/routes/_api/emoji.js @@ -0,0 +1,7 @@ +import { basename } from './utils' +import { getWithTimeout } from '../_utils/ajax' + +export async function getCustomEmoji (instanceName) { + let url = `${basename(instanceName)}/api/v1/custom_emojis` + return getWithTimeout(url) +} diff --git a/routes/_components/IconButton.html b/routes/_components/IconButton.html index c47e6ea..3d961eb 100644 --- a/routes/_components/IconButton.html +++ b/routes/_components/IconButton.html @@ -1,12 +1,10 @@ -{{#if pressable}} +{{#if delegateKey}} + + {{/each}} + + {{else}} +
No custom emoji found for this instance.
+ {{/if}} + + + + \ No newline at end of file diff --git a/routes/_components/dialog/ModalDialog.html b/routes/_components/dialog/ModalDialog.html index 30c1dbe..998b814 100644 --- a/routes/_components/dialog/ModalDialog.html +++ b/routes/_components/dialog/ModalDialog.html @@ -1,10 +1,15 @@