Skip to content

Commit

Permalink
feat(scrobbles): add nice logged out view
Browse files Browse the repository at this point in the history
  • Loading branch information
angristan committed Jul 23, 2021
1 parent 9836e23 commit 43b5869
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 20 deletions.
4 changes: 4 additions & 0 deletions firstfm.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
82A006C3267973D30009BD71 /* SampleArtist.json in Resources */ = {isa = PBXBuildFile; fileRef = 82A006C2267973D30009BD71 /* SampleArtist.json */; };
82A006C526797C3E0009BD71 /* SearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82A006C426797C3E0009BD71 /* SearchView.swift */; };
82B6CCDF26AB1795008AFDEF /* ProfileLoggedOutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82B6CCDE26AB1795008AFDEF /* ProfileLoggedOutView.swift */; };
82B6CCE126AB2832008AFDEF /* SrobblesLoggedOutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82B6CCE026AB2832008AFDEF /* SrobblesLoggedOutView.swift */; };
82BBD2462698B13B009B42FC /* Country.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82BBD2452698B13B009B42FC /* Country.swift */; };
82BBD2482698B37F009B42FC /* TrendsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82BBD2472698B37F009B42FC /* TrendsViewModel.swift */; };
82BBD24A2698C33D009B42FC /* TopCountryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82BBD2492698C33D009B42FC /* TopCountryView.swift */; };
Expand Down Expand Up @@ -155,6 +156,7 @@
82A006C2267973D30009BD71 /* SampleArtist.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = SampleArtist.json; sourceTree = "<group>"; };
82A006C426797C3E0009BD71 /* SearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchView.swift; sourceTree = "<group>"; };
82B6CCDE26AB1795008AFDEF /* ProfileLoggedOutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileLoggedOutView.swift; sourceTree = "<group>"; };
82B6CCE026AB2832008AFDEF /* SrobblesLoggedOutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SrobblesLoggedOutView.swift; sourceTree = "<group>"; };
82BBD2452698B13B009B42FC /* Country.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Country.swift; sourceTree = "<group>"; };
82BBD2472698B37F009B42FC /* TrendsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrendsViewModel.swift; sourceTree = "<group>"; };
82BBD2492698C33D009B42FC /* TopCountryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopCountryView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -331,6 +333,7 @@
children = (
82D5B4D52696E0E100716931 /* ScrobbledTrackRowView.swift */,
82D5B4CF2696DB8400716931 /* ScrobblesView.swift */,
82B6CCE026AB2832008AFDEF /* SrobblesLoggedOutView.swift */,
);
path = Scrobbles;
sourceTree = "<group>";
Expand Down Expand Up @@ -592,6 +595,7 @@
82C282E826A3332E000E5F41 /* FriendsResponse.swift in Sources */,
822E9A8C26A8CFAC00C5307B /* TrackView.swift in Sources */,
820455E0267ABC930009A418 /* AuthViewModel.swift in Sources */,
82B6CCE126AB2832008AFDEF /* SrobblesLoggedOutView.swift in Sources */,
825F0FC526A74539007BA84B /* TopArtistAlbumsView.swift in Sources */,
4A8C296126983B7300F55ECC /* LastFMAPI.swift in Sources */,
822E9A9626A97B7200C5307B /* TagViewModel.swift in Sources */,
Expand Down
45 changes: 25 additions & 20 deletions firstfm/Views/Scrobbles/ScrobblesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,43 @@ import SwiftUI
import SwiftUIRefresh

struct Scrobbles: View {
@EnvironmentObject var auth: AuthViewModel
@ObservedObject var vm = ScrobblesViewModel()
@State var scrobblesLoaded = false
@State private var isPullLoaderShowing = false

var body: some View {
NavigationView {
ZStack {
VStack {
List(vm.scrobbles) { track in
NavigationLink(
destination: TrackView(track: Track(name: track.name, playcount: "0", listeners: "", url: "", artist: nil, image: track.image)),
label: {
ScrobbledTrackRow(track: track)
})
}.navigationTitle("Your scrobbles").onAppear {
if !scrobblesLoaded {
if auth.isLoggedIn() {
ZStack {
VStack {
List(vm.scrobbles) { track in
NavigationLink(
destination: TrackView(track: Track(name: track.name, playcount: "0", listeners: "", url: "", artist: nil, image: track.image)),
label: {
ScrobbledTrackRow(track: track)
})
}.navigationTitle("Your scrobbles").onAppear {
if !scrobblesLoaded {
vm.getUserScrobbles()
// Prevent loading again when navigating
scrobblesLoaded = true
}
}
.pullToRefresh(isShowing: $isPullLoaderShowing) {
vm.getUserScrobbles()
// Prevent loading again when navigating
scrobblesLoaded = true
self.isPullLoaderShowing = false
}
}
.pullToRefresh(isShowing: $isPullLoaderShowing) {
vm.getUserScrobbles()
self.isPullLoaderShowing = false
// Show loader above the rest of the ZStack
if vm.isLoading {
ProgressView().scaleEffect(2)
}
}
// Show loader above the rest of the ZStack
if vm.isLoading {
ProgressView().scaleEffect(2)
}
}

} else {
SrobblesLoggedOutView()
}
}
}
}
56 changes: 56 additions & 0 deletions firstfm/Views/Scrobbles/SrobblesLoggedOutView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import SwiftUI

struct SrobblesLoggedOutView: View {
var body: some View {
GeometryReader { _ in
ZStack {
List {
ForEach((1...5), id: \.self) {_ in
NavigationLink(
destination: Color(.red),
label: {
ScrobbledTrackRow(track: ScrobbledTrack(
name: "toto",
url: "123",
image: [
LastFMImage(
url: "https://lastfm.freetls.fastly.net/i/u/64s/4128a6eb29f94943c9d206c08e625904.webp",
size: "lol"
),
LastFMImage(
url: "https://lastfm.freetls.fastly.net/i/u/64s/4128a6eb29f94943c9d206c08e625904.webp",
size: "lol"
),
LastFMImage(
url: "https://lastfm.freetls.fastly.net/i/u/64s/4128a6eb29f94943c9d206c08e625904.webp",
size: "lol"
),
LastFMImage(
url: "https://lastfm.freetls.fastly.net/i/u/64s/4128a6eb29f94943c9d206c08e625904.webp",
size: "lol"
)
],
artist: ScrobbledArtist(
mbid: "",
name: "Artist"
),
date: nil
))
})
}.navigationTitle("Your scrobbles")
.redacted(reason: .placeholder)
}
.offset(y: 30)
.overlay(TintOverlayView().opacity(0.2))
.blur(radius: 3)

LoginGuardView()
.offset(y: 200)
.tabItem {
Text("Profile")
Image(systemName: "person.crop.circle")
}
}
}
}
}

0 comments on commit 43b5869

Please sign in to comment.