Commit 77292861 authored by Phil Hughes's avatar Phil Hughes

Added constants file to re-use variables

Added comment to SCSS file
Updated category spec
parent 33ded12d
<script> <script>
import { chunk } from 'lodash'; import { chunk } from 'lodash';
import { searchEmoji } from '~/emoji'; import { searchEmoji } from '~/emoji';
import { EMOJIS_PER_ROW } from '../constants';
import { getEmojiCategories, generateCategoryHeight } from './utils'; import { getEmojiCategories, generateCategoryHeight } from './utils';
export default { export default {
...@@ -18,7 +19,7 @@ export default { ...@@ -18,7 +19,7 @@ export default {
if (this.searchValue !== '') { if (this.searchValue !== '') {
const emojis = chunk( const emojis = chunk(
searchEmoji(this.searchValue).map(({ emoji }) => emoji.name), searchEmoji(this.searchValue).map(({ emoji }) => emoji.name),
9, EMOJIS_PER_ROW,
); );
return { return {
......
...@@ -2,21 +2,11 @@ ...@@ -2,21 +2,11 @@
import { GlIcon, GlDropdown, GlSearchBoxByType } from '@gitlab/ui'; import { GlIcon, GlDropdown, GlSearchBoxByType } from '@gitlab/ui';
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 from './category.vue'; import Category from './category.vue';
import EmojiList from './emoji_list.vue'; import EmojiList from './emoji_list.vue';
import { getEmojiCategories } from './utils'; import { getEmojiCategories } from './utils';
const CATEGORY_ICON_MAP = {
activity: 'dumbbell',
people: 'smiley',
nature: 'nature',
food: 'food',
travel: 'car',
objects: 'object',
symbols: 'heart',
flags: 'flag',
};
export default { export default {
components: { components: {
GlIcon, GlIcon,
......
import { chunk, memoize } from 'lodash'; import { chunk, memoize } from 'lodash';
import { initEmojiMap, getEmojiCategoryMap } from '~/emoji'; import { initEmojiMap, getEmojiCategoryMap } from '~/emoji';
import { EMOJIS_PER_ROW, EMOJI_ROW_HEIGHT, CATEGORY_ROW_HEIGHT } from '../constants';
export const generateCategoryHeight = (emojisLength) => emojisLength * 34 + 29; export const generateCategoryHeight = (emojisLength) =>
emojisLength * EMOJI_ROW_HEIGHT + CATEGORY_ROW_HEIGHT;
export const getEmojiCategories = memoize(async () => { export const getEmojiCategories = memoize(async () => {
await initEmojiMap(); await initEmojiMap();
...@@ -11,7 +13,7 @@ export const getEmojiCategories = memoize(async () => { ...@@ -11,7 +13,7 @@ export const getEmojiCategories = memoize(async () => {
return Object.freeze( return Object.freeze(
Object.keys(categories).reduce((acc, category) => { Object.keys(categories).reduce((acc, category) => {
const emojis = chunk(categories[category], 9); const emojis = chunk(categories[category], EMOJIS_PER_ROW);
const height = generateCategoryHeight(emojis.length); const height = generateCategoryHeight(emojis.length);
const newAcc = { const newAcc = {
...acc, ...acc,
......
export const CATEGORY_ICON_MAP = {
activity: 'dumbbell',
people: 'smiley',
nature: 'nature',
food: 'food',
travel: 'car',
objects: 'object',
symbols: 'heart',
flags: 'flag',
};
export const EMOJIS_PER_ROW = 9;
export const EMOJI_ROW_HEIGHT = 34;
export const CATEGORY_ROW_HEIGHT = 37;
...@@ -2,6 +2,7 @@ import { escape, minBy } from 'lodash'; ...@@ -2,6 +2,7 @@ import { escape, minBy } from 'lodash';
import emojiAliases from 'emojis/aliases.json'; import emojiAliases from 'emojis/aliases.json';
import AccessorUtilities from '../lib/utils/accessor'; import AccessorUtilities from '../lib/utils/accessor';
import axios from '../lib/utils/axios_utils'; import axios from '../lib/utils/axios_utils';
import { CATEGORY_ICON_MAP } from './constants';
let emojiMap = null; let emojiMap = null;
let validEmojiNames = null; let validEmojiNames = null;
...@@ -155,16 +156,7 @@ export function sortEmoji(items) { ...@@ -155,16 +156,7 @@ export function sortEmoji(items) {
return [...items].sort((a, b) => a.score - b.score || a.fieldValue.localeCompare(b.fieldValue)); return [...items].sort((a, b) => a.score - b.score || a.fieldValue.localeCompare(b.fieldValue));
} }
export const CATEGORY_NAMES = [ export const CATEGORY_NAMES = Object.keys(CATEGORY_ICON_MAP);
'activity',
'people',
'nature',
'food',
'travel',
'objects',
'symbols',
'flags',
];
let emojiCategoryMap; let emojiCategoryMap;
export function getEmojiCategoryMap() { export function getEmojiCategoryMap() {
......
...@@ -24,6 +24,7 @@ gl-emoji { ...@@ -24,6 +24,7 @@ gl-emoji {
.emoji-picker-emoji { .emoji-picker-emoji {
height: 30px; height: 30px;
// Create a width that fits 9 emojis per row
width: 100 / 9 * 1%; width: 100 / 9 * 1%;
} }
......
...@@ -14,32 +14,24 @@ describe('Emoji category component', () => { ...@@ -14,32 +14,24 @@ describe('Emoji category component', () => {
wrapper.destroy(); wrapper.destroy();
}); });
it('renders emoji groups', () => { beforeEach(() => {
factory({ factory({
category: 'Activity', category: 'Activity',
emojis: [['thumbsup'], ['thumbsdown']], emojis: [['thumbsup'], ['thumbsdown']],
}); });
});
it('renders emoji groups', () => {
expect(wrapper.findAll(EmojiGroup).length).toBe(2); expect(wrapper.findAll(EmojiGroup).length).toBe(2);
}); });
it('renders group', async () => { it('renders group', async () => {
factory({
category: 'Activity',
emojis: [['thumbsup'], ['thumbsdown']],
});
await wrapper.setData({ renderGroup: true }); await wrapper.setData({ renderGroup: true });
expect(wrapper.find(EmojiGroup).attributes('rendergroup')).toBe('true'); expect(wrapper.find(EmojiGroup).attributes('rendergroup')).toBe('true');
}); });
it('renders group on appear', async () => { it('renders group on appear', async () => {
factory({
category: 'Activity',
emojis: [['thumbsup'], ['thumbsdown']],
});
wrapper.find(GlIntersectionObserver).vm.$emit('appear'); wrapper.find(GlIntersectionObserver).vm.$emit('appear');
await nextTick(); await nextTick();
...@@ -48,11 +40,6 @@ describe('Emoji category component', () => { ...@@ -48,11 +40,6 @@ describe('Emoji category component', () => {
}); });
it('emits appear event on appear', async () => { it('emits appear event on appear', async () => {
factory({
category: 'Activity',
emojis: [['thumbsup'], ['thumbsdown']],
});
wrapper.find(GlIntersectionObserver).vm.$emit('appear'); wrapper.find(GlIntersectionObserver).vm.$emit('appear');
await nextTick(); await nextTick();
......
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