Skip to content

Commit

Permalink
Cleanup Graph Popup
Browse files Browse the repository at this point in the history
  • Loading branch information
Peyton-McKee committed Dec 21, 2023
1 parent eefbad0 commit 1bd00a8
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 38 deletions.
58 changes: 35 additions & 23 deletions ArgosIOS/Argos/Components/Carousel/CarouselView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,50 @@ struct CarouselView: View {
@State private var selectedIndex: Int = 0
@Binding var isPresented: Bool



var body: some View {
ZStack {
TabView(selection: self.$selectedIndex) {
ForEach(0..<runs.count, id: \.self) { index in
ZStack(alignment: .topLeading) {
CarouselContent(run: self.runs[index], selectRun: {
selectRun(self.runs[index])
})
}
.shadow(radius: 20)
if self.runs.count == 0 {
VStack {
ArgosHeader("No Runs Found")
ArgosButton(title: "Close", action: {
withAnimation {
self.isPresented.toggle()
}
})
}
}
.frame(height: 300)
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.ignoresSafeArea()

HStack {
ForEach(0..<runs.count, id: \.self) { index in
Capsule()
.fill(.foreground.opacity(self.selectedIndex == index ? 1 : 0.33))
.frame(width: 35, height: 8)
.onTapGesture {
self.selectedIndex = index
.padding()

} else {
TabView(selection: self.$selectedIndex) {
ForEach(0..<runs.count, id: \.self) { index in
ZStack(alignment: .topLeading) {
CarouselContent(run: self.runs[index], selectRun: {
selectRun(self.runs[index])
})
}
.shadow(radius: 20)
}
}
.frame(height: 300)
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.ignoresSafeArea()

HStack {
ForEach(0..<runs.count, id: \.self) { index in
Capsule()
.fill(.foreground.opacity(self.selectedIndex == index ? 1 : 0.33))
.frame(width: 35, height: 8)
.onTapGesture {
self.selectedIndex = index
}
}
.offset(y: 130)
}
.offset(y: 130)
}
}
.background(Color(.systemBackground))
.clipShape(.buttonBorder)

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct HorizontalExpandingScrollView : View {
}
}
}
.background(Color(.systemGroupedBackground))
.background(Color(.systemBackground))
.onAppear {
print("HOriz")
}
Expand Down
26 changes: 22 additions & 4 deletions ArgosIOS/Argos/Singletons/SocketClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ class SocketClient: ObservableObject {
static let shared = SocketClient(manager: SocketManager(socketURL: URL(string: "http://localhost:8000")!, config: [.log(true), .compress]))
private let socket: SocketIOClient
private let manager: SocketManager


@Published public private(set) var isConnected = false
@Published public private(set) var runId: Int? = nil
@Published public private(set) var values = [String: DataValue]()

private init(manager: SocketManager) {
self.manager = manager
self.socket = manager.defaultSocket
self.receiveMessage()
self.handleConnection()
self.handleDisconnection()
}

public func connect() {
socket.connect(timeoutAfter: 10, withHandler: {
self.socket.connect(timeoutAfter: 10, withHandler: {
print("Could Not connect to Server")
})
}

public func receiveMessage() {
socket.on("message", callback: {
private func receiveMessage() {
self.socket.on("message", callback: {
data, _ in
do {
let decoder = JSONDecoder()
Expand All @@ -45,4 +49,18 @@ class SocketClient: ObservableObject {
}
})
}

private func handleConnection() {
self.socket.on(clientEvent: .connect, callback: {
_, _ in
self.isConnected = true
})
}

private func handleDisconnection() {
self.socket.on(clientEvent: .disconnect, callback: {
_, _ in
self.isConnected = false
})
}
}
8 changes: 6 additions & 2 deletions ArgosIOS/Argos/Views/Graph/GraphContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ struct GraphContainer: View {
var body: some View {
VStack {
GraphView(data: self.$currentData).frame(maxHeight: .infinity)
GraphCaption(dataType: self.$selectedDataType, mostRecentvalue: self.$currentData.last?.value, driver: self.$driver, location: self.$location, system: self.$system)
GraphSelectionPopUp(selectDataType: self.setSelectedDataType)
ZStack {
GraphCaption(dataType: self.$selectedDataType, mostRecentvalue: self.$currentData.last?.value, driver: self.$driver, location: self.$location, system: self.$system)
}
.overlay(GraphSelectionPopUp(selectDataType: self.setSelectedDataType)
.frame(maxWidth: .infinity, alignment: .bottomLeading),
alignment: .bottom)
}
.onAppear {
APIHandler.shared.getRunById(id: runId, completion: {
Expand Down
20 changes: 14 additions & 6 deletions ArgosIOS/Argos/Views/Graph/GraphSelectionPopUp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@ struct GraphSelectionPopUp : View {
var selectDataType : (_ dataType: DataType) -> Void

var body: some View {
VStack {
ArgosLabel("Select Data Type")
.onTapGesture {
self.present()
}
VStack (spacing: 0) {
HStack {
ArgosLabel("Select Data Type")
.onTapGesture {
self.present()
}
.background(Color(.systemBackground))
.clipShape(.buttonBorder)
}
.frame(maxWidth: .infinity, alignment: .leading)
if (self.isPresented) {
HorizontalExpandingScrollView(items: self.nodes.map({
ScrollViewItem(name: $0.name, subItems: $0.dataTypes.map({
dataType in
ScrollViewSubItem(name: dataType.name, onSelect: {
self.selectDataType(dataType)
withAnimation {
self.selectDataType(dataType)
self.isPresented.toggle()
}
})
}))
}))
Expand Down
12 changes: 10 additions & 2 deletions ArgosIOS/Argos/Views/LandingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import SwiftUI

struct LandingView: View {
@EnvironmentObject private var errorHandling: ErrorHandling
@ObservedObject private var socketClient = SocketClient.shared

@State private var showMain = false
@State private var stateOfCharge: Double = 0
@State private var packTemp: Float = 0
Expand All @@ -25,6 +27,13 @@ struct LandingView: View {
NavigationStack {
if self.showMain {
VStack {
if self.socketClient.isConnected {
ArgosHeader("Connected To Router")
.multilineTextAlignment(.center)
} else {
ArgosHeader("Not Connected To Router")
.multilineTextAlignment(.center)
}
BatteryView(progress: .constant(self.stateOfCharge), fill: .green, outline: .secondary, direction: .horizontal)
HStack {
ThermometerView(current: self.packTemp, minimum: -15, maximum: 60, label: "Pack").frame(maxWidth: .infinity)
Expand Down Expand Up @@ -75,8 +84,7 @@ struct LandingView: View {
}
})

SocketClient.shared.receiveMessage()
SocketClient.shared.connect()
self.socketClient.connect()

DispatchQueue.main.asyncAfter(deadline: DispatchTime.now().advanced(by: .seconds(2)), execute: {
withAnimation {
Expand Down

0 comments on commit 1bd00a8

Please sign in to comment.