Skip to content

Commit

Permalink
Merge pull request #135 from makinosp/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
makinosp authored Sep 23, 2024
2 parents faecabf + 8336bcd commit 9e4714f
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Harmonie.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.7.2;
MARKETING_VERSION = 0.7.3;
PRODUCT_BUNDLE_IDENTIFIER = jp.mknn.harmonie;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -506,7 +506,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.7.2;
MARKETING_VERSION = 0.7.3;
PRODUCT_BUNDLE_IDENTIFIER = jp.mknn.harmonie;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"location" : "https://github.com/makinosp/vrckit",
"state" : {
"branch" : "develop",
"revision" : "3e8473947c3044297be4647d8230381c16921090"
"revision" : "bc261c16c86f2738501799f3c86d1d581f5f2cb9"
}
},
{
Expand Down
13 changes: 0 additions & 13 deletions harmonie/Models/FavoriteFriendModel.swift

This file was deleted.

22 changes: 22 additions & 0 deletions harmonie/Models/FavoriteModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// FavoriteModel.swift
// Harmonie
//
// Created by makinosp on 2024/09/16.
//

import VRCKit

struct FavoriteFriend: Sendable, Hashable {
let favoriteGroupId: String
var friends: [Friend]
}

struct FavoriteWorld: Sendable, Hashable {
let group: FavoriteGroup?
var worlds: [World]
}

extension FavoriteWorld: Identifiable {
var id: Int { hashValue }
}
21 changes: 20 additions & 1 deletion harmonie/ViewModels/FavoriteViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ final class FavoriteViewModel {
favoriteGroups.filter { $0.type == .friend }
}

func getFavoriteGroup(id: String) -> FavoriteGroup? {
favoriteGroups.first { $0.id == id }
}

func getFavoriteGroup(name: String) -> FavoriteGroup? {
favoriteGroups.first { $0.name == name }
}

/// Asynchronously fetches and updates the favorite groups and their details.
/// - Throws: An error if any network request or decoding operation fails.
func fetchFavorite(service: FavoriteServiceProtocol, friendVM: FriendViewModel) async throws {
Expand Down Expand Up @@ -119,6 +127,17 @@ final class FavoriteViewModel {
}

func fetchFavoritedWorlds(service: WorldServiceProtocol) async throws {
favoriteWorlds = try await service.fetchFavoritedWorlds()
favoriteWorlds = try await service.fetchFavoritedWorlds(n: 100)
}

var groupedFavoriteWorlds: [FavoriteWorld] {
Dictionary(grouping: favoriteWorlds, by: { $0.favoriteGroup ?? "Unknown" })
.sorted { $0.key < $1.key }
.map { dictionary in
FavoriteWorld(
group: getFavoriteGroup(name: dictionary.key),
worlds: dictionary.value
)
}
}
}
2 changes: 1 addition & 1 deletion harmonie/Views/Favorite/FavoriteFriendListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct FavoriteFriendListView: View {
var body: some View {
List(favoriteVM.favoriteFriendGroups, selection: $selected) { group in
if let friends = favoriteVM.getFavoriteFriends(group.id) {
Section(header: Text(group.displayName)) {
DisclosureGroup(group.displayName) {
ForEach(friends) { friend in
NavigationLabel {
Label {
Expand Down
12 changes: 4 additions & 8 deletions harmonie/Views/Favorite/FavoriteWorldListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ struct FavoriteWorldListView: View {
}

var body: some View {
List(groupedWorlds.keys.sorted(), id: \.hashValue, selection: $selected) { group in
if let worlds = groupedWorlds[group] {
Section(header: Text(group)) {
ForEach(worlds) { world in
List(favoriteVM.groupedFavoriteWorlds, selection: $selected) { favoriteWorlds in
if let group = favoriteWorlds.group {
DisclosureGroup(group.displayName) {
ForEach(favoriteWorlds.worlds) { world in
worldItem(world)
.tag(Selected(id: world.id))
}
Expand All @@ -29,10 +29,6 @@ struct FavoriteWorldListView: View {
}
}

private var groupedWorlds: [String: [World]] {
Dictionary(grouping: favoriteVM.favoriteWorlds, by: { $0.favoriteGroup ?? "Unknown" })
}

private func worldItem(_ world: World) -> some View {
HStack(spacing: 12) {
SquareURLImage(
Expand Down
28 changes: 14 additions & 14 deletions harmonie/Views/Favorite/FavoritesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ struct FavoritesView: View {
@State private var selected: Selected?

var body: some View {
@Bindable var favoriteVM = favoriteVM
NavigationSplitView(columnVisibility: .constant(.all)) {
Group {
if favoriteVM.segment == .friend {
FavoriteFriendListView(selected: $selected)
} else if favoriteVM.segment == .world {
FavoriteWorldListView(selected: $selected)
VStack {
Picker("", selection: $favoriteVM.segment) {
ForEach(Segment.allCases) { segment in
Text(segment.description).tag(segment)
}
}
}
.toolbar {
ToolbarItem(placement: .status) {
@Bindable var favoriteVM = favoriteVM
Picker("", selection: $favoriteVM.segment) {
ForEach(Segment.allCases) { segment in
Text(segment.description).tag(segment)
}
.pickerStyle(.segmented)
.padding(.horizontal, 20)
Group {
if favoriteVM.segment == .friend {
FavoriteFriendListView(selected: $selected)
} else if favoriteVM.segment == .world {
FavoriteWorldListView(selected: $selected)
}
.pickerStyle(SegmentedPickerStyle())
}
.contentMargins(.top, 0)
}
.navigationTitle("Favorites")
} detail: {
Expand Down
1 change: 1 addition & 0 deletions harmonie/Views/Friend/FriendsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct FriendsView: View {
let friendVM = FriendViewModel(user: PreviewDataProvider.shared.previewUser)
let favoriteVM = FavoriteViewModel()
FriendsView()
.environment(appVM)
.environment(friendVM)
.environment(favoriteVM)
.task {
Expand Down

0 comments on commit 9e4714f

Please sign in to comment.