From a97a17eea6465e6914bb2007a4ec759a7983dc5a Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 15 Aug 2022 19:24:56 +0100 Subject: [PATCH] adding last spotify refresh, locked to user object --- Mixonomer/Model/User.swift | 35 ++++++++++++++++----- Mixonomer/Views/Admin/UserView.swift | 9 +++++- Mixonomer/Views/Playlist/PlaylistList.swift | 2 +- Mixonomer/Views/Playlist/PlaylistView.swift | 2 +- Mixonomer/Views/Settings/SettingsList.swift | 16 ++++++++++ 5 files changed, 54 insertions(+), 10 deletions(-) diff --git a/Mixonomer/Model/User.swift b/Mixonomer/Model/User.swift index 2fe6b41..6012739 100644 --- a/Mixonomer/Model/User.swift +++ b/Mixonomer/Model/User.swift @@ -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) diff --git a/Mixonomer/Views/Admin/UserView.swift b/Mixonomer/Views/Admin/UserView.swift index e4d9419..3ce5574 100644 --- a/Mixonomer/Views/Admin/UserView.swift +++ b/Mixonomer/Views/Admin/UserView.swift @@ -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())) } } diff --git a/Mixonomer/Views/Playlist/PlaylistList.swift b/Mixonomer/Views/Playlist/PlaylistList.swift index bc00fcf..ed5e08c 100644 --- a/Mixonomer/Views/Playlist/PlaylistList.swift +++ b/Mixonomer/Views/Playlist/PlaylistList.swift @@ -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())) } } } diff --git a/Mixonomer/Views/Playlist/PlaylistView.swift b/Mixonomer/Views/Playlist/PlaylistView.swift index 49672a4..ec63821 100644 --- a/Mixonomer/Views/Playlist/PlaylistView.swift +++ b/Mixonomer/Views/Playlist/PlaylistView.swift @@ -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())) } } diff --git a/Mixonomer/Views/Settings/SettingsList.swift b/Mixonomer/Views/Settings/SettingsList.swift index 1209ab0..da80962 100644 --- a/Mixonomer/Views/Settings/SettingsList.swift +++ b/Mixonomer/Views/Settings/SettingsList.swift @@ -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