Skip to content

Commit 57c7dea

Browse files
committed
Update Chat.vue
Updated to automatically scroll to the object that was selected.
1 parent f5fb4df commit 57c7dea

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

spa/src/components/Chat.vue

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
<li
161161
v-for="object in sharedObjects"
162162
:key="object.id"
163+
:ref="'obj-'+object.id"
163164
class="flex cursor-default"
164165
@click="handler($event)" @contextmenu="handler($event)"
165166
>
@@ -524,6 +525,17 @@ export default Vue.extend({
524525
}
525526
e.preventDefault();
526527
},
528+
scrollToSelected(): void {
529+
if (!this.selectedId) return;
530+
this.$nextTick(() => {
531+
const refKey = `obj-${this.selectedId}`;
532+
const el = (this.$refs as any)[refKey] as Element | Element[] | undefined;
533+
const node = Array.isArray(el) ? el[0] : el;
534+
if (node && (node as any).scrollIntoView) {
535+
(node as any).scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' });
536+
}
537+
});
538+
},
527539
async getRole(): Promise<void> {
528540
const response = await this.$http.get("/member/getrolename");
529541
if(response.data.PrimaryRoleName.length === 0 ){
@@ -570,7 +582,6 @@ export default Vue.extend({
570582
body: this.message,
571583
})
572584
.then((response) => {
573-
//this.debugMsg(response.data);
574585
msgID = response.data.messageId;
575586
if(this.displayRole){
576587
this.$socket.emit("CHAT", {
@@ -1236,6 +1247,10 @@ export default Vue.extend({
12361247
clickId(newValue) {
12371248
this.selectedId = newValue;
12381249
this.activePanel = 'sharedObjects';
1250+
this.$nextTick(() => this.scrollToSelected());
1251+
},
1252+
selectedId() {
1253+
this.scrollToSelected();
12391254
},
12401255
async activePanel() {
12411256
if(this.activePanel === 'backpack') {
@@ -1244,6 +1259,9 @@ export default Vue.extend({
12441259
if(this.activePanel === 'places') {
12451260
await this.getActivePlaces();
12461261
}
1262+
if(this.activePanel === 'sharedObjects' && this.selectedId) {
1263+
this.$nextTick(() => this.scrollToSelected());
1264+
}
12471265
},
12481266
},
12491267
computed: {

0 commit comments

Comments
 (0)