Skip to content

Commit

Permalink
Merge pull request #133 from makinosp/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
makinosp authored Sep 21, 2024
2 parents f75e2f0 + 6c5075e commit 52c4700
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 68 deletions.
29 changes: 29 additions & 0 deletions harmonie/Models/SegmentModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// SegmentModel.swift
// Harmonie
//
// Created by makinosp on 2024/09/21.
//

enum Segment {
case friend, world
}

extension Segment: Identifiable {
var id: Int { hashValue }
}

extension Segment: CaseIterable {
var allCases: [Segment] {
[.friend, .world]
}
}

extension Segment: CustomStringConvertible {
var description: String {
switch self {
case .friend: "Friend"
case .world: "World"
}
}
}
33 changes: 33 additions & 0 deletions harmonie/Models/SelectionModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// SelectionModel.swift
// Harmonie
//
// Created by makinosp on 2024/07/28.
//

struct Selected: Hashable, Identifiable, Sendable {
let id: String
}

struct SegmentIdSelection: Hashable, Sendable {
let selected: Selected
let segment: Segment
}

extension SegmentIdSelection: Identifiable {
var id: Int { hashValue }
}

extension SegmentIdSelection {
init(friendId: String) {
selected = Selected(id: friendId)
segment = .friend
}
}

extension SegmentIdSelection {
init(worldId: String) {
selected = Selected(id: worldId)
segment = .world
}
}
10 changes: 0 additions & 10 deletions harmonie/Utils/Selected.swift

This file was deleted.

23 changes: 0 additions & 23 deletions harmonie/ViewModels/FavoriteViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ final class FavoriteViewModel {
var favoriteWorlds: [World] = []
var segment: Segment = .friend

enum Segment {
case friend, world
}

/// A filtered list of favorite groups that contain only friend-type groups.
/// It retrieves friend-type groups from the `favoriteGroups` property.
var favoriteFriendGroups: [FavoriteGroup] {
Expand Down Expand Up @@ -126,22 +122,3 @@ final class FavoriteViewModel {
favoriteWorlds = try await service.fetchFavoritedWorlds()
}
}

extension FavoriteViewModel.Segment: Identifiable {
var id: Int { hashValue }
}

extension FavoriteViewModel.Segment: CaseIterable {
var allCases: [FavoriteViewModel.Segment] {
[.friend, .world]
}
}

extension FavoriteViewModel.Segment: CustomStringConvertible {
var description: String {
switch self {
case .friend: "Friend"
case .world: "World"
}
}
}
2 changes: 1 addition & 1 deletion harmonie/Views/Favorite/FavoritesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct FavoritesView: View {
ToolbarItem(placement: .status) {
@Bindable var favoriteVM = favoriteVM
Picker("", selection: $favoriteVM.segment) {
ForEach(FavoriteViewModel.Segment.allCases) { segment in
ForEach(Segment.allCases) { segment in
Text(segment.description).tag(segment)
}
}
Expand Down
8 changes: 6 additions & 2 deletions harmonie/Views/Location/LocationCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ struct LocationCardView: View, InstanceServicePresentable {
}
}
.onTapGesture {
selected = InstanceLocation(location: location, instance: instance)
selected = tag(instance)
}
}
}
.tag(InstanceLocation(location: location, instance: instance))
.tag(tag(instance))
}

private func tag(_ instance: Instance) -> InstanceLocation {
InstanceLocation(location: location, instance: instance)
}

private func personAmount(_ instance: Instance) -> String {
Expand Down
34 changes: 23 additions & 11 deletions harmonie/Views/Location/LocationDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,37 @@ import NukeUI
import VRCKit

struct LocationDetailView: View {
@Binding var selectedUser: Selected?
@Binding var selection: SegmentIdSelection?
private let instance: Instance
private let location: FriendsLocation

init(instanceLocation: InstanceLocation, selectedUser: Binding<Selected?>) {
init(instanceLocation: InstanceLocation, selection: Binding<SegmentIdSelection?>) {
instance = instanceLocation.instance
location = instanceLocation.location
_selectedUser = selectedUser
_selection = selection
}

var body: some View {
List(selection: $selectedUser) {
List(selection: $selection) {
Section("World") {
GradientOverlayImageView(
imageUrl: instance.world.imageUrl(.x1024),
thumbnailImageUrl: instance.world.imageUrl(.x256),
height: 80
) { bottomBar }
.listRowInsets(EdgeInsets())
HStack(spacing: 12) {
SquareURLImage(
imageUrl: instance.world.imageUrl(.x1024),
thumbnailImageUrl: instance.world.imageUrl(.x256)
)
VStack(alignment: .leading) {
Text(instance.world.name)
.font(.body)
.lineLimit(1)
Text(instance.world.description ?? "")
.font(.footnote)
.foregroundStyle(Color.gray)
.lineLimit(2)
}
.frame(maxWidth: .infinity, alignment: .leading)
Constants.Icon.forward
}
.tag(SegmentIdSelection(worldId: instance.world.id))
}
Section("Friends") {
friendList
Expand Down Expand Up @@ -95,7 +107,7 @@ struct LocationDetailView: View {
} icon: {
UserIcon(user: friend, size: Constants.IconSize.thumbnail)
}
.tag(Selected(id: friend.id))
.tag(SegmentIdSelection(friendId: friend.id))
}
}
}
61 changes: 41 additions & 20 deletions harmonie/Views/Location/LocationsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,48 @@ import VRCKit
struct LocationsView: View, FriendServicePresentable, InstanceServicePresentable {
@Environment(AppViewModel.self) var appVM: AppViewModel
@Environment(FriendViewModel.self) var friendVM: FriendViewModel
@State private var columnVisibility: NavigationSplitViewVisibility = .all
@State private var selectedInstance: InstanceLocation?
@State private var selectedUser: Selected?
@State private var selection: SegmentIdSelection?

var body: some View {
NavigationSplitView(columnVisibility: .constant(.all)) {
NavigationSplitView(columnVisibility: $columnVisibility) {
locationList
.navigationTitle("Locations")
.navigationSplitViewColumnWidth(
min: 300,
ideal: WindowUtil.width / 2,
max: WindowUtil.width / 2
)
.setColumn()
} content: {
if let selectedInstance = selectedInstance {
LocationDetailView(
instanceLocation: selectedInstance,
selectedUser: $selectedUser
)
} else {
ContentUnavailableView {
Label {
Text("Select a location")
} icon: {
Constants.Icon.location
Group {
if let selectedInstance = selectedInstance {
LocationDetailView(
instanceLocation: selectedInstance,
selection: $selection
)
} else {
ContentUnavailableView {
Label {
Text("Select a location")
} icon: {
Constants.Icon.location
}
}
}
}
.setColumn()
} detail: {
if let selectedUser = selectedUser {
UserDetailPresentationView(selected: selectedUser)
Group {
if let selection = selection {
Group {
switch selection.segment {
case .friend:
UserDetailPresentationView(selected: selection.selected)
case .world:
WorldDetailPresentationView(id: selection.selected.id)
}
}
.id(selection.selected.id)
}
}
.setColumn()
}
.navigationSplitViewStyle(.balanced)
.refreshable {
Expand Down Expand Up @@ -77,3 +88,13 @@ struct LocationsView: View, FriendServicePresentable, InstanceServicePresentable
}
}
}

fileprivate extension View {
func setColumn() -> some View {
self.navigationSplitViewColumnWidth(
min: WindowUtil.width * 1 / 3,
ideal: WindowUtil.width * 1 / 3,
max: WindowUtil.width / 2
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension UserDetailView {
HStack {
Spacer()
Label {
Text(DateUtil.shared.formatRelative(from: user.lastActivity))
Text(lastActivity)
} icon: {
Image(systemName: "stopwatch")
}
Expand Down
4 changes: 4 additions & 0 deletions harmonie/Views/UserDetail/UserDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct UserDetailView: View, FavoriteServicePresentable, InstanceServicePresenta
@State var instance: Instance?
@State var note: String
@State var isRequesting = false
@State var lastActivity = ""

init(user: UserDetail) {
_user = State(initialValue: user)
Expand Down Expand Up @@ -47,6 +48,9 @@ struct UserDetailView: View, FavoriteServicePresentable, InstanceServicePresenta
await fetchInstance(id: id)
}
}
.task {
lastActivity = await DateUtil.shared.formatRelative(from: user.lastActivity)
}
}

private var contentStacks: some View {
Expand Down
2 changes: 2 additions & 0 deletions harmonie/Views/WorldDetail/WorldDetailPresentationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct WorldDetailPresentationView: View, WorldServicePresentable {
.task(id: id) {
await fetchWorld(id: id)
}
.navigationTitle("Loading...")
.navigationBarTitleDisplayMode(.inline)
}
}

Expand Down

0 comments on commit 52c4700

Please sign in to comment.