Skip to content

Commit

Permalink
Merge pull request #9 from mbulling/version1
Browse files Browse the repository at this point in the history
Version1
  • Loading branch information
mbulling authored Apr 2, 2023
2 parents b37bdcb + eb741e2 commit e009d28
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 29 deletions.
2 changes: 1 addition & 1 deletion trivai/Assets.xcassets/AppIcon 1.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "TrivAI_logo5.png",
"filename" : "trivai_logo_3.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion trivai/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "TrivAI_logo5.png",
"filename" : "trivai_logo_3.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions trivai/Networking/NetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import SwiftUI

class NetworkManager {

static let host = "http://100.26.175.163:5000"
static let local_host = "http://192.168.4.43:3000"
static let host = "http://127.0.0.1:5000"

// Testing
static func testQuestions(completion: @escaping ([Question]?, Bool, _ errorMsg: String?) -> Void) {
Expand Down Expand Up @@ -61,7 +60,7 @@ class NetworkManager {

// Create multiple choice questions based on topic
static func createTopicQuestion(topic: String, num_questions: Int, completion: @escaping ([Question]?, Bool, _ errorMsg: String?) -> Void) {
let endpoint = "\(local_host)/mcq/topic/"
let endpoint = "\(host)/beta_topics_mc"

let params : Parameters = [
"topic": topic,
Expand Down Expand Up @@ -110,7 +109,7 @@ class NetworkManager {

// Get topics
static func getTopics(completion: @escaping ([Question]?, Bool, _ errorMsg: String?) -> Void) {
let endpoint = "\(host)/topics/"
let endpoint = "\(host)/beta_get_topics/"


AF.request(endpoint, method: .post, encoding: JSONEncoding.default).validate().responseData {
Expand Down
64 changes: 52 additions & 12 deletions trivai/Networking/NetworkTesting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ struct NetworkTesting: View {
@State var apiCall = false

func call_api() {
self.quizInfo.title = user_input
self.apiCall = true
NetworkManager.createTopicQuestion(topic: user_input, num_questions: Int(numQuestions+0.49)) { questions, success, error in
if (success) {
self.quizInfo.title = user_input
self.apiCall = false
DispatchQueue.main.async {
self.questionListWrapper = QuestionListWrapper(questions: questions ?? [])
Expand All @@ -38,12 +38,38 @@ struct NetworkTesting: View {

var body: some View {
VStack() {
if(self.apiCall == false){
VStack {
Text("Choose Topic")
.font(.system(size:40))
.foregroundColor(Color.black)
.foregroundColor(Color.white)
.bold()
TextField("Enter Any Topic", text:$user_input)
.padding()
.padding(.bottom, 20)
.padding(.top, 10)
.background(Color("background3"))
.frame(maxWidth: .infinity)
}
.background(Color("background3"))
.frame(maxWidth: .infinity)



Spacer()
VStack {
Text("\(numQuestions, specifier: "%.0f") QUESTIONS")
.font(.caption)
.fontWeight(.bold)
.foregroundColor(.gray)
Slider(value: $numQuestions, in: 1...10)

}
.padding(.leading, 50)
.padding(.trailing, 50)

TextField("ENTER TOPIC", text:$user_input)
.font(.system(size:25))
.fontWeight(.bold)
.foregroundColor(.gray)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
.frame(width: 320.0, height: 40.0)
Expand All @@ -52,12 +78,13 @@ struct NetworkTesting: View {
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(lineWidth: 1.0)
.border(Color("background3"))
).padding()
VStack {
Text("\(numQuestions, specifier: "%.0f") questions")
Slider(value: $numQuestions, in: 1...10)
}.padding()


Spacer()

VStack {
Button (action: {
self.call_api()
}) {
Expand All @@ -69,17 +96,30 @@ struct NetworkTesting: View {
.background(Color("background4"))
.cornerRadius(10)
.shadow(radius: 20)
.background(Color("background3")).padding(EdgeInsets(top: 30, leading: 10, bottom: 0, trailing: 10))
.padding()
}.sheet(item: $questionListWrapper) { wrapper in
QuestionsView(info: quizInfo, questions: wrapper.questions) {
QuestionsView(info: Info(title: self.user_input, peopleAttended: 100, rules: ["Answer the questions carefully"]), questions: wrapper.questions) {
// some action
}
}
} else {
Text("Loading...")
.sheet(isPresented: $apiCall) {
LoadingView()
}
}
.background(Color("background3")).padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))



}

}
}

#if DEBUG
struct NetworkTesting_Previews: PreviewProvider {
static var previews: some View {
NetworkTesting()
}
}
#endif
6 changes: 3 additions & 3 deletions trivai/main/CertificateRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct CertificateRow: View {
@State private var loading = false

func getTopics() {
AF.request("http://192.168.4.43:3000/topics").responseJSON { response in
AF.request("http://127.0.0.1:5000/topics").responseJSON { response in
print(response.result)
switch response.result {
case .success(let value):
Expand All @@ -36,11 +36,11 @@ struct CertificateRow: View {
}

func makeQuestions(topic: String, num_questions: Int) {
self.quizInfo.title = topic
self.loading = true
NetworkManager.createTopicQuestion(topic: topic, num_questions: 3) { questions, success, error in
if (success) {
self.loading = false
self.quizInfo.title = topic
DispatchQueue.main.async {
self.questionListWrapper = QuestionListWrapper(questions: questions ?? [])
}
Expand Down Expand Up @@ -80,7 +80,7 @@ struct CertificateRow: View {
.padding(.leading, 10)
}
}
.sheet(isPresented: $loading) { Text("Loading...") }
.sheet(isPresented: $loading) { LoadingView() }
.onAppear {
self.getTopics()
}
Expand Down
1 change: 1 addition & 0 deletions trivai/main/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct CertificateView: View {
Text(item)
.font(.system(size: 25))
.fontWeight(.bold)
.textCase(.uppercase)
.foregroundColor(Color.white)
.padding()
.offset(y: -5)//, alignment: .topLeading)
Expand Down
10 changes: 5 additions & 5 deletions trivai/main/HomeList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ let coursesData = [
Course(title: "Create a Quiz",
image: "newQuiz",
color: Color("background4"),
shadowColor: Color("backgroundShadow4")),
Course(title: "Scan page",
image: "myCamera",
color: Color("background7"),
shadowColor: Color(hue: 0.677, saturation: 0.701, brightness: 0.788, opacity: 0.5)),
shadowColor: Color("backgroundShadow4"))
// Course(title: "Scan page",
// image: "myCamera",
// color: Color("background7"),
// shadowColor: Color(hue: 0.677, saturation: 0.701, brightness: 0.788, opacity: 0.5)),
]
42 changes: 42 additions & 0 deletions trivai/main/LoadingView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// LoadingView.swift
// trivai
//
// Created by Mason Bulling on 4/2/23.
// Copyright © 2023 Mithun. All rights reserved.
//

import Foundation
import SwiftUI

struct LoadingView: View {
@State private var isAnimating = false

var body: some View {
ZStack {
Circle()
.stroke(Color.gray, lineWidth: 8)
.frame(width: 100, height: 100)

Circle()
.trim(from: 0, to: 0.8)
.stroke(Color("background3"), lineWidth: 8)
.frame(width: 100, height: 100)
.rotationEffect(.degrees(isAnimating ? 360 : 0))
.animation(Animation.linear(duration: 1).repeatForever(autoreverses: false))
}
.onAppear {
self.isAnimating = true
}
}
}


struct LoadingView_Preview: View {
var body: some View {
VStack {
LoadingView()
}
}
}

2 changes: 1 addition & 1 deletion trivai/main/TopicList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct TopicList: View {
@State private var questionListWrapper: QuestionListWrapper? = nil

func getTopics() {
AF.request("http://192.168.4.43:3000/topics").responseJSON { response in
AF.request("http://127.0.0.1:5000/topics").responseJSON { response in
print(response.result)
switch response.result {
case .success(let value):
Expand Down
3 changes: 1 addition & 2 deletions trivai/quiz/CustomButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// CustomButton.swift
// TrivAI
//
// Created by Ryan Ho on 02/24/2023.
// Created by Mason Bulling on 04/02/2023.
//

import SwiftUI

// MARK: Reusable Custom Button (Ignores Safe Area)
struct CustomButton: View{
var title: String
var onClick: ()->()
Expand Down
1 change: 1 addition & 0 deletions trivai/quiz/Load.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct Load: View {
VStack {
Text(info.title)
//.font(.title)
.textCase(.uppercase)
.fontWeight(.semibold)
.scaledToFill()
.font(.system(size: 42))
Expand Down
1 change: 1 addition & 0 deletions trivai/quiz/QuestionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct QuestionsView: View {

Text(info.title)
.font(.title)
.textCase(.uppercase)
.fontWeight(.semibold)
.hAlign(.leading)
.foregroundColor(Color.white)
Expand Down

0 comments on commit e009d28

Please sign in to comment.