Skip to content

Commit d884b89

Browse files
committed
chat design
1 parent dad2dd6 commit d884b89

File tree

5 files changed

+83
-14
lines changed

5 files changed

+83
-14
lines changed

angular/src/app/shared/components/chat/chat.component.css

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
.chatWrapper{
22
width: 500px;
33
margin: 0 auto;
4-
border: solid black 1px;
54
padding: 10px;
6-
height: 70vh;
5+
height: 77vh;
6+
border-radius: 25px;
7+
box-shadow: 2px 3px 13px #0000007a;
8+
background: linear-gradient(to top, rgba(117, 179, 208, 1) 0%, #ace0f9 100%);
79
}
810

911
.input{
1012
position: relative;
11-
13+
background: white;
1214
}
1315

1416
.sendBtn{
@@ -30,7 +32,7 @@
3032

3133
.messagesWrapper{
3234
overflow-y: auto;
33-
height: 89%;
35+
height: 80%;
3436
}
3537
.messagesC{
3638
display: flex;
@@ -44,32 +46,49 @@
4446
.message{
4547
display: flex;
4648
justify-content: left;
49+
flex-direction: row;
50+
align-items: center;
51+
52+
}
53+
54+
.message .messageText{
55+
background: #265978;
56+
color: white;
4757
}
4858

4959
.message[isme="true"]{
5060
align-self: end;
5161
}
5262

63+
.message[isme="true"] .messageText{
64+
background: white;
65+
color: #265978;
66+
}
67+
5368
.messageText{
5469
padding: 10px 40px;
5570
background-color: grey;
5671
border-radius: 100px;
5772
width: fit-content;
5873
}
5974
.date{
75+
margin-top: 0.5px;
6076
font-size: 12px;
61-
color: grey;
77+
color: black;
6278
}
6379

80+
.message[isme="true"] .date{
81+
text-align: right;
82+
}
6483

6584
.input{
66-
border: 1px solid black;
6785
border-radius: 100px;
6886
overflow: hidden;
69-
height: 50px;
87+
height: fit-content;
7088
position: absolute;
7189
bottom: 0;
7290
width: 100%;
91+
padding: 5px;
7392
}
7493
.input input{
7594
padding: 10px 90px 10px 10px;
@@ -87,3 +106,20 @@
87106
border-radius: 100px;
88107
cursor: pointer;
89108
}
109+
110+
.sendBtn:hover, .sendBtn:active{
111+
background-color: #6dcde2;
112+
}
113+
114+
img{
115+
width: 45px;
116+
height: 45px;
117+
border: 1px solid;
118+
border-radius: 50%;
119+
margin-bottom: 10px;
120+
}
121+
122+
.recipientName h3{
123+
margin: 10px 2px;
124+
font-style: italic;
125+
}

angular/src/app/shared/components/chat/chat.component.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<section class="chatWrapper">
22
<div class="chatC">
3+
<div class="recipientName">
4+
<h3>{{nameRecipient}}</h3>
5+
</div>
36
<div #messagesWrapper class="messagesWrapper">
47
<div class="messagesC">
58
<div *ngFor="let message of chatMessages" [attr.isMe]="message.authorId==me.id" class="message">
6-
<div *ngIf="message.authorId==me.id" class="userPic">
7-
9+
<div *ngIf="message.authorId!==me.id" class="userPic">
10+
<img [src]="'data:image/png;base64,'+ imageRecipient">
811
</div>
912
<div class="textAndDateC">
1013
<div class="messageText">

angular/src/app/shared/components/chat/chat.component.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {ActivatedRoute} from "@angular/router";
33
import * as signalR from "@microsoft/signalr";
44
import {ChatService} from "../../services/chat.service";
55
import {ChatMessage, Me} from "../../interfaces";
6+
import { UserService } from '../../services/user.service';
67

78

89
@Component({
@@ -14,16 +15,20 @@ export class ChatComponent implements OnInit{
1415
constructor(
1516
private route: ActivatedRoute,
1617
private ChatService: ChatService,
18+
private userService:UserService
1719
) {
1820
}
1921

2022
@ViewChild("messagesWrapper") messagesWrapper!:ElementRef
21-
22-
me:Me = {id: "7a83ebc1-fefd-4173-836e-f03db09cd1ee"}
23+
idFromToken!:string ;
24+
me:Me = {id: this.idFromToken}
2325
egn:string = ""
2426
connection:any = undefined
2527

26-
messageText:string=""
28+
messageText:string="";
29+
30+
imageRecipient!:string;
31+
nameRecipient!: string;
2732

2833
chatMessages:ChatMessage[] = [
2934

@@ -35,6 +40,13 @@ export class ChatComponent implements OnInit{
3540
this.startChatBtnClick(this.egn,localStorage.getItem("token")!)
3641
this.fetchChat()
3742
});
43+
const token= localStorage.getItem('token');
44+
this.idFromToken = this.userService.jwtdecrypt(token!).nameid;
45+
this.me = {id: this.idFromToken};
46+
setTimeout(() => {
47+
this.scrollToBottom();
48+
}, 500);
49+
this.recipient();
3850
}
3951

4052

@@ -73,7 +85,11 @@ export class ChatComponent implements OnInit{
7385

7486
const formattedDateTime = `${year}-${month}-${day} ${hours}:${minutes}`;
7587

76-
this.chatMessages.push({ message: messageElement.value, messageTime: formattedDateTime, authorId: this.me.id, isRead: true})
88+
this.chatMessages.push({
89+
message: messageElement.value, messageTime: formattedDateTime, authorId: this.me.id, isRead: true,
90+
id: '',
91+
recipientId: ''
92+
})
7793
messageElement.value =""
7894
setTimeout(()=>{
7995
this.scrollToBottom()
@@ -83,5 +99,14 @@ export class ChatComponent implements OnInit{
8399
this.messagesWrapper.nativeElement.scrollTop = this.messagesWrapper.nativeElement.scrollHeight;
84100
}
85101

102+
recipient(){
103+
this.userService.getRecipient(this.egn).subscribe((res:any)=>{
104+
console.log(res);
105+
this.imageRecipient=res.userImage;
106+
this.nameRecipient=res.fullName;
107+
},(err)=>{
108+
console.log(err);
109+
})
110+
}
86111

87112
}

angular/src/app/shared/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const medicineEndpoint = 'API/Medicine'
33
export const prescriptionEndpoint = 'API/Prescription'
44
export const registerEndpoint = 'API/Authentication/Register'
55
export const loginEndpoint = 'API/Authentication/Login'
6+
export const chatEndpoint = 'API/Chat/'
67

78

89
const prescriptionId = "e617dab4-d3ca-47d7-a52c-90ad09126f61"

angular/src/app/shared/services/user.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HttpClient } from '@angular/common/http';
22
import { Injectable } from '@angular/core';
3-
import {API_URL, loginEndpoint, prescriptionEndpoint, registerEndpoint} from '../constants';
3+
import {API_URL, chatEndpoint, loginEndpoint, prescriptionEndpoint, registerEndpoint} from '../constants';
44
import * as jwt from 'jsonwebtoken';
55
import {jwtDecode} from 'jwt-decode';
66
import {Profile} from "../interfaces";
@@ -55,4 +55,8 @@ export class UserService {
5555
return this.http.get<Profile>(prescriptionEndpoint+'?patientEgn='+personalId)
5656
//Prescription?patientEgn=333333333
5757
}
58+
59+
getRecipient(id:string){
60+
return this.http.get(chatEndpoint+id)
61+
}
5862
}

0 commit comments

Comments
 (0)