Commit d16914b7 authored by Phil Hughes's avatar Phil Hughes

Moved some re-used values into constants file

parent 1b94ec93
...@@ -3,7 +3,7 @@ import { GlIcon, GlDropdown, GlSearchBoxByType } from '@gitlab/ui'; ...@@ -3,7 +3,7 @@ import { GlIcon, GlDropdown, GlSearchBoxByType } from '@gitlab/ui';
import { findLastIndex } from 'lodash'; import { findLastIndex } from 'lodash';
import VirtualList from 'vue-virtual-scroll-list'; import VirtualList from 'vue-virtual-scroll-list';
import { CATEGORY_NAMES } from '~/emoji'; import { CATEGORY_NAMES } from '~/emoji';
import { CATEGORY_ICON_MAP } from '../constants'; import { CATEGORY_ICON_MAP, FREQUENTLY_USED_KEY } from '../constants';
import Category from './category.vue'; import Category from './category.vue';
import EmojiList from './emoji_list.vue'; import EmojiList from './emoji_list.vue';
import { addToFrequentlyUsed, getEmojiCategories, hasFrequentlyUsedEmojis } from './utils'; import { addToFrequentlyUsed, getEmojiCategories, hasFrequentlyUsedEmojis } from './utils';
...@@ -33,7 +33,7 @@ export default { ...@@ -33,7 +33,7 @@ export default {
computed: { computed: {
categoryNames() { categoryNames() {
return CATEGORY_NAMES.filter((c) => { return CATEGORY_NAMES.filter((c) => {
if (c === 'frequently_used') return hasFrequentlyUsedEmojis(); if (c === FREQUENTLY_USED_KEY) return hasFrequentlyUsedEmojis();
return true; return true;
}).map((category) => ({ }).map((category) => ({
name: category, name: category,
......
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import { chunk, memoize, uniq } from 'lodash'; import { chunk, memoize, uniq } from 'lodash';
import { initEmojiMap, getEmojiCategoryMap } from '~/emoji'; import { initEmojiMap, getEmojiCategoryMap } from '~/emoji';
import { EMOJIS_PER_ROW, EMOJI_ROW_HEIGHT, CATEGORY_ROW_HEIGHT } from '../constants'; import {
EMOJIS_PER_ROW,
EMOJI_ROW_HEIGHT,
CATEGORY_ROW_HEIGHT,
FREQUENTLY_USED_KEY,
FREQUENTLY_USED_COOKIE_KEY,
} from '../constants';
export const generateCategoryHeight = (emojisLength) => export const generateCategoryHeight = (emojisLength) =>
emojisLength * EMOJI_ROW_HEIGHT + CATEGORY_ROW_HEIGHT; emojisLength * EMOJI_ROW_HEIGHT + CATEGORY_ROW_HEIGHT;
export const getFrequentlyUsedEmojis = () => { export const getFrequentlyUsedEmojis = () => {
const savedEmojis = Cookies.get('frequently_used_emojis'); const savedEmojis = Cookies.get(FREQUENTLY_USED_COOKIE_KEY);
if (!savedEmojis) return null; if (!savedEmojis) return null;
...@@ -24,13 +30,13 @@ export const getFrequentlyUsedEmojis = () => { ...@@ -24,13 +30,13 @@ export const getFrequentlyUsedEmojis = () => {
export const addToFrequentlyUsed = (emoji) => { export const addToFrequentlyUsed = (emoji) => {
const frequentlyUsedEmojis = uniq( const frequentlyUsedEmojis = uniq(
(Cookies.get('frequently_used_emojis') || '') (Cookies.get(FREQUENTLY_USED_COOKIE_KEY) || '')
.split(',') .split(',')
.filter((e) => e) .filter((e) => e)
.concat(emoji), .concat(emoji),
); );
Cookies.set('frequently_used_emojis', frequentlyUsedEmojis.join(','), { expires: 365 }); Cookies.set(FREQUENTLY_USED_COOKIE_KEY, frequentlyUsedEmojis.join(','), { expires: 365 });
}; };
export const hasFrequentlyUsedEmojis = () => getFrequentlyUsedEmojis() !== null; export const hasFrequentlyUsedEmojis = () => getFrequentlyUsedEmojis() !== null;
...@@ -46,7 +52,7 @@ export const getEmojiCategories = memoize(async () => { ...@@ -46,7 +52,7 @@ export const getEmojiCategories = memoize(async () => {
return Object.freeze( return Object.freeze(
Object.keys(categories) Object.keys(categories)
.filter((c) => c !== 'frequently_used') .filter((c) => c !== FREQUENTLY_USED_KEY)
.reduce((acc, category) => { .reduce((acc, category) => {
const emojis = chunk(categories[category], EMOJIS_PER_ROW); const emojis = chunk(categories[category], EMOJIS_PER_ROW);
const height = generateCategoryHeight(emojis.length); const height = generateCategoryHeight(emojis.length);
......
export const FREQUENTLY_USED_KEY = 'frequently_used';
export const FREQUENTLY_USED_COOKIE_KEY = 'frequently_used_emojis';
export const CATEGORY_ICON_MAP = { export const CATEGORY_ICON_MAP = {
frequently_used: 'history', [FREQUENTLY_USED_KEY]: 'history',
activity: 'dumbbell', activity: 'dumbbell',
people: 'smiley', people: 'smiley',
nature: 'nature', nature: 'nature',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment