diff --git a/chatapi/src/models/db-doc.model.ts b/chatapi/src/models/db-doc.model.ts index 0721a6364a..81d3295026 100644 --- a/chatapi/src/models/db-doc.model.ts +++ b/chatapi/src/models/db-doc.model.ts @@ -3,6 +3,6 @@ export interface DbDoc { _rev: string; user: any; title: string; - time: number; + createdDate: number; conversations: []; } diff --git a/chatapi/src/services/chat.service.ts b/chatapi/src/services/chat.service.ts index 0aeb030066..0e7854cb68 100644 --- a/chatapi/src/services/chat.service.ts +++ b/chatapi/src/services/chat.service.ts @@ -23,6 +23,7 @@ export async function chat(data: any): Promise<{ } else { dbData.title = content; dbData.conversations = []; + dbData.createdDate = Date.now(); } dbData.conversations.push({ 'query': content, 'response': '' }); @@ -35,6 +36,7 @@ export async function chat(data: any): Promise<{ dbData.conversations[dbData.conversations.length - 1].response = completionText; + dbData.updatedDate = Date.now(); dbData._id = res?.id; dbData._rev = res?.rev; const couchSaveResponse = await db.insert(dbData); diff --git a/chatapi/src/utils/db.utils.ts b/chatapi/src/utils/db.utils.ts index 422b7a7646..483b83b428 100644 --- a/chatapi/src/utils/db.utils.ts +++ b/chatapi/src/utils/db.utils.ts @@ -12,7 +12,8 @@ async function getChatDocument(id: string) { const res = await db.get(id) as DbDoc; return { 'conversations': res.conversations, - 'title': res.title + 'title': res.title, + 'createdDate': res.createdDate, }; // Should return user, team data as well particularly for the "/conversations" endpoint } catch (error) { @@ -24,9 +25,10 @@ async function getChatDocument(id: string) { } export async function retrieveChatHistory(dbData: any, messages: ChatMessage[]) { - const { conversations, title } = await getChatDocument(dbData._id); + const { conversations, title, createdDate } = await getChatDocument(dbData._id); dbData.conversations = conversations; dbData.title = title; + dbData.createdDate = createdDate; for (const { query, response } of conversations) { messages.push({ 'role': 'user', 'content': query }); diff --git a/src/app/chat/chat-sidebar/chat-sidebar.component.html b/src/app/chat/chat-sidebar/chat-sidebar.component.html index 42853bc2fd..5dc39b2d13 100644 --- a/src/app/chat/chat-sidebar/chat-sidebar.component.html +++ b/src/app/chat/chat-sidebar/chat-sidebar.component.html @@ -1,8 +1,8 @@ - +
- @@ -30,7 +30,7 @@
    -
  • +
  • diff --git a/src/app/chat/chat-sidebar/chat-sidebar.component.ts b/src/app/chat/chat-sidebar/chat-sidebar.component.ts index a758d2a90b..1b85ea15fb 100644 --- a/src/app/chat/chat-sidebar/chat-sidebar.component.ts +++ b/src/app/chat/chat-sidebar/chat-sidebar.component.ts @@ -1,10 +1,11 @@ -import { Component, OnInit, OnDestroy } from '@angular/core'; +import { Component, OnInit, OnDestroy, HostListener } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { ChatService } from '../../shared/chat.service'; import { CouchService } from '../../shared/couchdb.service'; +import { DeviceInfoService, DeviceType } from '../../shared/device-info.service'; import { SearchService } from '../../shared/forms/search.service'; import { showFormErrors } from '../../shared/table-helpers'; import { UserService } from '../../shared/user.service'; @@ -17,6 +18,13 @@ import { UserService } from '../../shared/user.service'; export class ChatSidebarComponent implements OnInit, OnDestroy { readonly dbName = 'chat_history'; private onDestroy$ = new Subject(); + private _titleSearch = ''; + get titleSearch(): string { return this._titleSearch.trim(); } + set titleSearch(value: string) { + this._titleSearch = value; + this.recordSearch(); + this.filterConversations(); + } conversations: any; filteredConversations: any; selectedConversation: any; @@ -24,22 +32,20 @@ export class ChatSidebarComponent implements OnInit, OnDestroy { fullTextSearch = false; searchType: 'questions' | 'responses'; overlayOpen = false; + deviceType: DeviceType; + deviceTypes: typeof DeviceType = DeviceType; titleForm: { [key: string]: FormGroup } = {}; - private _titleSearch = ''; - get titleSearch(): string { return this._titleSearch.trim(); } - set titleSearch(value: string) { - this._titleSearch = value; - this.recordSearch(); - this.filterConversations(); - } constructor( private chatService: ChatService, private couchService: CouchService, + private deviceInfoService: DeviceInfoService, private formBuilder: FormBuilder, private searchService: SearchService, private userService: UserService - ) {} + ) { + this.deviceType = this.deviceInfoService.getDeviceType(); + } ngOnInit() { this.titleSearch = ''; @@ -53,6 +59,10 @@ export class ChatSidebarComponent implements OnInit, OnDestroy { this.recordSearch(true); } + @HostListener('window:resize') OnResize() { + this.deviceType = this.deviceInfoService.getDeviceType(); + } + subscribeToNewChats() { this.chatService.newChatAdded$ .pipe(takeUntil(this.onDestroy$)) @@ -74,7 +84,7 @@ export class ChatSidebarComponent implements OnInit, OnDestroy { updateConversation(conversation, title) { this.couchService.updateDocument( - this.dbName, { ...conversation, title: title, updatedTime: this.couchService.datePlaceholder } + this.dbName, { ...conversation, title: title, updatedDate: this.couchService.datePlaceholder } ).subscribe((data) => { this.getChatHistory(); return data; @@ -101,8 +111,13 @@ export class ChatSidebarComponent implements OnInit, OnDestroy { getChatHistory() { this.chatService.findConversations([], [ this.userService.get().name ]).subscribe( - (conversations) => { - this.conversations = conversations; + (conversations: any) => { + this.conversations = conversations.sort((a, b) => { + const dateA = a.updatedDate || a.createdDate; + const dateB = b.updatedDate || b.createdDate; + + return dateB - dateA; + }); this.filteredConversations = [ ...conversations ]; this.initializeFormGroups(); }, diff --git a/src/app/chat/chat-sidebar/chat-sidebar.scss b/src/app/chat/chat-sidebar/chat-sidebar.scss index 0f26e3746f..1a8ffba02d 100644 --- a/src/app/chat/chat-sidebar/chat-sidebar.scss +++ b/src/app/chat/chat-sidebar/chat-sidebar.scss @@ -3,12 +3,8 @@ .header { padding: 10px; - .start-button { - border: solid; - margin-right: 0.5rem; - } - .icon-button { + margin-left: 10px; background-color: $accent; } } diff --git a/src/app/chat/chat-window/chat-window.component.ts b/src/app/chat/chat-window/chat-window.component.ts index 8903a6a011..5655843210 100644 --- a/src/app/chat/chat-window/chat-window.component.ts +++ b/src/app/chat/chat-window/chat-window.component.ts @@ -22,7 +22,6 @@ export class ChatWindowComponent implements OnInit, OnDestroy { promptForm: FormGroup; data = { user: this.userService.get().name, - time: this.couchService.datePlaceholder, content: '', _id: '', _rev: '' @@ -119,7 +118,8 @@ export class ChatWindowComponent implements OnInit, OnDestroy { submitPrompt() { const content = this.promptForm.get('prompt').value; - this.data.content = content; + this.data = { ...this.data, content }; + this.setSelectedConversation(); this.chatService.getPrompt(this.data, true).subscribe( diff --git a/src/app/courses/step-view-courses/courses-step-view.component.html b/src/app/courses/step-view-courses/courses-step-view.component.html index b72a5258e6..3b5323e91a 100644 --- a/src/app/courses/step-view-courses/courses-step-view.component.html +++ b/src/app/courses/step-view-courses/courses-step-view.component.html @@ -65,9 +65,9 @@

    Step {{ {{stepNum}}/{{maxStep}} - + - +

diff --git a/src/app/meetups/add-meetups/meetups-add.component.ts b/src/app/meetups/add-meetups/meetups-add.component.ts index 6498768fa3..29937c0e38 100644 --- a/src/app/meetups/add-meetups/meetups-add.component.ts +++ b/src/app/meetups/add-meetups/meetups-add.component.ts @@ -55,11 +55,15 @@ export class MeetupsAddComponent implements OnInit { private fb: FormBuilder, private userService: UserService, private stateService: StateService - ) { } + ) { + this.createForm(); + } ngOnInit() { if (this.meetup._id) { this.setMeetupData({ ...this.meetup }); + } else { + this.createForm(); } if (!this.isDialog && this.route.snapshot.url[0].path === 'update') { this.couchService.get('meetups/' + this.route.snapshot.paramMap.get('id')).subscribe( @@ -67,7 +71,6 @@ export class MeetupsAddComponent implements OnInit { error => console.log(error) ); } - this.createForm(); } setMeetupData(meetup: any) {