Skip to content

Commit

Permalink
Fix scroll to last prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
gsans committed Oct 12, 2023
1 parent c9c2435 commit a15acc0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/app/custom-chat/custom-chat.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="container chat column">
<!-- <div class="header">{{title}}</div> -->

<div class="messages">
<div class="messages" #scroll>
<ng-container *ngFor="let message of messages">
<div class="message-container">
<div class="avatar"
Expand Down
42 changes: 24 additions & 18 deletions src/app/custom-chat/custom-chat.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
-webkit-font-smoothing: antialiased;
}

.header, .messages, .form {
.header,
.messages,
.form {
background-color: white;
}

Expand Down Expand Up @@ -40,7 +42,7 @@
.custom-control {
background-color: rgb(247, 249, 252);
border-color: rgb(228, 233, 242);
border-radius: 5px ;
border-radius: 5px;
width: 100%;

padding-bottom: 7px;
Expand All @@ -49,7 +51,6 @@
padding-top: 7px;
}


.avatar {
display: block;
border-radius: 50%;
Expand Down Expand Up @@ -105,7 +106,10 @@
padding-left: 10px;
top: 6px;
position: relative;
font-family: 'Source Code Pro', Consolas, Menlo, Monaco, "Andale Mono WT", "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Liberation Mono", "Nimbus Mono L", "Courier New", Courier, monospace;
font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Andale Mono WT",
"Andale Mono", "Lucida Console", "Lucida Sans Typewriter",
"DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Liberation Mono",
"Nimbus Mono L", "Courier New", Courier, monospace;
font-size: 12px;
font-weight: 600;
}
Expand All @@ -119,10 +123,9 @@
padding: 1px 4px 1px 4px;
border-radius: 10px;
border: 1px solid rgba(208, 208, 208, 0.5);
box-shadow: 1px 1px 1px 0px rgba(208, 208, 208, 0.2)
box-shadow: 1px 1px 1px 0px rgba(208, 208, 208, 0.2);
}


.message-content .btn-reply {
display: none;
float: right;
Expand Down Expand Up @@ -154,7 +157,7 @@ input.mdc-text-field__input:focus {
border-bottom-color: yellow;
}

::ng-deep markdown code[class*="language-"],
::ng-deep markdown code[class*="language-"],
::ng-deep markdown pre[class*="language-"] {
font-size: 12px;
font-weight: 600;
Expand All @@ -174,8 +177,8 @@ input.mdc-text-field__input:focus {
/* Hide scrollbar for IE, Edge and Firefox */
::ng-deep markdown code[class*="language-"],
::ng-deep markdown pre[class*="language-"] {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}

::ng-deep .mermaid svg {
Expand All @@ -189,22 +192,26 @@ input.mdc-text-field__input:focus {
caret-color: black !important;
}


::ng-deep .mdc-text-field--filled:not(.mdc-text-field--disabled).mdc-text-field--focused .mdc-floating-label,
::ng-deep .mdc-text-field--filled:not(.mdc-text-field--disabled).mdc-text-field--focused .mdc-floating-label--float-above {
::ng-deep
.mdc-text-field--filled:not(.mdc-text-field--disabled).mdc-text-field--focused
.mdc-floating-label,
::ng-deep
.mdc-text-field--filled:not(.mdc-text-field--disabled).mdc-text-field--focused
.mdc-floating-label--float-above {
color: inherit !important;
}

::ng-deep .mdc-text-field--filled:not(.mdc-text-field--disabled) .mdc-line-ripple::after {
border-bottom-color: inherit !important;
border-width: 1px;
::ng-deep
.mdc-text-field--filled:not(.mdc-text-field--disabled)
.mdc-line-ripple::after {
border-bottom-color: inherit !important;
border-width: 1px;
}

::ng-deep .mat-mdc-form-field-focus-overlay {
background-color: #a3a3a3 !important;
background-color: #a3a3a3 !important;
}


.header {
position: relative;
}
Expand All @@ -224,5 +231,4 @@ input.mdc-text-field__input:focus {

.root {
height: 100%;
overflow: hidden;
}
6 changes: 4 additions & 2 deletions src/app/custom-chat/custom-chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare global {
})
export class CustomChatComponent implements OnInit {
@ViewChild('bottom') bottom!: ElementRef;
@ViewChild('scroll') scroll!: ElementRef;
readonly clipboardButton = ClipboardButtonComponent;
disabled: boolean = false;

Expand Down Expand Up @@ -138,7 +139,7 @@ alert(s);
date: new Date(),
avatar: "https://pbs.twimg.com/profile_images/1688607716653105152/iL4c9mUH_400x400.jpg",
} as any);
//this.scrollToBottom();
this.scrollToBottom();

this.loading = true;
//disable after timeout
Expand Down Expand Up @@ -191,7 +192,8 @@ alert(s);

private scrollToBottom() {
requestAnimationFrame(() => {
this.bottom.nativeElement.scrollIntoView({ behavior: 'smooth' });
const top = this.bottom.nativeElement.offsetTop;
this.scroll.nativeElement.scrollTop = top;
});
}

Expand Down

0 comments on commit a15acc0

Please sign in to comment.