Skip to content

Commit

Permalink
Show messages in chats
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectricS01 committed Oct 19, 2023
1 parent 8f775ab commit 1302a42
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 42 deletions.
10 changes: 1 addition & 9 deletions TPU Mac/TPU_Mac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
C45099272ACFFA8100FA9247 /* TPU_MacTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C45099262ACFFA8100FA9247 /* TPU_MacTests.swift */; };
C45099312ACFFA8100FA9247 /* TPU_MacUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C45099302ACFFA8100FA9247 /* TPU_MacUITests.swift */; };
C45099332ACFFA8100FA9247 /* TPU_MacUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C45099322ACFFA8100FA9247 /* TPU_MacUITestsLaunchTests.swift */; };
C4569DEA2AD170CF00F17C06 /* ApolloCodegenLib in Frameworks */ = {isa = PBXBuildFile; productRef = C4569DE92AD170CF00F17C06 /* ApolloCodegenLib */; };
C4569DEC2AD1787E00F17C06 /* graphql in Resources */ = {isa = PBXBuildFile; fileRef = C4569DEB2AD1787E00F17C06 /* graphql */; };
C4569DF12AD17A2A00F17C06 /* PrivateUploaderAPI in Frameworks */ = {isa = PBXBuildFile; productRef = C4569DF02AD17A2A00F17C06 /* PrivateUploaderAPI */; };
C4569DF72AD1828300F17C06 /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4569DF62AD1828300F17C06 /* Network.swift */; };
Expand Down Expand Up @@ -67,7 +66,6 @@
C4569DF12AD17A2A00F17C06 /* PrivateUploaderAPI in Frameworks */,
C48C2E9E2AD0417B0000A362 /* Apollo in Frameworks */,
C4FE71542AD3F085003E4DC0 /* KeychainSwift in Frameworks */,
C4569DEA2AD170CF00F17C06 /* ApolloCodegenLib in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -175,7 +173,6 @@
name = "TPU Mac";
packageProductDependencies = (
C48C2E9D2AD0417B0000A362 /* Apollo */,
C4569DE92AD170CF00F17C06 /* ApolloCodegenLib */,
C4569DF02AD17A2A00F17C06 /* PrivateUploaderAPI */,
C4FE71532AD3F085003E4DC0 /* KeychainSwift */,
);
Expand Down Expand Up @@ -674,7 +671,7 @@
repositoryURL = "https://github.com/apollographql/apollo-ios.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.5.2;
minimumVersion = 1.6.1;
};
};
C4FE71522AD3F084003E4DC0 /* XCRemoteSwiftPackageReference "keychain-swift" */ = {
Expand All @@ -688,11 +685,6 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
C4569DE92AD170CF00F17C06 /* ApolloCodegenLib */ = {
isa = XCSwiftPackageProductDependency;
package = C48C2E9C2AD0417B0000A362 /* XCRemoteSwiftPackageReference "apollo-ios" */;
productName = ApolloCodegenLib;
};
C4569DF02AD17A2A00F17C06 /* PrivateUploaderAPI */ = {
isa = XCSwiftPackageProductDependency;
productName = PrivateUploaderAPI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apollographql/apollo-ios.git",
"state" : {
"revision" : "42802f5cbcab4705c73d9d83fbc2bcfab022bc17",
"version" : "1.5.2"
}
},
{
"identity" : "inflectorkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattt/InflectorKit",
"state" : {
"revision" : "d8cbcc04972690aaa5fc760a2b9ddb3e9f0decd7",
"version" : "1.0.0"
"revision" : "7bbdce4bebb0b3978e69f8a34f26227ab733d96d",
"version" : "1.6.1"
}
},
{
Expand All @@ -35,24 +26,6 @@
"revision" : "7a2e3cd27de56f6d396e84f63beefd0267b55ccb",
"version" : "0.14.1"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531",
"version" : "1.2.3"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "a902f1823a7ff3c9ab2fba0f992396b948eda307",
"version" : "1.0.5"
}
}
],
"version" : 2
Expand Down
66 changes: 62 additions & 4 deletions TPU Mac/TPU_Mac/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,78 @@ struct GalleryView: View {

struct CommsView: View {
@State private var chatsList: [ChatsQuery.Data.Chat] = []
@State private var chatMessages: [MessagesQuery.Data.Message] = []
@State private var chatOpen: Int = 0

func openChat (chatId: Int?) {
messages(chat: chatId ?? 0) { result in
switch result {
case .success(let graphQLResult):
if let unwrapped = graphQLResult.data {
chatMessages = unwrapped.messages
chatOpen = chatId ?? 0
}
case .failure(let error):
print(error)
}
}
}

var body: some View {
NavigationSplitView {
List {
ForEach(0..<chatsList.count, id: \.self) { result in
Button(chatsList[result].recipient?.username ?? chatsList[result].name) {
print(chatsList[result].id)
openChat(chatId: chatsList[result].association?.id)
}

}
}
} detail: {
Text("Comms")
.navigationTitle("Comms")
if chatOpen != 0 {
ScrollView {
VStack(alignment: .leading, spacing: 6) {
ForEach(0..<chatMessages.count, id: \.self) { result in
HStack {
AsyncImage(
url: URL(string: "https://i.electrics01.com/i/" + (chatMessages[result].user?.avatar ?? ""))
) { image in
image.resizable()
} placeholder: {
ProgressView()
}
.frame(width: 32, height: 32)
.cornerRadius(16)
VStack {
HStack {
Text(chatMessages[result].user?.username ?? "Error")
Text(chatMessages[result].createdAt )
}.frame(minWidth: 0,
maxWidth: .infinity,
minHeight: 0,
maxHeight: .infinity,
alignment: .topLeading)
Text(chatMessages[result].content ?? "Error")
.frame(minWidth: 0,
maxWidth: .infinity,
minHeight: 0,
maxHeight: .infinity,
alignment: .topLeading)
}
}
}
}.frame(
minWidth: 0,
maxWidth: .infinity,
minHeight: 0,
maxHeight: .infinity,
alignment: .topLeading
)
}
} else {
Text("Comms")
}
}
.navigationTitle("Comms")
.onAppear {
chats { result in
switch result {
Expand Down

0 comments on commit 1302a42

Please sign in to comment.