Mixonomer-iOS/Mixonomer/Views/AppSkeleton.swift

83 lines
2.1 KiB
Swift
Raw Normal View History

2020-02-16 18:47:09 +00:00
//
// AppSkeleton.swift
2022-08-07 13:31:15 +01:00
// Mixonomer
2020-02-16 18:47:09 +00:00
//
// Created by Andy Pack on 16/02/2020.
// Copyright © 2020 Sarsoo. All rights reserved.
//
import SwiftUI
import Alamofire
import SwiftyJSON
2020-02-16 18:47:09 +00:00
struct AppSkeleton: View {
@EnvironmentObject var liveUser: LiveUser
@State private var selection = 0 // Tab view selection
2020-02-16 18:47:09 +00:00
var body: some View {
TabView {
PlaylistList()
.tabItem {
VStack {
Image(systemName: "music.note.list")
Text("Playlists")
}
}
.tag(0)
2022-08-14 13:14:21 +01:00
if liveUser.lastfm_connected() {
TagList()
.tabItem {
VStack {
Image(systemName: "tag")
Text("Tags")
}
2022-08-14 13:14:21 +01:00
}
.tag(1)
}
if let user = liveUser.user {
if user.type == .admin {
AdminList()
.tabItem( {
VStack {
Image(systemName: "person.badge.key.fill")
Text("Admin")
}
})
.tag(2)
2020-02-16 18:47:09 +00:00
}
}
SettingsList()
.tabItem {
VStack {
Image(systemName: "slider.horizontal.3")
Text("Settings")
}
}
.tag(3)
}.onAppear {
self.fetchAll()
2020-02-16 18:47:09 +00:00
}
}
private func fetchAll() {
self.liveUser.refresh_user()
self.liveUser.refresh_playlists()
self.liveUser.refresh_tags()
}
2020-02-16 18:47:09 +00:00
}
struct RootView_Previews: PreviewProvider {
2020-02-16 18:47:09 +00:00
static var previews: some View {
AppSkeleton()
.environmentObject(LiveUser(playlists: [], tags: [], username: "user", loggedIn: false))
2020-02-16 18:47:09 +00:00
}
}