-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(AutoScroll): Implement AutoScroll to Chat Component (#116)
* fea(AutoScroll): Use Flexbox to set scrol to bottom when render * feat(Chat): Add new message per 5 seconds * feat(AutoScroll): remove autoscroll feature from scroll component * feat(AutoScroll): Add new scroll component for chat * fea(AutoScroll): Make Custom Chat Scroll Style same as Vue Custom Scroll Bar * feat(AutoScroll): show unread messages & init them when click Mark as Read * feat(AutoScroll): prevent autoscroll when prevent scroll offset is set * feat(AutoScroll): change labels with i18n text * feat(AutoScroll): add custom scroll css for firefox (Firefox 64 only support two type of css for custom scroll bar) * feat(AutoScroll): Update unread message style when scroll element is resized * feat(AutoScroll): refactor some css values on chat scroll * feat(AutoScroll): Move action/mutation/state from Media to Ui and Update i18n text Co-authored-by: Matt Wisniewski <[email protected]>
- Loading branch information
Eric Lee
and
Matt Wisniewski
authored
Sep 6, 2021
1 parent
b64409f
commit 59bcdd2
Showing
18 changed files
with
283 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div :class="classObject" ref="scrollRef" v-on:scroll="onScrolled"> | ||
<slot /> | ||
<div | ||
v-if="$store.state.ui.unreadMessage>0" | ||
class="new-message-alert" | ||
:style="{ right: newMessageAlertPos.right + 'px', | ||
top: newMessageAlertPos.top + 'px', width: newMessageAlertPos.width + 'px' }" | ||
@click="autoScrollToBottom" | ||
> | ||
{{ $store.state.ui.unreadMessage }} {{ $t('pages.chat.new_message') }} | ||
<span>{{ $t('pages.chat.jump_to_current') }}</span> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
.scroll-area { | ||
margin: auto; | ||
width: 100%; | ||
height: 100%; | ||
white-space: nowrap; | ||
} | ||
|
||
.enable-wrap { | ||
white-space: normal !important; | ||
} | ||
|
||
.auto-scroll { | ||
display: flex; | ||
flex-direction: column-reverse; | ||
overflow-y: auto; | ||
overflow-x: hidden; | ||
|
||
/* Custom Scroll for Firefox */ | ||
scrollbar-color: @primary-color transparent; | ||
scrollbar-width: thin; | ||
|
||
/* Scroll Width */ | ||
&::-webkit-scrollbar { | ||
width: 5px; | ||
&:hover { | ||
width: 11px; | ||
} | ||
} | ||
|
||
/* Scroll Track */ | ||
&::-webkit-scrollbar-track { | ||
border-radius: @corner-rounding; | ||
} | ||
|
||
/* Scroll Handle */ | ||
&::-webkit-scrollbar-thumb { | ||
background: @primary-color; | ||
border-radius: @corner-rounding; | ||
} | ||
} | ||
|
||
.new-message-alert { | ||
position: fixed; | ||
background: @primary-color; | ||
cursor: pointer; | ||
padding: 2px 20px; | ||
font-size: 14px; | ||
border-radius: 6px; | ||
z-index: 1000; | ||
span { | ||
float: right; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<template src="./ChatScroll.html"></template> | ||
|
||
<script> | ||
import Vue from 'vue' | ||
export default Vue.extend({ | ||
name: 'ChatScroll', | ||
props: { | ||
autoScroll: { | ||
type: Boolean, | ||
default: true, | ||
required: false, | ||
}, | ||
preventScrollOffset: { | ||
type: Number, | ||
default: 500, | ||
required: false, | ||
}, | ||
enableWrap: { | ||
type: Boolean, | ||
default: false, | ||
required: false, | ||
}, | ||
contents: { | ||
/* Content Type could be any value in below array */ | ||
type: [Array, Object, String, Number], | ||
default: '', | ||
required: false, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
loaded: false, | ||
newMessageAlert: false, | ||
newMessageAlertPos: { | ||
top: 0, | ||
right: 30, | ||
width: 0, | ||
}, | ||
ro: new ResizeObserver(() => {}), | ||
} | ||
}, | ||
computed: { | ||
classObject() { | ||
return { | ||
'enable-wrap': this.enableWrap, | ||
'auto-scroll': this.autoScroll, | ||
dark: this.theme === 'dark', | ||
} | ||
}, | ||
}, | ||
watch: { | ||
contents: { | ||
deep: true, | ||
handler() { | ||
const lastMsg = this.contents[this.contents.length - 1] | ||
if (lastMsg.from === this.$mock.user.address) { | ||
this.autoScrollToBottom() | ||
} else { | ||
this.newMessageAlert = true | ||
} | ||
}, | ||
}, | ||
}, | ||
mounted() { | ||
this.$nextTick(() => { | ||
this.ro = new ResizeObserver((_) => { | ||
this.calcNewMessageAlertPos() | ||
}) | ||
this.ro.observe(this.$el) | ||
this.autoScrollToBottom() | ||
}) | ||
}, | ||
beforeDestroy() { | ||
this.loaded = false | ||
this.ro.unobserve(this.$el) | ||
}, | ||
methods: { | ||
autoScrollToBottom() { | ||
const interval = this.loaded ? 100 : 1000 | ||
if (this.$el && this.autoScroll) { | ||
setTimeout(() => { | ||
this.$nextTick(() => { | ||
this.$el.scrollTop = 0 | ||
this.loaded = true | ||
this.$store.dispatch('setIsScrollOver', false) | ||
}) | ||
}, interval) | ||
} | ||
}, | ||
calcNewMessageAlertPos() { | ||
if (this.$el) { | ||
this.newMessageAlertPos.top = this.$el.offsetTop + 15 | ||
this.newMessageAlertPos.width = this.$el.offsetWidth - 60 | ||
} | ||
}, | ||
onScrolled() { | ||
if (this.$el) { | ||
if (Math.abs(this.$el.scrollTop) > this.preventScrollOffset) { | ||
this.$store.dispatch('setIsScrollOver', true) | ||
} else { | ||
this.$store.dispatch('setIsScrollOver', false) | ||
} | ||
} | ||
}, | ||
}, | ||
}) | ||
</script> | ||
|
||
<!-- Add "scoped" attribute to limit CSS to this component only --> | ||
<style scoped lang="less" src="./ChatScroll.less"></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ | |
|
||
.enable-wrap { | ||
white-space: normal!important; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
<div id="direct"> | ||
<UiTailoredEncrypted /> | ||
<TailoredMessagingConversation :messages="$store.state.media.messages" :loading="loading" /> | ||
</div> | ||
<TailoredMessagingConversation | ||
:messages="$store.state.ui.messages" | ||
:loading="loading" | ||
/> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.