aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Views/ServerView.swift
blob: 221156a1d346f5e31640d89a33d40053373a9305 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import SwiftUI

struct ServerView: View {
  @Environment(HotlineClient.self) private var hotline
  @Environment(\.colorScheme) var colorScheme
  
  func connectionStatusTitle(status: HotlineClientStatus) -> String {
    switch(status) {
    case .disconnected:
      return "Disconnected"
    case .connecting:
      return "Connecting"
    case .connected:
      return "Connected"
    case .loggingIn:
      return "Logging In"
    case .loggedIn:
      return "Logged In"
    }
  }
  
  func connectionProgress(status: HotlineClientStatus) -> Double {
    return Double(status.rawValue) / Double(HotlineClientStatus.loggedIn.rawValue)
  }
  
  enum Tab {
    case chat, users, news, messageBoard, files
  }
  
  var body: some View {
    TabView {
      ChatView()
        .tabItem {
          Image(systemName: "bubble")
        }
        .tag(Tab.chat)
      
      UserListView()
        .tabItem {
          Image(systemName: "person.2")
        }
        .tag(Tab.users)
      
      NewsView()
        .tabItem {
          Image(systemName: "newspaper")
        }
        .tag(Tab.news)
      
      MessageBoardView()
        .tabItem {
          Image(systemName: "book.closed")
        }
        .tag(Tab.messageBoard)
      
      FilesView()
        .tabItem {
          Image(systemName: "folder").tint(.black)
        }
        .tag(Tab.files)
    }
    .accentColor(colorScheme == .dark ? .white : .black)
  }
}

#Preview {
  ServerView()
    .environment(HotlineClient())
}