Skip to content

Commit

Permalink
SlidingTabView removed
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabicz committed Mar 5, 2023
1 parent 0e44ae7 commit 6aaf8dc
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 36 deletions.
23 changes: 6 additions & 17 deletions OpenAI chat-dalle/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,19 @@
//

import SwiftUI
import SlidingTabView

struct ContentView: View {

@State private var selectedTabIndex = 0
var chatBotView = ChatBotView()
var dalleView = DalleView()

var body: some View {
NavigationView {

VStack(alignment: .leading) {
SlidingTabView(selection: self.$selectedTabIndex, tabs: ["CHAT BOT", "DALL-E 2"], animation: .easeInOut, activeAccentColor: .white, inactiveAccentColor: .gray, selectionBarColor: .white)

//selectedTabIndex == 0 ? AnyView(chatBotView) : AnyView(dalleView)
if selectedTabIndex == 0 {
chatBotView
} else {
dalleView
TabView {
ChatBotView().tabItem{
Label("CHAT BOT", systemImage: "ellipses.bubble")
}
DalleView().tabItem{
Label("DALL-E 2", systemImage: "paintbrush")
}

Spacer()
}
.background(Color(red: 53/255, green: 54/255, blue: 65/255))
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions OpenAI chat-dalle/OpenAI_chat_dalleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import SwiftUI

@main
struct OpenAI_chat_dalleApp: App {
let dalleViewModel = DalleViewModel()

var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(dalleViewModel)

}
}
}
2 changes: 1 addition & 1 deletion OpenAI chat-dalle/ViewModels/DalleViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DalleViewModel: ObservableObject {
private let apiKey: String
private var openAI: OpenAI
@Published var messages = [Message]()

init() {
apiKey = "API_KEY"
openAI = OpenAI(Configuration(organizationId: "Personal", apiKey: apiKey))
Expand Down
14 changes: 7 additions & 7 deletions OpenAI chat-dalle/Views/ChatBotView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import SwiftUI

struct ChatBotView: View {

@StateObject var chatBotViewModel = ChatBotViewModel()
@ObservedObject var chatBotViewModel = ChatBotViewModel()
@State var typingMessage: String = ""
@Namespace var bottomID
@FocusState private var fieldIsFocused: Bool

var body: some View {
NavigationView(){
VStack(alignment: .leading){
Expand Down Expand Up @@ -95,8 +95,8 @@ struct ChatBotView: View {
}
}

struct ChatGPTView_Previews: PreviewProvider {
static var previews: some View {
ChatBotView()
}
}
//struct ChatGPTView_Previews: PreviewProvider {
// static var previews: some View {
// ChatBotView()
// }
//}
12 changes: 6 additions & 6 deletions OpenAI chat-dalle/Views/DalleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI
struct DalleView: View {

@State var typingMessage: String = ""
@StateObject var dalleViewModel = DalleViewModel()
@ObservedObject var dalleViewModel = DalleViewModel()
@Namespace var bottomID
@FocusState private var fieldIsFocused: Bool

Expand Down Expand Up @@ -100,8 +100,8 @@ struct DalleView: View {
}
}

struct DalleView_Previews: PreviewProvider {
static var previews: some View {
DalleView()
}
}
//struct DalleView_Previews: PreviewProvider {
// static var previews: some View {
// DalleView()
// }
//}
11 changes: 6 additions & 5 deletions OpenAI chat-dalle/Views/Messages/MessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import SwiftUI

struct MessageView: View {
var message: Message
var message: Message

var body: some View {
HStack(spacing: 0) {
VStack(alignment: .leading, spacing: 0) {
Expand All @@ -31,19 +31,19 @@ struct MessageView: View {
.aspectRatio(contentMode: .fit)
.cornerRadius(13)
.shadow(color: .green, radius: 1)

Button(action: {
guard let image = message.content as? UIImage else {
return
}

let avc = UIActivityViewController(activityItems: [image, UIImage()], applicationActivities: nil)

avc.completionWithItemsHandler = { (activityType, completed, returnedItems, error) in
if completed && activityType == .saveToCameraRoll {
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}
}

if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first(where: { $0.isKeyWindow }),
let rootViewController = window.rootViewController {
Expand All @@ -66,5 +66,6 @@ struct MessageView: View {
}
.background(message.isUserMessage ? Color(red: 53/255, green: 54/255, blue: 65/255) : Color(red: 68/255, green: 70/255, blue: 83/255))
.shadow( radius: message.isUserMessage ? 0 : 0.5)

}
}

0 comments on commit 6aaf8dc

Please sign in to comment.