adding last spotify refresh, locked to user object

This commit is contained in:
andy 2022-08-15 19:24:56 +01:00
parent 589ca39555
commit a97a17eea6
5 changed files with 54 additions and 10 deletions

View File

@ -22,29 +22,38 @@ class User: Identifiable, Decodable {
var email: String?
var type: UserType
var locked: Bool
var last_login: String
var last_keygen: String
var last_refreshed: String
var spotify_linked: Bool
@Published var lastfm_username: String?
//MARK: Initialization
init(username: String,
email: String?,
init(username: String = "user",
email: String? = nil,
type: UserType = .user,
last_login: String,
last_keygen: String,
spotify_linked: Bool,
lastfm_username: String?){
locked: Bool = false,
last_login: String = "",
last_keygen: String = "",
last_refreshed: String = "",
spotify_linked: Bool = true,
lastfm_username: String? = nil){
self.username = username
self.email = email
self.type = type
self.locked = locked
self.last_login = last_login
self.last_keygen = last_keygen
self.last_refreshed = last_refreshed
self.spotify_linked = spotify_linked
self.lastfm_username = lastfm_username
}
@ -54,8 +63,11 @@ class User: Identifiable, Decodable {
case email
case type
case locked
case last_login
case last_keygen
case last_refreshed
case spotify_linked
case lastfm_username
@ -72,6 +84,7 @@ class User: Identifiable, Decodable {
}
type = try container.decode(UserType.self, forKey: .type)
locked = try container.decode(Bool.self, forKey: .locked)
last_login = try container.decode(String.self, forKey: .last_login)
do{
@ -79,6 +92,11 @@ class User: Identifiable, Decodable {
}catch {
last_keygen = ""
}
do{
last_refreshed = try container.decode(String.self, forKey: .last_refreshed)
}catch {
last_refreshed = ""
}
spotify_linked = try container.decode(Bool.self, forKey: .spotify_linked)
do{
@ -95,8 +113,11 @@ class User: Identifiable, Decodable {
try container.encode(self.email, forKey: .email)
try container.encode(self.type.rawValue, forKey: .type)
try container.encode(self.locked, forKey: .locked)
try container.encode(self.last_login, forKey: .last_login)
try container.encode(self.last_keygen, forKey: .last_keygen)
try container.encode(self.last_refreshed, forKey: .last_refreshed)
try container.encode(self.spotify_linked, forKey: .spotify_linked)
try container.encode(self.lastfm_username, forKey: .lastfm_username)

View File

@ -55,6 +55,13 @@ struct UserView: View {
Text(user.last_keygen)
.foregroundColor(.gray)
}
HStack {
Text("Last Spotify Refresh")
Spacer()
Text(user.last_refreshed)
.foregroundColor(.gray)
}
}
}
.navigationBarTitle(Text(user.username))
@ -63,6 +70,6 @@ struct UserView: View {
struct UserView_Previews: PreviewProvider {
static var previews: some View {
UserView(user: .constant(User(username: "", email: "", last_login: "", last_keygen: "", spotify_linked: true, lastfm_username: nil)))
UserView(user: .constant(User()))
}
}

View File

@ -103,7 +103,7 @@ struct PlaylistList_Previews: PreviewProvider {
PlaylistList()
.environmentObject(LiveUser(playlists: [], tags: [], username: "user", loggedIn: false))
PlaylistList()
.environmentObject(LiveUser(playlists: [], tags: [], username: "user", loggedIn: false, user: User(username: "user", email: nil, last_login: "", last_keygen: "", spotify_linked: false, lastfm_username: nil)))
.environmentObject(LiveUser(playlists: [], tags: [], username: "user", loggedIn: false, user: User()))
}
}
}

View File

@ -347,7 +347,7 @@ struct PlaylistView_Previews: PreviewProvider {
lastfm_stat_artist_percent: 80
)
))
.environmentObject(LiveUser(playlists: [], tags: [], username: "user", loggedIn: false, user: User(username: "", email: "", last_login: "", last_keygen: "", spotify_linked: true, lastfm_username: "last.fm")))
.environmentObject(LiveUser(playlists: [], tags: [], username: "user", loggedIn: false, user: User()))
}
}

View File

@ -39,6 +39,22 @@ struct SettingsList: View {
Text("Log out")
}
}
Section(header: Text("Config")) {
if let spotify_linked = self.liveUser.user?.spotify_linked {
Toggle(isOn: .constant(spotify_linked)) {
Text("Spotify Link")
}
.disabled(true)
}
// HStack {
// Text("Last.fm Username")
// Spacer()
//
// Text(self.$liveUser.user.lastfm_username ?? .constant(""))
// }
}
Section {
Button(action: {
deleteAlertShowing = true