Skip to content

Commit

Permalink
0.3.6 Fix iOS filter UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectricS01 committed Oct 3, 2024
1 parent a705363 commit 1252581
Show file tree
Hide file tree
Showing 6 changed files with 751 additions and 745 deletions.
4 changes: 2 additions & 2 deletions TPU_Mac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 0.3.5;
MARKETING_VERSION = 0.3.6;
PRODUCT_BUNDLE_IDENTIFIER = "ElectricS01.TPU-Mac";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand Down Expand Up @@ -561,7 +561,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 0.3.5;
MARKETING_VERSION = 0.3.6;
PRODUCT_BUNDLE_IDENTIFIER = "ElectricS01.TPU-Mac";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand Down
340 changes: 171 additions & 169 deletions TPU_Mac/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,195 +236,197 @@ struct ChatView: View {
}

var body: some View {
VStack {
ScrollViewReader { proxy in
ScrollView {
LazyVStack(alignment: .leading, spacing: 0) {
ForEach(Array(chatMessages.enumerated()), id: \.element) { index, message in
let dontMerge = merge(message: message, previousMessage: index != 0 ? chatMessages[index - 1] : nil)
Spacer(minLength: dontMerge ? 16 : 0)
if message.id == unreadId {
HStack {
VStack { Divider().background(.red) }
Text("New Message").foregroundStyle(.red)
VStack { Divider().background(.red) }
}
}
if message.reply != nil {
Button(action: {
proxy.scrollTo(message.replyId)
}) {
#if !os(macOS)
VStack {
ScrollViewReader { proxy in
ScrollView {
LazyVStack(alignment: .leading, spacing: 0) {
ForEach(Array(chatMessages.enumerated()), id: \.element) { index, message in
let dontMerge = merge(message: message, previousMessage: index != 0 ? chatMessages[index - 1] : nil)
Spacer(minLength: dontMerge ? 16 : 0)
if message.id == unreadId {
HStack {
Image(systemName: "arrow.turn.up.right").frame(width: 16, height: 16)
ProfilePicture(avatar: message.reply?.user?.avatar, size: 16)
Text(message.reply?.user?.username ?? "User has been deleted")
Text((message.reply?.content ?? "Message has been deleted").replacingOccurrences(of: "\n", with: "")).textSelection(.enabled).lineLimit(1)
}.padding(EdgeInsets(top: 0, leading: 18, bottom: 0, trailing: 0))
}.buttonStyle(.plain)
}
HStack(alignment: .top, spacing: 6) {
if dontMerge {
ProfilePicture(avatar: message.user?.avatar)
} else {
Spacer().frame(width: 32)
VStack { Divider().background(.red) }
Text("New Message").foregroundStyle(.red)
VStack { Divider().background(.red) }
}
}
VStack {
if dontMerge {
if message.reply != nil {
Button(action: {
proxy.scrollTo(message.replyId)
}) {
HStack {
Text(message.user?.username ?? "User has been deleted")
Text(DateUtils.dateFormat(message.createdAt))
}.frame(minWidth: 0,
maxWidth: .infinity,
minHeight: 0,
maxHeight: 10,
alignment: .topLeading)
}
if editingId != message.id {
Text(.init(message.content ?? "Message has been deleted"))
.textSelection(.enabled)
.frame(minWidth: 0,
maxWidth: .infinity,
alignment: .leading)
.lineLimit(nil)
Image(systemName: "arrow.turn.up.right").frame(width: 16, height: 16)
ProfilePicture(avatar: message.reply?.user?.avatar, size: 16)
Text(message.reply?.user?.username ?? "User has been deleted")
Text((message.reply?.content ?? "Message has been deleted").replacingOccurrences(of: "\n", with: "")).textSelection(.enabled).lineLimit(1)
}.padding(EdgeInsets(top: 0, leading: 18, bottom: 0, trailing: 0))
}.buttonStyle(.plain)
}
HStack(alignment: .top, spacing: 6) {
if dontMerge {
ProfilePicture(avatar: message.user?.avatar)
} else {
TextField("Keep it civil!", text: $editingMessage)
.onSubmit {
editMessage()
}
.focused($focusedField, equals: .editing)
.textFieldStyle(RoundedBorderTextFieldStyle())
Spacer().frame(width: 32)
}
ForEach(message.embeds, id: \.self) { embed in
if embed.media != [] {
LazyImage(url: URL(string: embed.media?[0].attachment == nil ? ("https://i.electrics01.com" + (embed.media?[0].proxyUrl ?? "")) : ("https://i.electrics01.com/i/" + (embed.media?[0].attachment ?? "")))) { state in
if let image = state.image {
image.resizable().aspectRatio(contentMode: .fit)
// .onAppear {
//// if chatMessages.count != 0 {
//// proxy.scrollTo(0, anchor: .bottom)
//// }
// }
} else if state.error != nil {
Color.red
} else {
ProgressView()
VStack {
if dontMerge {
HStack {
Text(message.user?.username ?? "User has been deleted")
Text(DateUtils.dateFormat(message.createdAt))
}.frame(minWidth: 0,
maxWidth: .infinity,
minHeight: 0,
maxHeight: 10,
alignment: .topLeading)
}
if editingId != message.id {
Text(.init(message.content ?? "Message has been deleted"))
.textSelection(.enabled)
.frame(minWidth: 0,
maxWidth: .infinity,
alignment: .leading)
.lineLimit(nil)
} else {
TextField("Keep it civil!", text: $editingMessage)
.onSubmit {
editMessage()
}
}.frame(minWidth: 0, maxWidth: 600, minHeight: 0, maxHeight: 400)
.focused($focusedField, equals: .editing)
.textFieldStyle(RoundedBorderTextFieldStyle())
}
}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)
}
Button(action: {
if replyingId != message.id {
replyingId = message.id
} else { replyingId = -1 }
}) {
Image(systemName: "arrowshape.turn.up.left.fill").frame(width: 16, height: 16)
}
Button(action: {
pinMessage(messageId: message.id, pinned: message.pinned)
}) {
Image(systemName: message.pinned ? "pin.slash.fill" : "pin.fill").frame(width: 16, height: 16)
}
if coreUser?.id == message.userId {
ForEach(message.embeds, id: \.self) { embed in
if embed.media != [] {
LazyImage(url: URL(string: embed.media?[0].attachment == nil ? ("https://i.electrics01.com" + (embed.media?[0].proxyUrl ?? "")) : ("https://i.electrics01.com/i/" + (embed.media?[0].attachment ?? "")))) { state in
if let image = state.image {
image.resizable().aspectRatio(contentMode: .fit)
// .onAppear {
//// if chatMessages.count != 0 {
//// proxy.scrollTo(0, anchor: .bottom)
//// }
// }
} else if state.error != nil {
Color.red
} else {
ProgressView()
}
}.frame(minWidth: 0, maxWidth: 600, minHeight: 0, maxHeight: 400)
}
}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)
}
Button(action: {
replyingId = -1
if editingId != message.id {
editingId = message.id
editingMessage = message.content ?? ""
} else { editingId = -1 }
if replyingId != message.id {
replyingId = message.id
} else { replyingId = -1 }
}) {
Image(systemName: "pencil").frame(width: 16, height: 16)
Image(systemName: "arrowshape.turn.up.left.fill").frame(width: 16, height: 16)
}
}
}.padding(EdgeInsets(top: 0, leading: 4, bottom: 0, trailing: 4)).id(message.id)
// .background(Color(hoverItem == message.id ? Color.primary : .clear))
// .onHover(perform: { _ in
// hoverItem = message.id
// })
}.padding(EdgeInsets(top: 0, leading: 8, bottom: 0, trailing: 12))
}
.id(0)
.frame(
minWidth: 0,
maxWidth: .infinity,
minHeight: 0,
maxHeight: .infinity,
alignment: .topLeading
)
.onAppear {
if chatMessages.count != 0 {
Button(action: {
pinMessage(messageId: message.id, pinned: message.pinned)
}) {
Image(systemName: message.pinned ? "pin.slash.fill" : "pin.fill").frame(width: 16, height: 16)
}
if coreUser?.id == message.userId {
Button(action: {
replyingId = -1
if editingId != message.id {
editingId = message.id
editingMessage = message.content ?? ""
} else { editingId = -1 }
}) {
Image(systemName: "pencil").frame(width: 16, height: 16)
}
}
}.padding(EdgeInsets(top: 0, leading: 4, bottom: 0, trailing: 4)).id(message.id)
// .background(Color(hoverItem == message.id ? Color.primary : .clear))
// .onHover(perform: { _ in
// hoverItem = message.id
// })
}.padding(EdgeInsets(top: 0, leading: 8, bottom: 0, trailing: 12))
}
.id(0)
.frame(
minWidth: 0,
maxWidth: .infinity,
minHeight: 0,
maxHeight: .infinity,
alignment: .topLeading
)
.onAppear {
if chatMessages.count != 0 {
proxy.scrollTo(0, anchor: .bottom)
}
}
.onChange(of: chatMessages) {
proxy.scrollTo(0, anchor: .bottom)
}
}
.onChange(of: chatMessages) {
proxy.scrollTo(0, anchor: .bottom)
if replyingId != -1 {
HStack {
Image(systemName: "arrow.turn.up.right").frame(width: 16, height: 16)
Text(chatMessages.last(where: { $0.id == replyingId })?.user?.username ?? "User has been deleted")
Text(chatMessages.last(where: { $0.id == replyingId })?.content ?? "Message has been deleted")
.textSelection(.enabled)
.lineLimit(1)
.onAppear {
if chatMessages.count != 0 {
proxy.scrollTo(0, anchor: .bottom)
}
}
}.padding(EdgeInsets(top: 0, leading: 18, bottom: 0, trailing: 0))
.frame(minWidth: 0,
maxWidth: .infinity,
alignment: .topLeading)
}
TextField("Keep it civil!", text: $inputMessage)
.focused($focusedField, equals: .editing)
.onSubmit {
sendMessage()
}
.textFieldStyle(RoundedBorderTextFieldStyle())
}
if replyingId != -1 {
HStack {
Image(systemName: "arrow.turn.up.right").frame(width: 16, height: 16)
Text(chatMessages.last(where: { $0.id == replyingId })?.user?.username ?? "User has been deleted")
Text(chatMessages.last(where: { $0.id == replyingId })?.content ?? "Message has been deleted")
.textSelection(.enabled)
.lineLimit(1)
.onAppear {
if chatMessages.count != 0 {
proxy.scrollTo(0, anchor: .bottom)
}
.navigationTitle(chatsList[chatOpen].recipient?.username ?? chatsList[chatOpen].name)
.navigationBarTitleDisplayMode(.inline)
.toolbar(content: {
ToolbarItem(placement: .principal) {
Text(chatsList[chatOpen].recipient?.username ?? chatsList[chatOpen].name)
.bold()
.onTapGesture {
showingSheet.toggle()
}
.sheet(isPresented: $showingSheet) {
List {
ForEach(0 ..< chatsList[chatOpen].users.count, id: \.self) { result in
Button(action: { print("Clicked: " + (chatsList[chatOpen].users[result].user?.username ?? "User's name could not be found")) }) {
HStack {
ProfilePicture(avatar: chatsList[chatOpen].users[result].user?.avatar)
Text(chatsList[chatOpen].users[result].user?.username ?? "User's name could not be found")
Spacer()
}.contentShape(Rectangle())
}.buttonStyle(.plain)
}
}.padding(EdgeInsets(top: -8, leading: -10, bottom: -8, trailing: 0))
}
}.padding(EdgeInsets(top: 0, leading: 18, bottom: 0, trailing: 0))
.frame(minWidth: 0,
maxWidth: .infinity,
alignment: .topLeading)
}
TextField("Keep it civil!", text: $inputMessage)
.focused($focusedField, equals: .editing)
.onSubmit {
sendMessage()
}
.textFieldStyle(RoundedBorderTextFieldStyle())
})
}
.navigationTitle(chatsList[chatOpen].recipient?.username ?? chatsList[chatOpen].name)
.navigationBarTitleDisplayMode(.inline)
.toolbar(content: {
ToolbarItem(placement: .principal) {
Text(chatsList[chatOpen].recipient?.username ?? chatsList[chatOpen].name)
.bold()
.onTapGesture {
showingSheet.toggle()
}
.sheet(isPresented: $showingSheet) {
List {
ForEach(0 ..< chatsList[chatOpen].users.count, id: \.self) { result in
Button(action: { print("Clicked: " + (chatsList[chatOpen].users[result].user?.username ?? "User's name could not be found")) }) {
HStack {
ProfilePicture(avatar: chatsList[chatOpen].users[result].user?.avatar)
Text(chatsList[chatOpen].users[result].user?.username ?? "User's name could not be found")
Spacer()
}.contentShape(Rectangle())
}.buttonStyle(.plain)
}
}.padding(EdgeInsets(top: -8, leading: -10, bottom: -8, trailing: 0))
}
.navigationTitle("Comms")
.onAppear {
getChat(chatId: chatOpen)
messagesSubscription()
editingSubscription()
}
.onDisappear {
if let subscription = apolloSubscription {
subscription.cancel()
apolloSubscription = nil
}
})
}
.navigationTitle("Comms")
.onAppear {
getChat(chatId: chatOpen)
messagesSubscription()
editingSubscription()
}
.onDisappear {
if let subscription = apolloSubscription {
subscription.cancel()
apolloSubscription = nil
}
}
.onReceive(NotificationCenter.default.publisher(for: NSNotification.Name("NavigateToPage"))) { notification in
if let userInfo = notification.userInfo, let pageID = userInfo["to"] as? Int {
getChat(chatId: chatsList.firstIndex(where: { $0.id == pageID }))
.onReceive(NotificationCenter.default.publisher(for: NSNotification.Name("NavigateToPage"))) { notification in
if let userInfo = notification.userInfo, let pageID = userInfo["to"] as? Int {
getChat(chatId: chatsList.firstIndex(where: { $0.id == pageID }))
}
}
}
#endif
}
}
Loading

0 comments on commit 1252581

Please sign in to comment.