summaryrefslogtreecommitdiff
path: root/Xmission/Code/Home/Screens/HomeScreen.swift
blob: dac8a207d79943e025dfcc23698ac52ac5a24b68 (plain) (blame)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import SwiftUI

struct HomeScreen: View {
    @ObservedObject var viewModel: HomeViewModel = .init()

    var body: some View {
        NavigationView {
            List {
                ForEach(viewModel.torrents, id: \.name) { torrent in
                    TorrentRow(torrent: torrent)
                        .swipeActions(edge: .trailing) {
                            Button {} label: {
                                Label("Delete", systemImage: "trash")
                            }
                            .tint(.red)
                        }
                        .listRowSeparator(.hidden)
                }
            }
            .listStyle(.plain)

            .navigationBarTitle(Text("192.168.0.2"), displayMode: .inline)
            .navigationBarItems(
                leading: Button(
                    action: { print("Adding torrent") },
                    label: { Image(systemName: "plus") }
                ),
                trailing:
                Button(
                    action: { print("Going to Settings") },
                    label: { Image(systemName: "gear") }
                )
            )
        }
    }
}

struct TorrentRow: View {
    let torrent: Torrent

    var body: some View {
        HStack {
            ProgressView(
                value: torrent.completionPercent,
                total: 100,
                label: {
                    VStack {
                        Text(torrent.name)
                        HStack {
                            // todo chips
                        }
                    }
                },
                currentValueLabel: {
                    HStack {
                        Text("Ratio: " + String(torrent.ratio)).frame(
                            maxWidth: .infinity,
                            maxHeight: .infinity,
                            alignment: .leading
                        )

                        Text(String(torrent.completionPercent) + "%").frame(
                            maxWidth: .infinity,
                            maxHeight: .infinity,
                            alignment: .center
                        )

                        HStack {
                            Image(systemName: "chevron.up", variableValue: 100)
                            Text(String(torrent.rateUpload))
                            Image(systemName: "chevron.down")
                            Text(String(torrent.rateDownload))
                        }.frame(
                            maxWidth: .infinity,
                            maxHeight: .infinity,
                            alignment: .trailing
                        )
                    }
                }
            )
        }
    }
}

struct HomeScreen_Previews: PreviewProvider {
    static var previews: some View {
        HomeScreen()
    }
}