mirror of
https://github.com/danbulant/Nertivia-Client
synced 2026-06-24 17:11:43 +00:00
emoji suggestions finished
This commit is contained in:
parent
41ce5ae36a
commit
ec37b3ac92
4 changed files with 133 additions and 53 deletions
|
|
@ -31,8 +31,8 @@
|
||||||
</div>
|
</div>
|
||||||
<news v-if="!selectedChannelID "/>
|
<news v-if="!selectedChannelID "/>
|
||||||
<div class="chat-input-area" v-if="selectedChannelID">
|
<div class="chat-input-area" v-if="selectedChannelID">
|
||||||
<div class="emoji-suggestion-outer" v-if="showEmojiSuggestions">
|
<div class="emoji-suggestion-outer" v-if="emojiArray">
|
||||||
<emoji-suggestions :emojiArray="emojiSuggestionsArray"/>
|
<emoji-suggestions :emojiArray="emojiArray"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="message-area">
|
<div class="message-area">
|
||||||
|
|
@ -103,9 +103,7 @@ export default {
|
||||||
postTimerID: null,
|
postTimerID: null,
|
||||||
getTimerID: null,
|
getTimerID: null,
|
||||||
typing: false,
|
typing: false,
|
||||||
whosTyping: "",
|
whosTyping: ""
|
||||||
showEmojiSuggestions: false,
|
|
||||||
emojiSuggestionsArray: []
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -132,7 +130,7 @@ export default {
|
||||||
|
|
||||||
if (this.message == "") return;
|
if (this.message == "") return;
|
||||||
if (this.message.length > 5000) return;
|
if (this.message.length > 5000) return;
|
||||||
this.showEmojiSuggestions = false;
|
(this.$store.dispatch('setEmojiArray', null));
|
||||||
clearInterval(this.postTimerID);
|
clearInterval(this.postTimerID);
|
||||||
this.postTimerID = null;
|
this.postTimerID = null;
|
||||||
this.messageLength = 0;
|
this.messageLength = 0;
|
||||||
|
|
@ -198,48 +196,53 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emojiSwitchKey(event) {
|
emojiSwitchKey(event) {
|
||||||
if (!this.showEmojiSuggestions) return;
|
if (!this.emojiArray) return;
|
||||||
|
|
||||||
const keyCode = event.keyCode;
|
const keyCode = event.keyCode;
|
||||||
|
|
||||||
if (keyCode == 38) {
|
if (keyCode == 38) {
|
||||||
//up
|
//up
|
||||||
bus.$emit("emojiSuggestions:up");
|
bus.$emit("emojiSuggestions:key", "up");
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (keyCode == 40) {
|
if (keyCode == 40) {
|
||||||
//down
|
//down
|
||||||
bus.$emit("emojiSuggestions:down");
|
bus.$emit("emojiSuggestions:key", "down");
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GetWordByPos(str, pos) {
|
ReturnWord(text, caretPos) {
|
||||||
let left = str.substr(0, pos);
|
var index = text.indexOf(caretPos);
|
||||||
let right = str.substr(pos);
|
var preText = text.substring(0, caretPos);
|
||||||
|
if (preText.indexOf(" ") > 0) {
|
||||||
left = left.replace(/^.+ /g, "");
|
var words = preText.split(" ");
|
||||||
right = right.replace(/ .+$/g, "");
|
return words[words.length - 1]; //return last word
|
||||||
|
} else {
|
||||||
return left + right;
|
return preText;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
showEmojiPopout(event) {
|
showEmojiPopout(event) {
|
||||||
if (event.keyCode == 38 || event.keyCode == 40) return; // up/down
|
if (event.keyCode == 38 || event.keyCode == 40) return; // up/down
|
||||||
|
|
||||||
const cursorPosition = event.target.selectionStart;
|
const cursorPosition = event.target.selectionStart;
|
||||||
const cursorWord = this.GetWordByPos(this.message, cursorPosition)
|
const cursorWord = this.ReturnWord(this.message, cursorPosition);
|
||||||
const cursorLetter = this.message.substring(cursorPosition - 1, cursorPosition)
|
const cursorLetter = this.message.substring(
|
||||||
|
cursorPosition - 1,
|
||||||
|
cursorPosition
|
||||||
|
);
|
||||||
|
|
||||||
if (cursorLetter.trim() == "" || cursorWord.endsWith(":"))
|
if (cursorLetter.trim() == "" || cursorWord.endsWith(":"))
|
||||||
return this.showEmojiSuggestions = false;
|
return (this.$store.dispatch('setEmojiArray', null));
|
||||||
|
|
||||||
if (cursorWord.startsWith(":") && cursorWord.length >= 3) {
|
if (!cursorWord.startsWith(":") || cursorWord.length <= 2)
|
||||||
const searchArr = emojiParser.searchEmoji(cursorWord.slice(1, -1));
|
return (this.$store.dispatch('setEmojiArray', null));
|
||||||
if (searchArr.length <= 0) return (this.showEmojiSuggestions = false);
|
|
||||||
this.emojiSuggestionsArray = searchArr;
|
const searchArr = emojiParser.searchEmoji(cursorWord.slice(1, -1));
|
||||||
this.showEmojiSuggestions = true;
|
if (searchArr.length <= 0) return (this.$store.dispatch('setEmojiArray', null));
|
||||||
}
|
|
||||||
|
(this.$store.dispatch('setEmojiArray', searchArr));
|
||||||
},
|
},
|
||||||
async onInput(event) {
|
async onInput(event) {
|
||||||
this.resize(event);
|
this.resize(event);
|
||||||
|
|
@ -254,6 +257,18 @@ export default {
|
||||||
this.resize(event);
|
this.resize(event);
|
||||||
this.showEmojiPopout(event);
|
this.showEmojiPopout(event);
|
||||||
},
|
},
|
||||||
|
enterEmojiSuggestion(){
|
||||||
|
this.$refs["input-box"].focus();
|
||||||
|
const emojiShortCode = `:${this.emojiArray[this.emojiIndex].shortcodes[0]}:`
|
||||||
|
const cursorPosition = this.$refs['input-box'].selectionStart;
|
||||||
|
const cursorWord = this.ReturnWord(this.message, cursorPosition);
|
||||||
|
|
||||||
|
const start = cursorPosition - cursorWord.length;
|
||||||
|
const end = cursorPosition;
|
||||||
|
|
||||||
|
this.message = this.message.substring(0, start) + emojiShortCode + this.message.substring(end);
|
||||||
|
return (this.$store.dispatch('setEmojiArray', null));
|
||||||
|
},
|
||||||
keyDown(event) {
|
keyDown(event) {
|
||||||
this.resize(event);
|
this.resize(event);
|
||||||
this.emojiSwitchKey(event);
|
this.emojiSwitchKey(event);
|
||||||
|
|
@ -262,6 +277,10 @@ export default {
|
||||||
// and the shift key is not held
|
// and the shift key is not held
|
||||||
if (!event.shiftKey) {
|
if (!event.shiftKey) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
if (this.emojiArray){
|
||||||
|
this.enterEmojiSuggestion();
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.sendMessage();
|
this.sendMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -333,6 +352,7 @@ export default {
|
||||||
}, 2500);
|
}, 2500);
|
||||||
};
|
};
|
||||||
bus.$on("newMessage", this.hideTypingStatus);
|
bus.$on("newMessage", this.hideTypingStatus);
|
||||||
|
bus.$on("emojiSuggestions:Selected", this.enterEmojiSuggestion)
|
||||||
//dismiss notification on focus
|
//dismiss notification on focus
|
||||||
window.onfocus = () => {
|
window.onfocus = () => {
|
||||||
bus.$emit("title:change", "Nertivia");
|
bus.$emit("title:change", "Nertivia");
|
||||||
|
|
@ -349,6 +369,7 @@ export default {
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
bus.$off("newMessage", this.hideTypingStatus);
|
bus.$off("newMessage", this.hideTypingStatus);
|
||||||
|
bus.$off("emojiSuggestions:Selected", this.enterEmojiSuggestion)
|
||||||
delete this.$options.sockets.typingStatus;
|
delete this.$options.sockets.typingStatus;
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|
@ -381,6 +402,12 @@ export default {
|
||||||
},
|
},
|
||||||
channelName() {
|
channelName() {
|
||||||
return this.$store.getters.channelName;
|
return this.$store.getters.channelName;
|
||||||
|
},
|
||||||
|
emojiArray() {
|
||||||
|
return this.$store.getters.emojiArray;
|
||||||
|
},
|
||||||
|
emojiIndex() {
|
||||||
|
return this.$store.getters.getEmojiIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,9 @@
|
||||||
<div class="emoji-suggetions-list">
|
<div class="emoji-suggetions-list">
|
||||||
<div
|
<div
|
||||||
v-for="(emoji, index) in $props.emojiArray.slice(0,10)"
|
v-for="(emoji, index) in $props.emojiArray.slice(0,10)"
|
||||||
:class="{emoji: true, selected: index === selectedIndex}"
|
:class="{emojiItem: true, selected: index === emojiIndex}"
|
||||||
@mouseover="hoverEvent"
|
@mouseover="hoverEvent"
|
||||||
|
@click="clickEvent"
|
||||||
:key="emoji.hexcode"
|
:key="emoji.hexcode"
|
||||||
>
|
>
|
||||||
<div class="preview" v-html="emojiParser(emoji.unicode)"></div>
|
<div class="preview" v-html="emojiParser(emoji.unicode)"></div>
|
||||||
|
|
@ -17,48 +18,51 @@ import { bus } from "@/main";
|
||||||
import emojiParser from "@/utils/emojiParser.js";
|
import emojiParser from "@/utils/emojiParser.js";
|
||||||
export default {
|
export default {
|
||||||
props: ["emojiArray"],
|
props: ["emojiArray"],
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
selectedIndex: 0
|
|
||||||
};
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
emojiParser(emoji) {
|
emojiParser(emoji) {
|
||||||
return emojiParser.replaceEmojis(emoji);
|
return emojiParser.replaceEmojis(emoji);
|
||||||
},
|
},
|
||||||
hoverEvent(event) {
|
hoverEvent(event) {
|
||||||
const emoji = event.target.closest(".emoji");
|
const emoji = event.target.closest(".emojiItem");
|
||||||
const parent = event.target.parentElement.children;
|
const parent = event.target.parentElement.children;
|
||||||
if (!emoji || !emoji) return;
|
if (!emoji) return;
|
||||||
const index = [...parent].findIndex(el => el === emoji);
|
const index = [...parent].findIndex(el => el === emoji);
|
||||||
if (index >= 0) this.selectedIndex = index;
|
if (index >= 0) this.$store.dispatch("changeIndex", index);
|
||||||
},
|
},
|
||||||
KeySwitch(key) {
|
KeySwitch(key) {
|
||||||
if (key == "up") {
|
if (key == "up") {
|
||||||
if (this.selectedIndex == 0)
|
if (this.emojiIndex == 0)
|
||||||
return (this.selectedIndex =
|
return this.$store.dispatch(
|
||||||
this.$props.emojiArray.slice(0, 10).length - 1);
|
"changeIndex",
|
||||||
|
this.$props.emojiArray.slice(0, 10).length - 1
|
||||||
|
);
|
||||||
|
|
||||||
this.selectedIndex--;
|
this.$store.dispatch("changeIndex", this.emojiIndex - 1);
|
||||||
}
|
}
|
||||||
if (key == "down") {
|
if (key == "down") {
|
||||||
if (
|
if (this.emojiIndex == this.$props.emojiArray.slice(0, 10).length - 1)
|
||||||
this.selectedIndex ==
|
return this.$store.dispatch("changeIndex", 0);
|
||||||
this.$props.emojiArray.slice(0, 10).length - 1
|
this.$store.dispatch("changeIndex", this.emojiIndex + 1);
|
||||||
)
|
|
||||||
return (this.selectedIndex = 0);
|
|
||||||
|
|
||||||
this.selectedIndex++;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
clickEvent() {
|
||||||
|
bus.$emit('emojiSuggestions:Selected')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
bus.$on("emojiSuggestions:up", () => this.KeySwitch("up"));
|
bus.$on("emojiSuggestions:key", this.KeySwitch);
|
||||||
bus.$on("emojiSuggestions:down", () => this.KeySwitch("down"));
|
},
|
||||||
|
destroyed() {
|
||||||
|
bus.$off("emojiSuggestions:key", this.KeySwitch);
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
emojiArray() {
|
emojiArray() {
|
||||||
this.selectedIndex = 0;
|
this.$store.dispatch("changeIndex", 0);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
emojiIndex() {
|
||||||
|
return this.$store.getters.getEmojiIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -96,7 +100,7 @@ export default {
|
||||||
.short-code {
|
.short-code {
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
.emoji {
|
.emojiItem {
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
align-content: center;
|
align-content: center;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import notificationsModule from './modules/notificationsModule';
|
||||||
import settingsModule from './modules/settingsModule';
|
import settingsModule from './modules/settingsModule';
|
||||||
import uploadFilesModule from './modules/uploadFilesModule';
|
import uploadFilesModule from './modules/uploadFilesModule';
|
||||||
import popoutsModule from './modules/popoutsModule';
|
import popoutsModule from './modules/popoutsModule';
|
||||||
|
import emojiSuggestionModule from './modules/emojiSuggestionModule';
|
||||||
import {
|
import {
|
||||||
router
|
router
|
||||||
} from './../router'
|
} from './../router'
|
||||||
|
|
@ -23,7 +24,8 @@ export const store = new Vuex.Store({
|
||||||
socketModule,
|
socketModule,
|
||||||
settingsModule,
|
settingsModule,
|
||||||
uploadFilesModule,
|
uploadFilesModule,
|
||||||
popoutsModule
|
popoutsModule,
|
||||||
|
emojiSuggestionModule
|
||||||
},
|
},
|
||||||
state: {
|
state: {
|
||||||
|
|
||||||
|
|
|
||||||
47
src/store/modules/emojiSuggestionModule.js
Normal file
47
src/store/modules/emojiSuggestionModule.js
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
import axios from 'axios'
|
||||||
|
import Vue from 'vue'
|
||||||
|
import {
|
||||||
|
bus
|
||||||
|
} from '../../main'
|
||||||
|
import VueRouter from 'vue-router';
|
||||||
|
import NotificationSounds from '@/utils/notificationSound';
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
array: null,
|
||||||
|
index: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
const getters = {
|
||||||
|
emojiArray(state) {
|
||||||
|
return state.array;
|
||||||
|
},
|
||||||
|
getEmojiIndex(state) {
|
||||||
|
return state.index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const actions = {
|
||||||
|
setEmojiArray(context, array) {
|
||||||
|
context.commit('setEmojiArray', array)
|
||||||
|
},
|
||||||
|
changeIndex(context, index) {
|
||||||
|
context.commit('changeIndex', index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mutations = {
|
||||||
|
setEmojiArray(state, array) {
|
||||||
|
Vue.set(state, "array", array);
|
||||||
|
},
|
||||||
|
changeIndex(state, index) {
|
||||||
|
Vue.set(state, "index", index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
namespace: true,
|
||||||
|
state,
|
||||||
|
getters,
|
||||||
|
actions,
|
||||||
|
mutations
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue