Skip to content

Commit

Permalink
Add indicator for selected conversation in conversation list (#86)
Browse files Browse the repository at this point in the history
* pass `selectedConversation` to `ConversationHistoryListView`


---------

Co-authored-by: Augustinas Malinauskas <[email protected]>
  • Loading branch information
wzulfikar and AugustDev authored Apr 29, 2024
1 parent c5f580d commit ebed97c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions Enchanted/UI/Shared/Chat/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ struct Chat: View, Sendable {
#else
SideBarStack(sidebarWidth: 300,showSidebar: $showMenu, sidebar: {
SidebarView(
selectedConversation: conversationStore.selectedConversation,
conversations: conversationStore.conversations,
onConversationTap: onConversationTap,
onConversationDelete: onConversationDelete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct ConversationGroup: Hashable {
}

struct ConversationHistoryList: View {
var selectedConversation: ConversationSD?
var conversations: [ConversationSD]
var onTap: (_ conversation: ConversationSD) -> ()
var onDelete: (_ conversation: ConversationSD) -> ()
Expand Down Expand Up @@ -60,17 +61,25 @@ struct ConversationHistoryList: View {
})

ForEach(conversationGroup.conversations, id:\.self) { dailyConversation in
HStack {
Button(action: {onTap(dailyConversation)}) {
Button(action: {onTap(dailyConversation)}) {
HStack {
Circle()
.frame(width: 6, height: 6)
.animation(.easeOut(duration: 0.15))
.transition(.opacity)
.showIf(selectedConversation == dailyConversation)

Text(dailyConversation.name)
.lineLimit(1)
.font(.system(size: 16))
.fontWeight(.regular)
.foregroundColor(Color(.label))
.animation(.easeOut(duration: 0.15))
.transition(.opacity)
Spacer()
}
.buttonStyle(.plain)
.animation(.easeOut(duration: 0.15))
}
.buttonStyle(.plain)
.contextMenu(menuItems: {
Button(role: .destructive, action: { onDelete(dailyConversation) }) {
Label("Delete", systemImage: "trash")
Expand All @@ -86,5 +95,5 @@ struct ConversationHistoryList: View {


#Preview {
ConversationHistoryList(conversations: ConversationSD.sample, onTap: {_ in}, onDelete: {_ in}, onDeleteDailyConversations: {_ in})
ConversationHistoryList(selectedConversation: ConversationSD.sample[0], conversations: ConversationSD.sample, onTap: {_ in}, onDelete: {_ in}, onDeleteDailyConversations: {_ in})
}
4 changes: 3 additions & 1 deletion Enchanted/UI/Shared/Sidebar/SidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI

struct SidebarView: View {
@Environment(\.openWindow) var openWindow
var selectedConversation: ConversationSD?
var conversations: [ConversationSD]
var onConversationTap: (_ conversation: ConversationSD) -> ()
var onConversationDelete: (_ conversation: ConversationSD) -> ()
Expand All @@ -28,6 +29,7 @@ struct SidebarView: View {
VStack {
ScrollView() {
ConversationHistoryList(
selectedConversation: selectedConversation,
conversations: conversations,
onTap: onConversationTap,
onDelete: onConversationDelete,
Expand Down Expand Up @@ -67,5 +69,5 @@ struct SidebarView: View {
}

#Preview {
SidebarView(conversations: ConversationSD.sample, onConversationTap: {_ in}, onConversationDelete: {_ in}, onDeleteDailyConversations: {_ in})
SidebarView(selectedConversation: ConversationSD.sample[0], conversations: ConversationSD.sample, onConversationTap: {_ in}, onConversationDelete: {_ in}, onDeleteDailyConversations: {_ in})
}
1 change: 1 addition & 0 deletions Enchanted/UI/macOS/Chat/ChatView_macOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct ChatView: View {
var body: some View {
NavigationSplitView(columnVisibility: $columnVisibility) {
SidebarView(
selectedConversation: selectedConversation,
conversations: conversations,
onConversationTap: onConversationTap,
onConversationDelete: onConversationDelete,
Expand Down

0 comments on commit ebed97c

Please sign in to comment.