기능추가 :: 대화 > 검색기능

This commit is contained in:
leejh 2019-10-23 15:45:48 +09:00
parent 8b55d904d6
commit 7e5bc54be1
2 changed files with 65 additions and 4 deletions

View File

@ -1,3 +1,33 @@
<ucap-room-list-item *ngFor="let room of roomList" [loginRes]="loginRes" [roomInfo]="room" <div>
[roomUserInfo]="getRoomUserList(room)" [sessionVerinfo]="sessionVerinfo" (click)="onSelectedRoom(room)"> <mat-form-field>
</ucap-room-list-item> <input
matInput
#inputSearch
type="text"
maxlength="20"
placeholder="대화방 이름 검색"
value=""
(keydown.enter)="onKeyDownEnter(inputSearch.value)"
/>
<button
mat-button
matSuffix
mat-icon-button
aria-label="Clear"
(click)="inputSearch.value = ''; searchWord = ''; isSearch = false"
>
<mat-icon>close</mat-icon>
</button>
</mat-form-field>
</div>
<div>
<ucap-room-list-item
*ngFor="let room of getRoomList()"
[loginRes]="loginRes"
[roomInfo]="room"
[roomUserInfo]="getRoomUserList(room)"
[sessionVerinfo]="sessionVerinfo"
(click)="onSelectedRoom(room)"
>
</ucap-room-list-item>
</div>

View File

@ -46,6 +46,9 @@ export class ChatComponent implements OnInit, OnDestroy {
); );
} }
isSearch = false;
searchWord = '';
ngOnInit() { ngOnInit() {
this.roomSubscription = combineLatest([ this.roomSubscription = combineLatest([
this.store.pipe( this.store.pipe(
@ -90,11 +93,39 @@ export class ChatComponent implements OnInit, OnDestroy {
} }
} }
onKeyDownEnter(search: string) {
if (search.trim().length > 1) {
this.isSearch = true;
this.searchWord = search;
}
}
onSelectedRoom(roomInfo: RoomInfo) { onSelectedRoom(roomInfo: RoomInfo) {
this.store.dispatch(ChatStore.selectedRoom({ roomSeq: roomInfo.roomSeq })); this.store.dispatch(ChatStore.selectedRoom({ roomSeq: roomInfo.roomSeq }));
} }
getRoomUserList(roomInfo: RoomInfo): RoomUserInfo[] | UserInfoShort[] { getRoomList() {
if (this.isSearch && this.searchWord.trim().length > 0) {
return this.roomList.filter(room => {
if (room.roomName.indexOf(this.searchWord) >= 0) {
return true;
}
if (
this.getRoomUserList(room).filter(user =>
user.seq !== this.loginRes.userSeq
? user.name.indexOf(this.searchWord) >= 0
: false
).length > 0
) {
return true;
}
return false;
});
}
return this.roomList;
}
getRoomUserList(roomInfo: RoomInfo): (RoomUserInfo | UserInfoShort)[] {
if (!!this.roomUserList && 0 < this.roomUserList.length) { if (!!this.roomUserList && 0 < this.roomUserList.length) {
const i = this.roomUserList.findIndex( const i = this.roomUserList.findIndex(
value => roomInfo.roomSeq === value.roomSeq value => roomInfo.roomSeq === value.roomSeq