diff options
Diffstat (limited to 'app/assets/javascripts/helpers')
-rw-r--r-- | app/assets/javascripts/helpers/avatar_helper.js | 5 | ||||
-rw-r--r-- | app/assets/javascripts/helpers/event_hub_factory.js | 20 |
2 files changed, 24 insertions, 1 deletions
diff --git a/app/assets/javascripts/helpers/avatar_helper.js b/app/assets/javascripts/helpers/avatar_helper.js index 7891b44dd27..4f04a1b8c16 100644 --- a/app/assets/javascripts/helpers/avatar_helper.js +++ b/app/assets/javascripts/helpers/avatar_helper.js @@ -1,11 +1,14 @@ import { escape } from 'lodash'; import { getFirstCharacterCapitalized } from '~/lib/utils/text_utility'; +import { getIdFromGraphQLId } from '~/graphql_shared/utils'; export const DEFAULT_SIZE_CLASS = 's40'; export const IDENTICON_BG_COUNT = 7; export function getIdenticonBackgroundClass(entityId) { - const type = (entityId % IDENTICON_BG_COUNT) + 1; + // If a GraphQL string id is passed in, convert it to the entity number + const id = typeof entityId === 'string' ? getIdFromGraphQLId(entityId) : entityId; + const type = (id % IDENTICON_BG_COUNT) + 1; return `bg${type}`; } diff --git a/app/assets/javascripts/helpers/event_hub_factory.js b/app/assets/javascripts/helpers/event_hub_factory.js new file mode 100644 index 00000000000..4d7f7550a94 --- /dev/null +++ b/app/assets/javascripts/helpers/event_hub_factory.js @@ -0,0 +1,20 @@ +import mitt from 'mitt'; + +export default () => { + const emitter = mitt(); + + emitter.once = (event, handler) => { + const wrappedHandler = evt => { + handler(evt); + emitter.off(event, wrappedHandler); + }; + emitter.on(event, wrappedHandler); + }; + + emitter.$on = emitter.on; + emitter.$once = emitter.once; + emitter.$off = emitter.off; + emitter.$emit = emitter.emit; + + return emitter; +}; |