Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #58

Merged
merged 4 commits into from
Apr 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "v-emoji-picker",
"version": "2.1.7",
"version": "2.1.8",
"author": {
"name": "João Eudes Lima",
"email": "joaoeudes7@gmail.com",
Expand Down Expand Up @@ -33,21 +33,21 @@
"vue": "^2.6.11"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^7.1.1",
"@rollup/plugin-node-resolve": "^7.1.3",
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"@typescript-eslint/eslint-plugin": "^2.26.0",
"@typescript-eslint/parser": "^2.26.0",
"@vue/cli-plugin-eslint": "^4.3.0",
"@vue/cli-plugin-typescript": "^4.3.0",
"@vue/cli-plugin-unit-mocha": "^4.3.0",
"@vue/cli-service": "^4.3.0",
"@typescript-eslint/eslint-plugin": "^2.28.0",
"@typescript-eslint/parser": "^2.28.0",
"@vue/cli-plugin-eslint": "^4.3.1",
"@vue/cli-plugin-typescript": "^4.3.1",
"@vue/cli-plugin-unit-mocha": "^4.3.1",
"@vue/cli-service": "^4.3.1",
"@vue/eslint-config-typescript": "^5.0.2",
"@vue/test-utils": "^1.0.0-beta.32",
"@vue/test-utils": "^1.0.0-beta.33",
"babel-eslint": "^10.1.0",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-vue": "^6.2.2",
"rollup": "^1.27.8",
"rollup-plugin-css-porter": "^1.0.2",
Expand All @@ -58,7 +58,7 @@
"rollup-plugin-vue": "^5.1.4",
"sass": "^1.26.3",
"sass-loader": "^8.0.2",
"terser": "^4.6.10",
"terser": "^4.6.11",
"typescript": "^3.8.3",
"vue": "^2.6.11",
"vue-template-compiler": "^2.6.11"
Expand Down
28 changes: 28 additions & 0 deletions src/AppTestUi.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<div>
<div>
<VEmojiPicker :customEmojis="emojis" />
</div>
<button @click="changeEmojis">Change</button>
</div>
</template>

<script lang='ts'>
import { Component, Prop, Vue } from "vue-property-decorator";

import { VEmojiPicker, emojisDefault } from "./index";

Vue.use(VEmojiPicker);

@Component({})
export default class AppTestUi extends Vue {
private emojis = emojisDefault;

changeEmojis() {
this.emojis = emojisDefault.slice(0, 8);
}
}
</script>

<style lang='scss' scoped>
</style>
42 changes: 25 additions & 17 deletions src/VEmojiPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export default class VEmojiPicker extends Vue {
@Prop({ default: true }) showCategories!: boolean;
@Prop({ default: "Search" }) labelSearch!: string;
@Prop({ default: "Peoples" }) initialCategory!: string;
@Prop({ default: () => [] as string[] }) exceptCategories!: string[];
@Prop({ default: () => [] as ICategory[] }) exceptCategories!: ICategory[];
@Prop({ default: () => [] as Emoji[] }) exceptEmojis!: IEmoji[];

mapEmojis: MapEmojis = {};
currentCategory = this.initialCategory;
Expand Down Expand Up @@ -90,26 +91,26 @@ export default class VEmojiPicker extends Vue {
async mapperEmojisCategory(emojis: IEmoji[]) {
this.$set(this.mapEmojis, "Frequently", []);

emojis.forEach((emoji: IEmoji) => {
const _category = emoji.category;
emojis
.filter(emoji => !this.exceptEmojis.includes(emoji))
.forEach(emoji => {
const _category = emoji.category;

if (!this.mapEmojis[_category]) {
this.$set(this.mapEmojis, _category, []);
}

if (!this.mapEmojis[_category]) {
this.$set(this.mapEmojis, _category, [emoji]);
} else {
this.mapEmojis[_category].push(emoji);
}
});
});
}

async restoreFrequentlyEmojis() {
const jsonMapIndexEmojis = localStorage.getItem("frequentlyEmojis");

if (jsonMapIndexEmojis) {
const mapIndexEmojis = JSON.parse(jsonMapIndexEmojis) as [];
const emojis = mapIndexEmojis.map(index => this.customEmojis[index]);
const mapIndexEmojis = JSON.parse(jsonMapIndexEmojis!!) || [];
const emojis = mapIndexEmojis.map(index => this.customEmojis[index]);

this.mapEmojis["Frequently"] = emojis;
}
this.mapEmojis["Frequently"] = emojis;
}

async saveFrequentlyEmojis(emojis: IEmoji[]) {
Expand All @@ -125,7 +126,9 @@ export default class VEmojiPicker extends Vue {
get categoriesFiltered() {
const { exceptCategories, customCategories } = this;

return customCategories.filter(c => !exceptCategories.includes(c.name));
return customCategories.filter(
category => !exceptCategories.includes(category)
);
}

@Emit("select")
Expand All @@ -140,9 +143,14 @@ export default class VEmojiPicker extends Vue {
return category;
}

@Watch("category")
watchCategory(newValue: string, old: string) {
this.currentCategory = newValue;
@Watch("customEmojis")
onChangeCustomEmojis(newEmojis: IEmoji[]) {
console.log(newEmojis == null);

if (newEmojis && newEmojis.length) {
this.mapEmojis = {};
this.mapperEmojisCategory(newEmojis);
}
}
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Vue from "vue";
import VEmojiPicker from "./index";
import AppTest from "./AppTestUi.vue";

Vue.config.productionTip = false;

new Vue({
render: h => h(VEmojiPicker)
render: h => h(AppTest)
}).$mount("#app");
Loading