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

feat: multi line sumbol #590

Merged
merged 7 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions src/assets/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@

@import './components/_chat.scss';
@import './components/_login-form.scss';
@import './components/_arrow-return.scss';

@import './themes/adamant/_index.scss';
16 changes: 16 additions & 0 deletions src/assets/styles/components/_arrow-return.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@import '../themes/adamant/_mixins.scss';

.arrow-return {
@include a-text-explanation();
}

.v-theme--light {
.arrow-return {
opacity: 0.7;
}
}
.v-theme--dark {
.arrow-return {
opacity: 0.6;
}
}
7 changes: 4 additions & 3 deletions src/components/AChat/AChatReplyPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
</div>

<div :class="classes.message">
{{ isCryptoTransfer ? cryptoTransferLabel : messageLabel }}
<span v-if="!isCryptoTransfer" v-html="messageLabel"></span>
<span v-else>{{ cryptoTransferLabel }}</span>
</div>

<v-btn
Expand All @@ -28,7 +29,7 @@ import { useStore } from 'vuex'
import ChatAvatar from '@/components/Chat/ChatAvatar.vue'
import { Cryptos } from '@/lib/constants'
import currencyFormatter from '@/filters/currencyAmountWithSymbol'
import { removeFormats } from '@/lib/markdown'
import { formatMessage } from '@/lib/markdown'

const className = 'a-chat-reply-preview'
const classes = {
Expand Down Expand Up @@ -77,7 +78,7 @@ export default defineComponent({

const messageLabel = computed(() => {
return store.state.options.formatMessages
? removeFormats(props.message.message)
? formatMessage(props.message.message)
: props.message.message
})

Expand Down
6 changes: 3 additions & 3 deletions src/components/AChat/QuotedMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{{ cryptoTransferLabel }}
</span>
<span v-else>
{{ messageLabel }}
<span v-html="messageLabel"></span>
</span>
</div>
</div>
Expand All @@ -35,7 +35,7 @@ import { getTransaction, decodeChat } from '@/lib/adamant-api'
import { normalizeMessage } from '@/lib/chat/helpers'
import { Cryptos } from '@/lib/constants'
import currencyFormatter from '@/filters/currencyAmountWithSymbol'
import { removeFormats } from '@/lib/markdown'
import { formatMessage } from '@/lib/markdown'

const className = 'quoted-message'
const classes = {
Expand Down Expand Up @@ -124,7 +124,7 @@ export default defineComponent({

const messageLabel = computed(() => {
return store.state.options.formatMessages
? removeFormats(transaction.value.message)
? formatMessage(transaction.value.message)
: transaction.value.message
})

Expand Down
6 changes: 3 additions & 3 deletions src/components/ChatPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@
<v-icon v-else :icon="statusIcon" size="15" />
</template>

{{ lastMessageTextNoFormats }}
<span v-html="lastMessageTextNoFormats"></span>
</v-list-item-subtitle>
</template>
</div>
</v-list-item>
</template>

<script>
import { removeFormats } from '@/lib/markdown'
import { formatMessage } from '@/lib/markdown'

import transaction from '@/mixins/transaction'
import formatDate from '@/filters/dateBrief'
Expand Down Expand Up @@ -183,7 +183,7 @@ export default {
},
lastMessageTextNoFormats() {
if (this.isAdamantChat(this.contactId) || this.$store.state.options.formatMessages) {
return removeFormats(this.lastMessageTextLocalized)
return formatMessage(this.lastMessageTextLocalized)
}

return this.lastMessageTextLocalized
Expand Down
13 changes: 12 additions & 1 deletion src/lib/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ export function renderMarkdown(text = '') {
*/
export function removeFormats(text = '') {
const node = document.createElement('div')
node.innerHTML = marked(DOMPurify.sanitize(text), { renderer })
const textWithSumbol = text.replace(/\n/g, '↵ ')
node.innerHTML = marked(DOMPurify.sanitize(textWithSumbol), { renderer })

return node.textContent || node.innerText || ''
}

export function formatMessage(text = '') {
const node = document.createElement('div')
const textWithSumbol = text.replace(/\n/g, '↵ ')
juliahermak marked this conversation as resolved.
Show resolved Hide resolved
node.innerHTML = marked(DOMPurify.sanitize(textWithSumbol), { renderer })

const textWithoutHtml = node.textContent || node.innerText || ''
const styledText = textWithoutHtml.replace(/↵/g, '<span class="arrow-return">↵</span>')
return styledText
}
Loading