Skip to content

Commit

Permalink
add underlined view menu
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMoonThatRises committed Dec 16, 2024
1 parent f0ef9ac commit e31ad19
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
56 changes: 56 additions & 0 deletions Spwifiy/Utils/ViewItems/UnderlinedViewMenu.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// UnderlinedViewMenu.swift
// Spwifiy
//
// Created by Peter Duanmu on 12/13/24.
//

import SwiftUI

struct UnderlinedViewMenu<Option: Equatable & RawRepresentable>: View where Option.RawValue: StringProtocol {

let types: [Option]

@Binding var currentOption: Option

var body: some View {
HStack {
ForEach(types, id: \.rawValue) { type in
VStack {
Button {
withAnimation(.defaultAnimation) {
currentOption = type
}
} label: {
Text(type.rawValue)
.foregroundStyle(.fgSecondary)
.padding(7)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.cursorHover(.pointingHand)

if currentOption == type {
RoundedRectangle(cornerRadius: 5)
.foregroundStyle(.sPrimary)
.frame(height: 3)
}

Spacer()
}
.fixedSize(horizontal: true, vertical: false)

if type != types.last {
Spacer()
.frame(width: 25)
}
}

Spacer()
}
.frame(maxWidth: .infinity, maxHeight: 50)
.padding()
.font(.satoshiBlack(12))
}

}
25 changes: 23 additions & 2 deletions Spwifiy/Views/MainViewOptions/ArtistView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ import SpotifyWebAPI

struct ArtistView: View {

enum CurrentView: String, CaseIterable {
case homeView = "Home"
case albumView = "Albums"
case singlesEpView = "Singles and EPs"
case merchView = "Merch"
case aboutView = "About"
}

@StateObject var artistViewModel: ArtistViewModel

@State var currentView: CurrentView = .homeView

init(spotifyCache: SpotifyCache, artist: Artist) {
self._artistViewModel = StateObject(
wrappedValue: ArtistViewModel(spotifyCache: spotifyCache, artist: artist)
Expand All @@ -28,7 +38,8 @@ struct ArtistView: View {

VStack {
HStack {
Text("Home")
UnderlinedViewMenu(types: CurrentView.allCases,
currentOption: $currentView)

ExpandSearch(searchText: $artistViewModel.searchText)

Expand All @@ -37,7 +48,17 @@ struct ArtistView: View {
.font(.title3)
.padding(5)

Divider()
Group {
switch currentView {
// case .homeView:
// case .albumView:
// case .singlesEpView:
// case .merchView:
// case .aboutView:
default:
Text("Unknown error")
}
}

Rectangle()
.frame(height: 600)
Expand Down

0 comments on commit e31ad19

Please sign in to comment.