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

68 messages section bugs #24

Merged
merged 2 commits into from
Jan 18, 2022
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
14 changes: 4 additions & 10 deletions src/components/Messages/MessageViewItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const props = defineProps({
},
});

const emits = defineEmits(["tag-click"]);

const showVoting = computed(
() => getActiveChannel.value && getActiveChannel.value.votingAllowed
);
Expand Down Expand Up @@ -91,23 +93,15 @@ function getDownVoteClass(item) {
return className;
}

// emit to update message in messagespage
function addToMessage(pseudonym) {
let textArea = document.getElementById("messageTextArea");
let existingText = textArea.value.trim();
if (pseudonym.indexOf(" ") > -1) pseudonym = '"' + pseudonym + '"';
if (existingText.indexOf(pseudonym) > -1) return;
if (existingText != "") existingText += " ";
textArea.value = existingText + "@" + pseudonym + " ";
textArea.focus();
emits("tag-click", pseudonym, true);
}

function getMessageClass(item) {
return item.downVotes.length > 2 ? "text-gray-400" : "text-black";
}

const threadLink = computed(
() => "/threads/" + this.$route.params.channel + "/" + this.item.name
);
/**
* Build html tag for tagged pseudonym
*/
Expand Down
23 changes: 12 additions & 11 deletions src/components/Messages/MessagesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@
>No messages. Start a conversation.</span
>
<template v-for="item in items" :key="item.id">
<MessageViewItem :item="item" />
<MessageViewItem :item="item" v-bind="$attrs" />
</template>
</div>
</div>
</template>

<script>
export default {
inheritAttrs: false,
};
</script>

<script setup>
import MessageViewItem from "./MessageViewItem.vue";

export default {
components: {
MessageViewItem,
},
props: {
items: {
type: Array,
required: true,
},
defineProps({
items: {
type: Array,
required: true,
},
};
});
</script>
17 changes: 14 additions & 3 deletions src/views/MessagesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
}
"
:items="updatedMsgs"
@tag-click="tagClick"
/>
<TagList
:items="filteredTags"
Expand Down Expand Up @@ -157,10 +158,14 @@ watchEffect(() => {
/**
* Update tag on message to follow a taggable pattern
*/
function tagClick(value) {
function tagClick(value, isClickedDirect = false) {
let pseudonym = `"${value}" `;
// Replace last occurrence of word starting with @
message.value = message.value.replace(/(\w*)(?=[^@]*)$/, pseudonym);
if (!isClickedDirect) {
// Replace last occurrence of word starting with @
message.value = message.value.replace(/(\w*)(?=[^@]*)$/, pseudonym);
} else {
message.value = message.value.replace(/$/, `@${pseudonym}`);
}
messageTextArea.value.focus();
}

Expand Down Expand Up @@ -188,6 +193,12 @@ function messageHandler(data) {
*/
if (data.thread.id === route.params.threadId) {
addMessage(data);
}

/**
* Scroll to bottom if the message belongs to current user
*/
if (data.owner === getId.value) {
scrollToBottom();
}

Expand Down