|
@@ -11,61 +11,24 @@ struct RoomsListView: View {
|
|
|
@Environment(\.colorScheme) var colorScheme
|
|
|
|
|
|
@StateObject var viewModel: RoomsListViewModel = RoomsListViewModel()
|
|
|
+
|
|
|
var body: some View {
|
|
|
Group {
|
|
|
- if viewModel.rooms.isEmpty {
|
|
|
- ProgressView()
|
|
|
- } else {
|
|
|
- List {
|
|
|
- ForEach(viewModel.rooms.indices, id: \.self) { index in
|
|
|
- ZStack {
|
|
|
- HStack {
|
|
|
- Image(systemName: "person.crop.circle")
|
|
|
- .resizable()
|
|
|
- .scaledToFit()
|
|
|
- .foregroundColor(.secondary.opacity(0.5))
|
|
|
- .padding(.vertical, 8)
|
|
|
- VStack(alignment: .leading, spacing: 0) {
|
|
|
- HStack {
|
|
|
- Text(viewModel.rooms[index].name)
|
|
|
- Spacer()
|
|
|
- Text("23:04")
|
|
|
- .font(.callout)
|
|
|
- .foregroundColor(.secondary)
|
|
|
- }
|
|
|
- .padding(.vertical, 4)
|
|
|
- HStack {
|
|
|
- VStack {
|
|
|
- Text("Сообщение \(index)")
|
|
|
- .foregroundColor(.secondary)
|
|
|
- Spacer()
|
|
|
- }
|
|
|
- Spacer()
|
|
|
- Text("\(index)")
|
|
|
- .font(.callout)
|
|
|
- .foregroundColor(colorScheme == .light ? .white : .black)
|
|
|
- .padding(.horizontal, 6)
|
|
|
- .background(
|
|
|
- Capsule().foregroundColor(.secondary)
|
|
|
- )
|
|
|
- }
|
|
|
- .padding(.vertical, 6)
|
|
|
- }
|
|
|
- }
|
|
|
- .foregroundColor(.primary)
|
|
|
- .frame(height: 60)
|
|
|
- NavigationLink {
|
|
|
- ChatView(viewModel: ChatViewModel(with: viewModel.rooms[index].jidString))
|
|
|
- } label: {
|
|
|
- EmptyView()
|
|
|
- }
|
|
|
- .opacity(0.0)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- .listStyle(.plain)
|
|
|
- }
|
|
|
- }
|
|
|
+ if viewModel.rooms.isEmpty {
|
|
|
+ ProgressView()
|
|
|
+ } else {
|
|
|
+ List(viewModel.rooms.indices, id: \.self) { index in
|
|
|
+ RoomsListCellView(
|
|
|
+ roomID: viewModel.rooms[index].jidString,
|
|
|
+ title: viewModel.rooms[index].name,
|
|
|
+ lastMessage: "Сообщение \(index)",
|
|
|
+ lastMessageTime: "14:\(Int.random(in: 10...50))",
|
|
|
+ unreadMessagesCount: Int.random(in: 1...100)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ .listStyle(.plain)
|
|
|
+ }
|
|
|
+ }
|
|
|
.onAppear {
|
|
|
viewModel.fetchRooms()
|
|
|
}
|
|
@@ -75,15 +38,21 @@ struct RoomsListView: View {
|
|
|
|
|
|
struct RoomsListView_Previews: PreviewProvider {
|
|
|
static var viewModel: RoomsListViewModel = RoomsListViewModel()
|
|
|
+
|
|
|
static var previews: some View {
|
|
|
- Group {
|
|
|
- NavigationView {
|
|
|
- RoomsListView(viewModel: viewModel)
|
|
|
- }
|
|
|
- NavigationView {
|
|
|
- RoomsListView(viewModel: viewModel)
|
|
|
- }
|
|
|
- .preferredColorScheme(.dark)
|
|
|
- }
|
|
|
+ NavigationView {
|
|
|
+ RoomsListView(viewModel: viewModel)
|
|
|
+ .onAppear {
|
|
|
+ viewModel.rooms = [
|
|
|
+ .init(jidString: "Jid", name: "Room title 1"),
|
|
|
+ .init(jidString: "Jid", name: "Room title 2"),
|
|
|
+ .init(jidString: "Jid", name: "Room title 3"),
|
|
|
+ .init(jidString: "Jid", name: "Room title 4"),
|
|
|
+ .init(jidString: "Jid", name: "Room title 5"),
|
|
|
+ .init(jidString: "Jid", name: "Room title 6"),
|
|
|
+ .init(jidString: "Jid", name: "Room title 7")
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|