mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
Save the latest callout card emoji
refs https://github.com/TryGhost/Team/issues/1206 - Re-use the saved emoji as the default for future callout cards - Introduced a localstorage util that ignores errors. Ignoring errors avoids issues with browsers that don't support localstorage
This commit is contained in:
parent
96a810e6c7
commit
78540cabfd
27
ghost/admin/app/utils/localstorage.js
Normal file
27
ghost/admin/app/utils/localstorage.js
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Returns the value for a localstorage key.
|
||||
* Silently ignores errors.
|
||||
* @param {string} key
|
||||
* @returns {string?} The value
|
||||
*/
|
||||
export function get(key) {
|
||||
try {
|
||||
return localStorage.getItem(key);
|
||||
} catch (e) {
|
||||
// do nothing here
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a localstorage value at the key `key`.
|
||||
* Silently ignores errors.
|
||||
* @param {string} key The key where to store the value
|
||||
* @param {string} value The value to store
|
||||
*/
|
||||
export function set(key, value) {
|
||||
try {
|
||||
localStorage.setItem(key, value);
|
||||
} catch (e) {
|
||||
// do nothing here
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
import * as storage from '../../../../app/utils/localstorage';
|
||||
import Browser from 'mobiledoc-kit/utils/browser';
|
||||
import Component from '@glimmer/component';
|
||||
import {EmojiButton} from '@joeattardi/emoji-button';
|
||||
@ -7,6 +8,8 @@ import {run} from '@ember/runloop';
|
||||
import {inject as service} from '@ember/service';
|
||||
import {set} from '@ember/object';
|
||||
|
||||
const storageKey = 'gh-kg-callout-emoji';
|
||||
|
||||
export default class KoenigCardCalloutComponent extends Component {
|
||||
@service config;
|
||||
@service feature;
|
||||
@ -56,7 +59,7 @@ export default class KoenigCardCalloutComponent extends Component {
|
||||
this.args.registerComponent(this);
|
||||
|
||||
const payloadDefaults = {
|
||||
calloutEmoji: '💡',
|
||||
calloutEmoji: storage.get(storageKey) || '💡',
|
||||
calloutText: '',
|
||||
backgroundColor: 'grey'
|
||||
};
|
||||
@ -94,6 +97,7 @@ export default class KoenigCardCalloutComponent extends Component {
|
||||
@action
|
||||
setCalloutEmoji(emoji) {
|
||||
this._updatePayloadAttr('calloutEmoji', emoji);
|
||||
storage.set(storageKey, emoji);
|
||||
}
|
||||
|
||||
@action
|
||||
|
Loading…
Reference in New Issue
Block a user