From 10b96fec36653b2e19b042282c4435bb3bbb0111 Mon Sep 17 00:00:00 2001 From: makinosp Date: Sun, 3 Nov 2024 16:01:19 +0900 Subject: [PATCH 01/15] feat: improvement preview data --- harmonie/Previews/Models/Friend.swift | 4 +- harmonie/Previews/Models/PreviewString.swift | 54 ++++++++++++++++---- harmonie/Previews/Models/UserDetail.swift | 12 ++--- 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/harmonie/Previews/Models/Friend.swift b/harmonie/Previews/Models/Friend.swift index 2a82980..fd2ee25 100644 --- a/harmonie/Previews/Models/Friend.swift +++ b/harmonie/Previews/Models/Friend.swift @@ -53,16 +53,16 @@ private extension Friend { init( id: UUID, avatarImageUrl: URL? = PreviewDataProvider.iconImageUrl, - displayName: String = PreviewString.Name.randomValue, location: Location, status: UserStatus ) { + let profile = PreviewProfile.random self.init( bio: "Biography", bioLinks: SafeDecodingArray(), avatarImageUrl: avatarImageUrl, avatarThumbnailUrl: avatarImageUrl, - displayName: displayName, + displayName: profile?.name ?? "", id: "usr_\(id.uuidString)", isFriend: true, lastLogin: Date(), diff --git a/harmonie/Previews/Models/PreviewString.swift b/harmonie/Previews/Models/PreviewString.swift index ef7c9ba..1f9fec5 100644 --- a/harmonie/Previews/Models/PreviewString.swift +++ b/harmonie/Previews/Models/PreviewString.swift @@ -5,17 +5,53 @@ // Created by makinosp on 2024/10/20. // -enum PreviewString { - enum Name: String, CaseIterable { - case emma - case josh - case clarke - case nathalie +import Foundation +import VRCKit + +enum PreviewProfile: String, CaseIterable { + case emma + case josh + case clarke + case nathalie + case meihua + case stella +} + +extension PreviewProfile { + var name: String { + rawValue.capitalized + } + + static var random: Self? { + allCases.randomElement() + } + + static var randomName: String { + random?.rawValue.capitalized ?? "" + } + + static var randomImageUrl: URL? { + random?.imageUrl() } } -extension PreviewString.Name { - static var randomValue: String { - allCases.randomElement()?.rawValue.capitalized ?? "" +extension PreviewProfile: ImageUrlRepresentable { + func imageUrl(_ resolution: ImageResolution = .origin) -> URL? { + let path: String + switch self { + case .emma: + path = "/00/64/j71jho9d_o.jpeg" + case .josh: + path = "/4c/65/8mxWMTxR_o.jpg" + case .clarke: + path = "/27/09/ooNrEkFY_o.jpg" + case .nathalie: + path = "/46/2a/PjWXRlvt_o.jpg" + case .meihua: + path = "/55/ca/a2MRVLCx_o.jpg" + case .stella: + path = "/2f/73/4L6Bn9x9_o.jpg" + } + return URL(string: PreviewDataProvider.imageBaseURL + path) } } diff --git a/harmonie/Previews/Models/UserDetail.swift b/harmonie/Previews/Models/UserDetail.swift index 9985f4e..9e67e54 100644 --- a/harmonie/Previews/Models/UserDetail.swift +++ b/harmonie/Previews/Models/UserDetail.swift @@ -34,7 +34,6 @@ private extension UserDetail { init( id: UUID = UUID(), bio: String = "Demo", - displayName: String = PreviewString.Name.randomValue, location: Location, state: User.State, status: UserStatus, @@ -43,22 +42,23 @@ private extension UserDetail { dateJoined: Date = Date(), lastActivity: Date = Date() ) { + let profile = PreviewProfile.random self.init( bio: bio, bioLinks: SafeDecodingArray(), - avatarImageUrl: PreviewDataProvider.iconImageUrl, - avatarThumbnailUrl: PreviewDataProvider.iconImageUrl, - displayName: displayName, + avatarImageUrl: profile?.imageUrl(), + avatarThumbnailUrl: profile?.imageUrl(), + displayName: profile?.name ?? "", id: "usr_\(id.uuidString)", isFriend: isFriend, lastLogin: Date(), lastPlatform: "standalonewindows", - profilePicOverride: PreviewDataProvider.iconImageUrl, + profilePicOverride: profile?.imageUrl(), state: state, status: status, statusDescription: statusDescription, tags: UserTags(), - userIcon: PreviewDataProvider.iconImageUrl, + userIcon: profile?.imageUrl(), location: location, friendKey: "", dateJoined: dateJoined, From 77a0faf307c755eacf7068fa751960ff708226e0 Mon Sep 17 00:00:00 2001 From: makinosp Date: Sun, 3 Nov 2024 16:05:32 +0900 Subject: [PATCH 02/15] refact: code refactoring --- .../AppViewModel+PreviewInitializer.swift | 2 +- harmonie/Previews/Models/Friend.swift | 10 ++++---- .../Previews/Models/FriendsLocation.swift | 2 +- harmonie/Previews/Models/Instance.swift | 2 +- .../{PreviewString.swift => Profile.swift} | 24 ++++++++++--------- harmonie/Previews/Models/UserDetail.swift | 4 ++-- harmonie/Previews/Models/World.swift | 2 +- harmonie/Previews/PreviewContainer.swift | 2 +- ...ewDataProvider.swift => PreviewData.swift} | 14 +++++------ .../AuthenticationPreviewService.swift | 2 +- .../Services/FavoritePreviewService.swift | 4 ++-- .../Services/FriendPreviewService.swift | 4 ++-- .../Services/InstancePreviewService.swift | 20 ++++++++-------- .../Services/UserPreviewService.swift | 2 +- .../Services/WorldPreviewService.swift | 12 +++++----- .../Views/Location/LocationCardView.swift | 2 +- harmonie/Views/Location/LocationsView.swift | 2 +- harmonie/Views/World/WorldView.swift | 2 +- 18 files changed, 57 insertions(+), 55 deletions(-) rename harmonie/Previews/Models/{PreviewString.swift => Profile.swift} (71%) rename harmonie/Previews/{PreviewDataProvider.swift => PreviewData.swift} (86%) diff --git a/harmonie/Previews/AppViewModel+PreviewInitializer.swift b/harmonie/Previews/AppViewModel+PreviewInitializer.swift index c228ca5..05894dd 100644 --- a/harmonie/Previews/AppViewModel+PreviewInitializer.swift +++ b/harmonie/Previews/AppViewModel+PreviewInitializer.swift @@ -11,6 +11,6 @@ extension AppViewModel { convenience init(isPreviewMode: Bool) { self.init() services = APIServiceUtil(isPreviewMode: true, client: client) - user = PreviewDataProvider.shared.previewUser + user = PreviewData.shared.previewUser } } diff --git a/harmonie/Previews/Models/Friend.swift b/harmonie/Previews/Models/Friend.swift index fd2ee25..5001fbd 100644 --- a/harmonie/Previews/Models/Friend.swift +++ b/harmonie/Previews/Models/Friend.swift @@ -8,7 +8,7 @@ import Foundation import VRCKit -extension PreviewDataProvider { +extension PreviewData { struct FriendSet { let friend: Friend let userDetail: UserDetail @@ -27,7 +27,7 @@ extension PreviewDataProvider { } } -extension PreviewDataProvider.FriendSet { +extension PreviewData.FriendSet { init( id: UUID, location: Location, @@ -39,7 +39,7 @@ extension PreviewDataProvider.FriendSet { location: location, status: status ), - userDetail: PreviewDataProvider.userDetail( + userDetail: PreviewData.userDetail( id: id, location: location, state: status == .offline ? .offline : .active, @@ -52,11 +52,11 @@ extension PreviewDataProvider.FriendSet { private extension Friend { init( id: UUID, - avatarImageUrl: URL? = PreviewDataProvider.iconImageUrl, + avatarImageUrl: URL? = PreviewData.iconImageUrl, location: Location, status: UserStatus ) { - let profile = PreviewProfile.random + let profile = PreviewData.Profile.random self.init( bio: "Biography", bioLinks: SafeDecodingArray(), diff --git a/harmonie/Previews/Models/FriendsLocation.swift b/harmonie/Previews/Models/FriendsLocation.swift index 3e90715..787e560 100644 --- a/harmonie/Previews/Models/FriendsLocation.swift +++ b/harmonie/Previews/Models/FriendsLocation.swift @@ -7,7 +7,7 @@ import VRCKit -extension PreviewDataProvider { +extension PreviewData { static var friendsLocation: FriendsLocation { FriendsLocation( location: .offline, diff --git a/harmonie/Previews/Models/Instance.swift b/harmonie/Previews/Models/Instance.swift index a4e8546..2fb2739 100644 --- a/harmonie/Previews/Models/Instance.swift +++ b/harmonie/Previews/Models/Instance.swift @@ -8,7 +8,7 @@ import Foundation import VRCKit -extension PreviewDataProvider { +extension PreviewData { static func instance(worldId: UUID, instanceId: Int) -> Instance { Instance(world: bar) } diff --git a/harmonie/Previews/Models/PreviewString.swift b/harmonie/Previews/Models/Profile.swift similarity index 71% rename from harmonie/Previews/Models/PreviewString.swift rename to harmonie/Previews/Models/Profile.swift index 1f9fec5..abb70c1 100644 --- a/harmonie/Previews/Models/PreviewString.swift +++ b/harmonie/Previews/Models/Profile.swift @@ -1,5 +1,5 @@ // -// PreviewString.swift +// PreviewProfile.swift // Harmonie // // Created by makinosp on 2024/10/20. @@ -8,16 +8,18 @@ import Foundation import VRCKit -enum PreviewProfile: String, CaseIterable { - case emma - case josh - case clarke - case nathalie - case meihua - case stella +extension PreviewData { + enum Profile: String, CaseIterable { + case emma + case josh + case clarke + case nathalie + case meihua + case stella + } } -extension PreviewProfile { +extension PreviewData.Profile { var name: String { rawValue.capitalized } @@ -35,7 +37,7 @@ extension PreviewProfile { } } -extension PreviewProfile: ImageUrlRepresentable { +extension PreviewData.Profile: ImageUrlRepresentable { func imageUrl(_ resolution: ImageResolution = .origin) -> URL? { let path: String switch self { @@ -52,6 +54,6 @@ extension PreviewProfile: ImageUrlRepresentable { case .stella: path = "/2f/73/4L6Bn9x9_o.jpg" } - return URL(string: PreviewDataProvider.imageBaseURL + path) + return URL(string: PreviewData.imageBaseURL + path) } } diff --git a/harmonie/Previews/Models/UserDetail.swift b/harmonie/Previews/Models/UserDetail.swift index 9e67e54..ce12a28 100644 --- a/harmonie/Previews/Models/UserDetail.swift +++ b/harmonie/Previews/Models/UserDetail.swift @@ -8,7 +8,7 @@ import Foundation import VRCKit -extension PreviewDataProvider { +extension PreviewData { static func previewUserDetail(id: UUID, instance: Instance) -> UserDetail { UserDetail( id: id, @@ -42,7 +42,7 @@ private extension UserDetail { dateJoined: Date = Date(), lastActivity: Date = Date() ) { - let profile = PreviewProfile.random + let profile = PreviewData.Profile.random self.init( bio: bio, bioLinks: SafeDecodingArray(), diff --git a/harmonie/Previews/Models/World.swift b/harmonie/Previews/Models/World.swift index 87f19af..3adeda9 100644 --- a/harmonie/Previews/Models/World.swift +++ b/harmonie/Previews/Models/World.swift @@ -8,7 +8,7 @@ import Foundation import VRCKit -extension PreviewDataProvider { +extension PreviewData { static let bar = World( id: UUID(), name: "Bar", diff --git a/harmonie/Previews/PreviewContainer.swift b/harmonie/Previews/PreviewContainer.swift index 8918842..8af925b 100644 --- a/harmonie/Previews/PreviewContainer.swift +++ b/harmonie/Previews/PreviewContainer.swift @@ -45,7 +45,7 @@ extension PreviewContainer where Content: View { } init(@ViewBuilder content: (_ user: UserDetail) -> Content) { - let userDetail = PreviewDataProvider.userDetail( + let userDetail = PreviewData.userDetail( id: UUID(), location: .private, state: .active, diff --git a/harmonie/Previews/PreviewDataProvider.swift b/harmonie/Previews/PreviewData.swift similarity index 86% rename from harmonie/Previews/PreviewDataProvider.swift rename to harmonie/Previews/PreviewData.swift index 29667ea..abe7f89 100644 --- a/harmonie/Previews/PreviewDataProvider.swift +++ b/harmonie/Previews/PreviewData.swift @@ -8,8 +8,8 @@ import Foundation import VRCKit -final class PreviewDataProvider: Sendable { - static let shared = PreviewDataProvider() +final class PreviewData: Sendable { + static let shared = PreviewData() private let previewUserId = UUID() let friends: [Friend] let userDetails: [UserDetail] @@ -39,7 +39,7 @@ final class PreviewDataProvider: Sendable { } var userDetails = onlineFriendsSet.map(\.userDetail) - userDetails.append(PreviewDataProvider.previewUserDetail(id: previewUserId, instance: Self.instance1)) + userDetails.append(PreviewData.previewUserDetail(id: previewUserId, instance: Self.instance1)) self.userDetails = userDetails self.friends = onlineFriendsSet.map(\.friend) @@ -52,8 +52,8 @@ final class PreviewDataProvider: Sendable { bio: "This is the demo user.", bioLinks: SafeDecodingArray(), currentAvatar: "", - avatarImageUrl: PreviewDataProvider.iconImageUrl, - avatarThumbnailUrl: PreviewDataProvider.iconImageUrl, + avatarImageUrl: PreviewData.iconImageUrl, + avatarThumbnailUrl: PreviewData.iconImageUrl, dateJoined: Date(), displayName: "Demo User", friendKey: "", @@ -67,13 +67,13 @@ final class PreviewDataProvider: Sendable { offlineFriends: offlineFriends.map(\.id), onlineFriends: onlineFriends.map(\.id), pastDisplayNames: [], - profilePicOverride: PreviewDataProvider.iconImageUrl, + profilePicOverride: PreviewData.iconImageUrl, state: .active, status: .active, statusDescription: "status", tags: UserTags(), twoFactorAuthEnabled: true, - userIcon: PreviewDataProvider.iconImageUrl, + userIcon: PreviewData.iconImageUrl, userLanguage: nil, userLanguageCode: nil, presence: Presence() diff --git a/harmonie/Previews/Services/AuthenticationPreviewService.swift b/harmonie/Previews/Services/AuthenticationPreviewService.swift index 1ec0d41..067fe68 100644 --- a/harmonie/Previews/Services/AuthenticationPreviewService.swift +++ b/harmonie/Previews/Services/AuthenticationPreviewService.swift @@ -15,7 +15,7 @@ final actor AuthenticationPreviewService: APIService, AuthenticationServiceProto func exists(userId: String) async throws -> Bool { true } func loginUserInfo() async throws -> Either { - .left(PreviewDataProvider.shared.previewUser) + .left(PreviewData.shared.previewUser) } func verify2FA(verifyType: VerifyType, code: String) async throws -> Bool { true } diff --git a/harmonie/Previews/Services/FavoritePreviewService.swift b/harmonie/Previews/Services/FavoritePreviewService.swift index 9bb6ba1..fd24838 100644 --- a/harmonie/Previews/Services/FavoritePreviewService.swift +++ b/harmonie/Previews/Services/FavoritePreviewService.swift @@ -20,7 +20,7 @@ final actor FavoritePreviewService: APIService, FavoriteServiceProtocol { id: "fvgrp_\(UUID().uuidString)", displayName: "\(type.rawValue.capitalized) Group \(index)", name: "group_\(index)", - ownerId: PreviewDataProvider.shared.previewUser.id, + ownerId: PreviewData.shared.previewUser.id, tags: [], type: type, visibility: .private @@ -32,7 +32,7 @@ final actor FavoritePreviewService: APIService, FavoriteServiceProtocol { func listFavorites(type: FavoriteType) async throws -> [Favorite] { switch type { case .friend: - PreviewDataProvider.shared.onlineFriends.prefix(5).map { friend in + PreviewData.shared.onlineFriends.prefix(5).map { friend in Favorite(id: UUID().uuidString, favoriteId: friend.id, tags: ["group_1"], type: .friend) } default: [] diff --git a/harmonie/Previews/Services/FriendPreviewService.swift b/harmonie/Previews/Services/FriendPreviewService.swift index 94bf0e0..6e2dcaf 100644 --- a/harmonie/Previews/Services/FriendPreviewService.swift +++ b/harmonie/Previews/Services/FriendPreviewService.swift @@ -13,11 +13,11 @@ final actor FriendPreviewService: APIService, FriendServiceProtocol { let client: APIClient func fetchFriends(offset: Int, n: Int, offline: Bool) async throws -> [Friend] { - offline ? PreviewDataProvider.shared.offlineFriends : PreviewDataProvider.shared.onlineFriends + offline ? PreviewData.shared.offlineFriends : PreviewData.shared.onlineFriends } func fetchFriends(count: Int, offline: Bool) async throws -> [Friend] { - offline ? PreviewDataProvider.shared.offlineFriends : PreviewDataProvider.shared.onlineFriends + offline ? PreviewData.shared.offlineFriends : PreviewData.shared.onlineFriends } func unfriend(id: String) async throws {} diff --git a/harmonie/Previews/Services/InstancePreviewService.swift b/harmonie/Previews/Services/InstancePreviewService.swift index eec7fc2..48453a1 100644 --- a/harmonie/Previews/Services/InstancePreviewService.swift +++ b/harmonie/Previews/Services/InstancePreviewService.swift @@ -14,23 +14,23 @@ final actor InstancePreviewService: APIService, InstanceServiceProtocol { func fetchInstance(location: String) async throws -> Instance { switch location { - case PreviewDataProvider.instance1.id: - PreviewDataProvider.instance1 - case PreviewDataProvider.instance2.id: - PreviewDataProvider.instance2 + case PreviewData.instance1.id: + PreviewData.instance1 + case PreviewData.instance2.id: + PreviewData.instance2 default: - PreviewDataProvider.instance1 + PreviewData.instance1 } } func fetchInstance(worldId: String, instanceId: String) async throws -> Instance { switch instanceId { - case PreviewDataProvider.instance1.instanceId: - PreviewDataProvider.instance1 - case PreviewDataProvider.instance2.instanceId: - PreviewDataProvider.instance2 + case PreviewData.instance1.instanceId: + PreviewData.instance1 + case PreviewData.instance2.instanceId: + PreviewData.instance2 default: - PreviewDataProvider.instance1 + PreviewData.instance1 } } } diff --git a/harmonie/Previews/Services/UserPreviewService.swift b/harmonie/Previews/Services/UserPreviewService.swift index 59f958d..002c091 100644 --- a/harmonie/Previews/Services/UserPreviewService.swift +++ b/harmonie/Previews/Services/UserPreviewService.swift @@ -13,7 +13,7 @@ final actor UserPreviewService: APIService, UserServiceProtocol { let client: APIClient func fetchUser(userId: String) async throws -> UserDetail { - PreviewDataProvider.shared.userDetails.first { $0.id == userId }! + PreviewData.shared.userDetails.first { $0.id == userId }! } func updateUser(id: String, editedInfo: EditableUserInfo) async throws {} diff --git a/harmonie/Previews/Services/WorldPreviewService.swift b/harmonie/Previews/Services/WorldPreviewService.swift index 3401727..4ef8426 100644 --- a/harmonie/Previews/Services/WorldPreviewService.swift +++ b/harmonie/Previews/Services/WorldPreviewService.swift @@ -15,19 +15,19 @@ final actor WorldPreviewService: APIService, WorldServiceProtocol { func fetchWorld(worldId: String) async throws -> World { switch worldId { - case PreviewDataProvider.bar.id: - PreviewDataProvider.bar - case PreviewDataProvider.casino.id: - PreviewDataProvider.casino + case PreviewData.bar.id: + PreviewData.bar + case PreviewData.casino.id: + PreviewData.casino default: - PreviewDataProvider.bar + PreviewData.bar } } func fetchFavoritedWorlds() async throws -> [FavoriteWorld] { (0..<100).map { number in FavoriteWorld( - world: PreviewDataProvider.casino, + world: PreviewData.casino, favoriteId: "fvrt_\(UUID())", favoriteGroup: number.description ) diff --git a/harmonie/Views/Location/LocationCardView.swift b/harmonie/Views/Location/LocationCardView.swift index 2390aa0..996cdaf 100644 --- a/harmonie/Views/Location/LocationCardView.swift +++ b/harmonie/Views/Location/LocationCardView.swift @@ -21,7 +21,7 @@ struct LocationCardView: View { if isFailure { EmptyView() } else { - locationCardContent(instance: instance ?? PreviewDataProvider.instance()) + locationCardContent(instance: instance ?? PreviewData.instance()) .redacted(reason: isRequesting ? .placeholder : []) .task { if case let .id(id) = location.location { diff --git a/harmonie/Views/Location/LocationsView.swift b/harmonie/Views/Location/LocationsView.swift index 5c1c735..b70ba09 100644 --- a/harmonie/Views/Location/LocationsView.swift +++ b/harmonie/Views/Location/LocationsView.swift @@ -97,7 +97,7 @@ struct LocationsView: View { ForEach(0...7, id: \.self) { _ in LocationCardView( selected: .constant(nil), - location: PreviewDataProvider.friendsLocation + location: PreviewData.friendsLocation ) } } else { diff --git a/harmonie/Views/World/WorldView.swift b/harmonie/Views/World/WorldView.swift index 0aad01a..b8219cf 100644 --- a/harmonie/Views/World/WorldView.swift +++ b/harmonie/Views/World/WorldView.swift @@ -178,7 +178,7 @@ struct WorldView: View { #Preview { PreviewContainer { NavigationStack { - WorldView(world: PreviewDataProvider.casino) + WorldView(world: PreviewData.casino) } } } From f3f3a1f64ea2d42bd4410094fa0c6cd802fcab93 Mon Sep 17 00:00:00 2001 From: makinosp Date: Sun, 3 Nov 2024 16:14:14 +0900 Subject: [PATCH 03/15] feat: improvement preview data --- harmonie/Previews/Models/Friend.swift | 9 ++++++--- harmonie/Previews/Models/UserDetail.swift | 22 ++++++++++++---------- harmonie/Previews/PreviewData.swift | 2 +- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/harmonie/Previews/Models/Friend.swift b/harmonie/Previews/Models/Friend.swift index 5001fbd..a5e1c8f 100644 --- a/harmonie/Previews/Models/Friend.swift +++ b/harmonie/Previews/Models/Friend.swift @@ -30,17 +30,20 @@ extension PreviewData { extension PreviewData.FriendSet { init( id: UUID, + profile: PreviewData.Profile? = PreviewData.Profile.random, location: Location, status: UserStatus ) { self.init( friend: Friend( id: id, + profile: profile, location: location, status: status ), userDetail: PreviewData.userDetail( id: id, + profile: profile, location: location, state: status == .offline ? .offline : .active, status: status @@ -52,16 +55,16 @@ extension PreviewData.FriendSet { private extension Friend { init( id: UUID, + profile: PreviewData.Profile? = PreviewData.Profile.random, avatarImageUrl: URL? = PreviewData.iconImageUrl, location: Location, status: UserStatus ) { - let profile = PreviewData.Profile.random self.init( bio: "Biography", bioLinks: SafeDecodingArray(), - avatarImageUrl: avatarImageUrl, - avatarThumbnailUrl: avatarImageUrl, + avatarImageUrl: profile?.imageUrl(), + avatarThumbnailUrl: profile?.imageUrl(), displayName: profile?.name ?? "", id: "usr_\(id.uuidString)", isFriend: true, diff --git a/harmonie/Previews/Models/UserDetail.swift b/harmonie/Previews/Models/UserDetail.swift index ce12a28..b173cea 100644 --- a/harmonie/Previews/Models/UserDetail.swift +++ b/harmonie/Previews/Models/UserDetail.swift @@ -9,30 +9,33 @@ import Foundation import VRCKit extension PreviewData { - static func previewUserDetail(id: UUID, instance: Instance) -> UserDetail { - UserDetail( - id: id, - location: .id(instance.id), - state: .active, - status: .active, - isFriend: false - ) + static func userDetail(id: UUID, instance: Instance) -> UserDetail { + UserDetail(id: id, location: .id(instance.id), state: .active, status: .active, isFriend: false) } static func userDetail( id: UUID, + profile: Profile? = nil, location: Location, state: User.State, status: UserStatus, isFriend: Bool = true ) -> UserDetail { - UserDetail(id: id, location: location, state: state, status: status, isFriend: isFriend) + UserDetail( + id: id, + profile: profile, + location: location, + state: state, + status: status, + isFriend: isFriend + ) } } private extension UserDetail { init( id: UUID = UUID(), + profile: PreviewData.Profile? = PreviewData.Profile.random, bio: String = "Demo", location: Location, state: User.State, @@ -42,7 +45,6 @@ private extension UserDetail { dateJoined: Date = Date(), lastActivity: Date = Date() ) { - let profile = PreviewData.Profile.random self.init( bio: bio, bioLinks: SafeDecodingArray(), diff --git a/harmonie/Previews/PreviewData.swift b/harmonie/Previews/PreviewData.swift index abe7f89..3df7e09 100644 --- a/harmonie/Previews/PreviewData.swift +++ b/harmonie/Previews/PreviewData.swift @@ -39,7 +39,7 @@ final class PreviewData: Sendable { } var userDetails = onlineFriendsSet.map(\.userDetail) - userDetails.append(PreviewData.previewUserDetail(id: previewUserId, instance: Self.instance1)) + userDetails.append(PreviewData.userDetail(id: previewUserId, instance: Self.instance1)) self.userDetails = userDetails self.friends = onlineFriendsSet.map(\.friend) From 02cb8dab51bf92bfbc40f9e135c72d820d0a7b2f Mon Sep 17 00:00:00 2001 From: makinosp Date: Sun, 3 Nov 2024 19:55:20 +0900 Subject: [PATCH 04/15] feat: improvement layout of FavoritesView --- harmonie/Views/Favorite/FavoritesView.swift | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/harmonie/Views/Favorite/FavoritesView.swift b/harmonie/Views/Favorite/FavoritesView.swift index a35ccfb..81b166e 100644 --- a/harmonie/Views/Favorite/FavoritesView.swift +++ b/harmonie/Views/Favorite/FavoritesView.swift @@ -83,11 +83,8 @@ struct FavoritesView: View { Section("Friends") { let groups = favoriteVM.favoriteGroups(.friend) ForEach(groups) { group in - if let friends = favoriteVM.getFavoriteFriends(group.id) { - friendsDisclosureGroup(group.displayName, friends: friends) - } else { - groupLabel(group.displayName, count: .zero, max: .friends) - } + let friends = favoriteVM.getFavoriteFriends(group.id) + friendsDisclosureGroup(group.displayName, friends: friends ?? []) } } } From 3c48ce9ef74166e64f2414464f00a17acbc3571a Mon Sep 17 00:00:00 2001 From: makinosp Date: Sun, 3 Nov 2024 21:01:02 +0900 Subject: [PATCH 05/15] feat: improvement preview data for FavoritePreviewService --- .../Services/FavoritePreviewService.swift | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/harmonie/Previews/Services/FavoritePreviewService.swift b/harmonie/Previews/Services/FavoritePreviewService.swift index fd24838..476595d 100644 --- a/harmonie/Previews/Services/FavoritePreviewService.swift +++ b/harmonie/Previews/Services/FavoritePreviewService.swift @@ -13,38 +13,47 @@ import VRCKit final actor FavoritePreviewService: APIService, FavoriteServiceProtocol { let client: APIClient - func listFavoriteGroups() async throws -> [FavoriteGroup] { - FavoriteType.allCases.flatMap { type in - (1...3).map { index in - FavoriteGroup( - id: "fvgrp_\(UUID().uuidString)", - displayName: "\(type.rawValue.capitalized) Group \(index)", - name: "group_\(index)", - ownerId: PreviewData.shared.previewUser.id, - tags: [], - type: type, - visibility: .private - ) - } + let favoriteGroups = FavoriteType.allCases.flatMap { type in + (1...3).map { number in + FavoriteGroup( + id: "fvgrp_\(UUID().uuidString)", + displayName: "\(type.rawValue.capitalized) Group \(number)", + name: "group_\(number)", + ownerId: PreviewData.shared.previewUser.id, + tags: [], + type: type, + visibility: .private + ) } } + func listFavoriteGroups() async throws -> [FavoriteGroup] { + favoriteGroups + } + func listFavorites(type: FavoriteType) async throws -> [Favorite] { - switch type { - case .friend: - PreviewData.shared.onlineFriends.prefix(5).map { friend in - Favorite(id: UUID().uuidString, favoriteId: friend.id, tags: ["group_1"], type: .friend) - } - default: [] - } + // No implementation required + [] } func listFavorites(n: Int, offset: Int, type: FavoriteType, tag: String?) async throws -> [Favorite] { + // No implementation required [] } func fetchFavoriteList(favoriteGroups: [FavoriteGroup], type: FavoriteType) async throws -> [FavoriteList] { - [] + favoriteGroups.enumerated().map { (index, group) in + switch (index, group.type) { + case (6, .friend): + FavoriteList( + id: group.id, + favorites: PreviewData.shared.onlineFriends.prefix(5).map { friend in + Favorite(favoriteId: friend.id, type: group.type) + } + ) + default: FavoriteList(id: group.id, favorites: []) + } + } } public func addFavorite( @@ -52,16 +61,24 @@ final actor FavoritePreviewService: APIService, FavoriteServiceProtocol { favoriteId: String, tag: String ) async throws -> Favorite { - Favorite(id: UUID().uuidString, favoriteId: favoriteId, tags: [tag], type: type) + Favorite(favoriteId: favoriteId, tags: [tag], type: type) } func updateFavoriteGroup( source: FavoriteGroup, displayName: String, visibility: FavoriteGroup.Visibility - ) async throws {} + ) async throws { + // No implementation required + } func removeFavorite(favoriteId: String) async throws -> SuccessResponse { SuccessResponse(success: .ok) } } + +private extension Favorite { + init(favoriteId: String, tags: [String] = [], type: FavoriteType) { + self.init(id: UUID().uuidString, favoriteId: favoriteId, tags: tags, type: type) + } +} From 5746178848286edef9db691be220f6bdceef5a07 Mon Sep 17 00:00:00 2001 From: makinosp Date: Sun, 3 Nov 2024 21:01:57 +0900 Subject: [PATCH 06/15] update: package dependencies --- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Harmonie.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Harmonie.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 3ee4457..684e374 100644 --- a/Harmonie.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Harmonie.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -52,7 +52,7 @@ "location" : "https://github.com/makinosp/vrckit", "state" : { "branch" : "develop", - "revision" : "7c88c46ceaf6d12b048cd03220c844de07206ec2" + "revision" : "8a803ceb610901c5061b7fb9aa4f7e6bfecd56f4" } } ], From 0be0c1be1bf64e8c9d746fa729bfa21afc821d25 Mon Sep 17 00:00:00 2001 From: makinosp Date: Mon, 4 Nov 2024 12:35:18 +0900 Subject: [PATCH 07/15] feat: improvement preview data --- harmonie/Previews/Models/World.swift | 43 +++++++++++++++++++++------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/harmonie/Previews/Models/World.swift b/harmonie/Previews/Models/World.swift index 3adeda9..3465e41 100644 --- a/harmonie/Previews/Models/World.swift +++ b/harmonie/Previews/Models/World.swift @@ -10,12 +10,9 @@ import VRCKit extension PreviewData { static let bar = World( - id: UUID(), name: "Bar", description: "Bar", imageUrl: URL(string: "\(imageBaseURL)/7a/95/kLHkm3Ez_o.jpg"), - thumbnailImageUrl: URL(string: "\(imageBaseURL)/7a/95/kLHkm3Ez_o.jpg"), - organization: "", favorites: 50, visits: 100, popularity: 10, @@ -23,12 +20,39 @@ extension PreviewData { ) static let casino = World( - id: UUID(), name: "Casino", description: "Casino", imageUrl: URL(string: "\(imageBaseURL)/83/48/NtBOJpF1_o.jpg"), - thumbnailImageUrl: URL(string: "\(imageBaseURL)/83/48/NtBOJpF1_o.jpg"), - organization: "", + favorites: 50, + visits: 75, + popularity: 5, + heat: 3 + ) + + static let fuji = World( + name: "Mt. Fuji", + description: "Mt. Fuji", + imageUrl: URL(string: "\(imageBaseURL)/81/2f/MOoiKQgL_o.jpg"), + favorites: 50, + visits: 75, + popularity: 5, + heat: 3 + ) + + static let chinatown = World( + name: "Chinatown", + description: "Chinatown", + imageUrl: URL(string: "\(imageBaseURL)/08/64/vu7gTsyJ_o.jpg"), + favorites: 50, + visits: 75, + popularity: 5, + heat: 3 + ) + + static let nightCity = World( + name: "Night City", + description: "Night City", + imageUrl: URL(string: "\(imageBaseURL)/db/22/kolgI25s_o.jpg"), favorites: 50, visits: 75, popularity: 5, @@ -38,12 +62,11 @@ extension PreviewData { extension World { init( - id: UUID, + id: UUID = UUID(), name: String, description: String, imageUrl: URL?, - thumbnailImageUrl: URL?, - organization: String, + organization: String = "", favorites: Int, visits: Int, popularity: Int, @@ -60,7 +83,7 @@ extension World { tags: [], releaseStatus: .public, imageUrl: imageUrl, - thumbnailImageUrl: thumbnailImageUrl, + thumbnailImageUrl: imageUrl, namespace: nil, organization: "", previewYoutubeId: nil, From 988e52d400b5b420f803dccbccb0deb73393fb92 Mon Sep 17 00:00:00 2001 From: makinosp Date: Mon, 4 Nov 2024 15:53:33 +0900 Subject: [PATCH 08/15] feat: adopt GeometryProxy to Equatable --- harmonie/Extensions/GeometryProxy+Equatable.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 harmonie/Extensions/GeometryProxy+Equatable.swift diff --git a/harmonie/Extensions/GeometryProxy+Equatable.swift b/harmonie/Extensions/GeometryProxy+Equatable.swift new file mode 100644 index 0000000..b15cf64 --- /dev/null +++ b/harmonie/Extensions/GeometryProxy+Equatable.swift @@ -0,0 +1,14 @@ +// +// GeometryProxy+Equatable.swift +// Harmonie +// +// Created by makinosp on 2024/11/04. +// + +import SwiftUICore + +extension GeometryProxy: @retroactive Equatable { + public static func == (lhs: GeometryProxy, rhs: GeometryProxy) -> Bool { + lhs.size == rhs.size && lhs.safeAreaInsets == rhs.safeAreaInsets + } +} From 5102c98c5814af53ef2e36df006b60ac0fad1e79 Mon Sep 17 00:00:00 2001 From: makinosp Date: Mon, 4 Nov 2024 15:55:50 +0900 Subject: [PATCH 09/15] feat: implement using GeometryReader to store screen sizes --- harmonie/ViewModels/AppViewModel.swift | 1 + harmonie/Views/ContentView.swift | 35 ++++++++++++--------- harmonie/Views/Location/LocationsView.swift | 14 ++++----- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/harmonie/ViewModels/AppViewModel.swift b/harmonie/ViewModels/AppViewModel.swift index a3b9747..11aa022 100644 --- a/harmonie/ViewModels/AppViewModel.swift +++ b/harmonie/ViewModels/AppViewModel.swift @@ -17,6 +17,7 @@ final class AppViewModel { var applicationError: ApplicationError? var services: APIServiceUtil var verifyType: VerifyType? + var screenSize: CGSize = .zero @ObservationIgnored var client: APIClient @ObservationIgnored let userDefaults: UserDefaults diff --git a/harmonie/Views/ContentView.swift b/harmonie/Views/ContentView.swift index 80e3875..2134aa2 100644 --- a/harmonie/Views/ContentView.swift +++ b/harmonie/Views/ContentView.swift @@ -12,21 +12,28 @@ struct ContentView: View { @Environment(AppViewModel.self) var appVM var body: some View { - switch appVM.step { - case .initializing: - ProgressScreen() - .task { - appVM.step = await appVM.setup(service: appVM.services.authenticationService) + GeometryReader { geometry in + Group { + switch appVM.step { + case .initializing: + ProgressScreen() + .task { + appVM.step = await appVM.setup(service: appVM.services.authenticationService) + } + .errorAlert() + case .loggingIn: + LoginView() + .errorAlert() + case .done: + MainTabView() + .environment(FriendViewModel(appVM: appVM)) + .environment(FavoriteViewModel()) + .errorAlert() } - .errorAlert() - case .loggingIn: - LoginView() - .errorAlert() - case .done: - MainTabView() - .environment(FriendViewModel(appVM: appVM)) - .environment(FavoriteViewModel()) - .errorAlert() + } + .onChange(of: geometry) { + appVM.screenSize = geometry.size + } } } } diff --git a/harmonie/Views/Location/LocationsView.swift b/harmonie/Views/Location/LocationsView.swift index b70ba09..ce54cd1 100644 --- a/harmonie/Views/Location/LocationsView.swift +++ b/harmonie/Views/Location/LocationsView.swift @@ -49,7 +49,7 @@ struct LocationsView: View { } } .navigationTitle("Social") - .setColumn() + .setColumn(appVM.screenSize) } private var content: some View { @@ -66,7 +66,7 @@ struct LocationsView: View { } } .background(Color(.systemGroupedBackground)) - .setColumn() + .setColumn(appVM.screenSize) } private var detail: some View { @@ -88,7 +88,7 @@ struct LocationsView: View { } } .background(Color(.systemGroupedBackground)) - .setColumn() + .setColumn(appVM.screenSize) } private var friendLocations: some View { @@ -153,11 +153,11 @@ extension Location { } private extension View { - func setColumn() -> some View { + func setColumn(_ screenSize: CGSize) -> some View { navigationSplitViewColumnWidth( - min: WindowUtil.width * 1 / 3, - ideal: WindowUtil.width * 1 / 3, - max: WindowUtil.width / 2 + min: screenSize.width * 1 / 3, + ideal: screenSize.width * 1 / 3, + max: screenSize.width / 2 ) } } From 32af72a67d405febd9ab424825057caf16f387c9 Mon Sep 17 00:00:00 2001 From: makinosp Date: Mon, 4 Nov 2024 15:57:08 +0900 Subject: [PATCH 10/15] feat: improvement layout of LocationsView/LocationCardView --- harmonie/Views/Location/LocationCardView.swift | 1 - harmonie/Views/Location/LocationsView.swift | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/harmonie/Views/Location/LocationCardView.swift b/harmonie/Views/Location/LocationCardView.swift index 996cdaf..4454ddb 100644 --- a/harmonie/Views/Location/LocationCardView.swift +++ b/harmonie/Views/Location/LocationCardView.swift @@ -66,7 +66,6 @@ struct LocationCardView: View { selected = tag(instance) } } - .padding(.top, 4) } .tag(tag(instance)) } diff --git a/harmonie/Views/Location/LocationsView.swift b/harmonie/Views/Location/LocationsView.swift index b70ba09..75a053f 100644 --- a/harmonie/Views/Location/LocationsView.swift +++ b/harmonie/Views/Location/LocationsView.swift @@ -41,6 +41,7 @@ struct LocationsView: View { inPrivateInstance } } + .environment(\.defaultMinListRowHeight, 80) .overlay { if friendVM.isContentUnavailable { ContentUnavailableView { From 9efaf83c79dff2424acbcc5b02f583b629b2c804 Mon Sep 17 00:00:00 2001 From: makinosp Date: Mon, 4 Nov 2024 15:59:40 +0900 Subject: [PATCH 11/15] refact: remove unnecessary code --- .../Components/GradientOverlayImageView.swift | 2 +- harmonie/Utils/WindowUtil.swift | 26 ------------------- .../Views/UserDetail/UserDetailView.swift | 1 + harmonie/Views/World/WorldView.swift | 1 + 4 files changed, 3 insertions(+), 27 deletions(-) delete mode 100644 harmonie/Utils/WindowUtil.swift diff --git a/harmonie/Components/GradientOverlayImageView.swift b/harmonie/Components/GradientOverlayImageView.swift index d4449a5..f533489 100644 --- a/harmonie/Components/GradientOverlayImageView.swift +++ b/harmonie/Components/GradientOverlayImageView.swift @@ -14,7 +14,7 @@ struct GradientOverlayImageView: View where TopConten @Init(.internal) private let imageUrl: URL? @Init(.internal, default: nil) private let thumbnailImageUrl: URL? @Init(.internal) private let height: CGFloat - @Init(.internal, default: WindowUtil.width) private let maxWidth: CGFloat + @Init(.internal) private let maxWidth: CGFloat @Init(.internal, default: Gradient(colors: [.black.opacity(0.5), .clear])) private let gradient: Gradient @Init(.internal, default: { EmptyView() }, escaping: true) private let topContent: () -> TopContent @Init(.internal, default: { EmptyView() }, escaping: true) private let bottomContent: () -> BottomContent diff --git a/harmonie/Utils/WindowUtil.swift b/harmonie/Utils/WindowUtil.swift deleted file mode 100644 index bb3bf40..0000000 --- a/harmonie/Utils/WindowUtil.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// WindowUtil.swift -// Harmonie -// -// Created by makinosp on 2024/09/15. -// - -import UIKit - -enum WindowUtil { - @MainActor static var window: UIWindowScene? { - UIApplication.shared.connectedScenes.first as? UIWindowScene - } - - @MainActor static var bounds: CGRect { - window?.screen.bounds ?? .zero - } - - @MainActor static var height: CGFloat { - window?.screen.bounds.height ?? .zero - } - - @MainActor static var width: CGFloat { - window?.screen.bounds.width ?? .zero - } -} diff --git a/harmonie/Views/UserDetail/UserDetailView.swift b/harmonie/Views/UserDetail/UserDetailView.swift index 11894a6..9c14739 100644 --- a/harmonie/Views/UserDetail/UserDetailView.swift +++ b/harmonie/Views/UserDetail/UserDetailView.swift @@ -31,6 +31,7 @@ struct UserDetailView: View { imageUrl: user.imageUrl(.x1024), thumbnailImageUrl: user.imageUrl(.x256), height: 250, + maxWidth: appVM.screenSize.width, topContent: { topOverlay }, bottomContent: { bottomOverlay } ) diff --git a/harmonie/Views/World/WorldView.swift b/harmonie/Views/World/WorldView.swift index b8219cf..001362e 100644 --- a/harmonie/Views/World/WorldView.swift +++ b/harmonie/Views/World/WorldView.swift @@ -22,6 +22,7 @@ struct WorldView: View { imageUrl: world.imageUrl(.x1024), thumbnailImageUrl: world.imageUrl(.x256), height: 250, + maxWidth: appVM.screenSize.width, topContent: { topOverlay }, bottomContent: { bottomOverlay } ) From b729ea32f2ec106d867642ff3979940d0f5a87bb Mon Sep 17 00:00:00 2001 From: makinosp Date: Mon, 4 Nov 2024 16:04:45 +0900 Subject: [PATCH 12/15] update: bump up to 0.9.8 --- Harmonie.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Harmonie.xcodeproj/project.pbxproj b/Harmonie.xcodeproj/project.pbxproj index 4fbeb7a..cbe91dd 100644 --- a/Harmonie.xcodeproj/project.pbxproj +++ b/Harmonie.xcodeproj/project.pbxproj @@ -474,7 +474,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 0.9.7; + MARKETING_VERSION = 0.9.8; PRODUCT_BUNDLE_IDENTIFIER = jp.mknn.harmonie; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -510,7 +510,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 0.9.7; + MARKETING_VERSION = 0.9.8; PRODUCT_BUNDLE_IDENTIFIER = jp.mknn.harmonie; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; From 702ad3f06c52cb8146c8af9910e94e829a77082b Mon Sep 17 00:00:00 2001 From: makinosp Date: Mon, 4 Nov 2024 17:12:53 +0900 Subject: [PATCH 13/15] feat: improvement preview data --- harmonie/Previews/Models/Friend.swift | 30 ++++++++++++++++++- harmonie/Previews/Models/Instance.swift | 23 +++++++++----- harmonie/Previews/PreviewData.swift | 29 ++++++------------ .../Services/InstancePreviewService.swift | 18 ++--------- .../Views/Location/LocationCardView.swift | 2 +- 5 files changed, 57 insertions(+), 45 deletions(-) diff --git a/harmonie/Previews/Models/Friend.swift b/harmonie/Previews/Models/Friend.swift index a5e1c8f..40bcb28 100644 --- a/harmonie/Previews/Models/Friend.swift +++ b/harmonie/Previews/Models/Friend.swift @@ -28,8 +28,36 @@ extension PreviewData { } extension PreviewData.FriendSet { + /// Initialize from world information init( - id: UUID, + id: UUID = UUID(), + profile: PreviewData.Profile? = PreviewData.Profile.random, + world: World, + status: UserStatus + ) { + let location: Location = .id(PreviewData.instanceId(world)) + self.init( + friend: Friend( + id: id, + profile: profile, + location: location, + status: status + ), + userDetail: PreviewData.userDetail( + id: id, + profile: profile, + location: location, + state: status == .offline ? .offline : .active, + status: status + ) + ) + } +} + +extension PreviewData.FriendSet { + /// Initialize from world information + init( + id: UUID = UUID(), profile: PreviewData.Profile? = PreviewData.Profile.random, location: Location, status: UserStatus diff --git a/harmonie/Previews/Models/Instance.swift b/harmonie/Previews/Models/Instance.swift index 2fb2739..38f7946 100644 --- a/harmonie/Previews/Models/Instance.swift +++ b/harmonie/Previews/Models/Instance.swift @@ -13,19 +13,28 @@ extension PreviewData { Instance(world: bar) } - static func instance() -> Instance { + static var instance: Instance { Instance(world: bar) } - static let instance1 = Instance(world: bar) - static let instance2 = Instance(world: casino) + static func instanceId(_ world: World) -> Instance.ID { + "\(world.id):0" + } + + static let instanceMap: [Instance.ID: Instance] = [ + instanceId(bar): Instance(world: bar, userCount: 25), + instanceId(casino): Instance(world: casino, userCount: 25), + instanceId(fuji): Instance(world: fuji, userCount: 25), + instanceId(chinatown): Instance(world: chinatown, userCount: 25), + instanceId(nightCity): Instance(world: nightCity, userCount: 25), + ] } private extension Instance { - init(world: World, instanceId: Int = 0) { + init(world: World, instanceId: Int = 0, capacity: Int = 32, userCount: Int = 0) { self.init( active: true, - capacity: 32, + capacity: capacity, full: false, groupAccessType: nil, id: "\(world.id):\(instanceId)", @@ -35,11 +44,11 @@ private extension Instance { ownerId: "usr_\(UUID().uuidString)", permanent: false, platforms: Platforms(), - recommendedCapacity: 32, + recommendedCapacity: capacity, region: Region.allCases.randomElement() ?? .us, tags: [], type: [.public, .friends].randomElement() ?? .public, - userCount: 0, + userCount: userCount, world: world ) } diff --git a/harmonie/Previews/PreviewData.swift b/harmonie/Previews/PreviewData.swift index 3df7e09..0f77710 100644 --- a/harmonie/Previews/PreviewData.swift +++ b/harmonie/Previews/PreviewData.swift @@ -18,28 +18,17 @@ final class PreviewData: Sendable { static let iconImageUrl = URL(string: "\(imageBaseURL)/44/8f/IQToHkKa_o.jpg") private init() { - let onlineFriendsSet: [FriendSet] = (0..<50).map { count in - let id = UUID() - return switch count { - case ..<5: - FriendSet(id: id, location: .id(Self.instance1.id), status: .active) - case ..<10: - FriendSet(id: id, location: .id(Self.instance2.id), status: .active) - case ..<15: - FriendSet(id: id, location: .id(Self.instance2.id), status: .joinMe) - case ..<20: - FriendSet(id: id, location: .private, status: .askMe) - case ..<25: - FriendSet(id: id, location: .id(Self.instance1.id), status: .joinMe) - case ..<30: - FriendSet(id: id, location: .private, status: .busy) - default: - FriendSet(id: id, location: .offline, status: .offline) - } - } + let onlineFriendsSet: [FriendSet] = [ + (0..<10).map { _ in FriendSet(world: Self.bar, status: .joinMe) }, + (0..<5).map { _ in FriendSet(world: Self.casino, status: .active) }, + (0..<3).map { _ in FriendSet(world: Self.fuji, status: .joinMe) }, + (0..<2).map { _ in FriendSet(world: Self.chinatown, status: .active) }, + [FriendSet(world: Self.nightCity, status: .joinMe)], + (0..<25).map { _ in FriendSet(location: .private, status: .busy) } + ].flatMap { $0 } var userDetails = onlineFriendsSet.map(\.userDetail) - userDetails.append(PreviewData.userDetail(id: previewUserId, instance: Self.instance1)) + userDetails.append(PreviewData.userDetail(id: previewUserId, instance: Self.instance)) self.userDetails = userDetails self.friends = onlineFriendsSet.map(\.friend) diff --git a/harmonie/Previews/Services/InstancePreviewService.swift b/harmonie/Previews/Services/InstancePreviewService.swift index 48453a1..8b671b9 100644 --- a/harmonie/Previews/Services/InstancePreviewService.swift +++ b/harmonie/Previews/Services/InstancePreviewService.swift @@ -13,24 +13,10 @@ final actor InstancePreviewService: APIService, InstanceServiceProtocol { let client: APIClient func fetchInstance(location: String) async throws -> Instance { - switch location { - case PreviewData.instance1.id: - PreviewData.instance1 - case PreviewData.instance2.id: - PreviewData.instance2 - default: - PreviewData.instance1 - } + PreviewData.instanceMap[location] ?? PreviewData.instance } func fetchInstance(worldId: String, instanceId: String) async throws -> Instance { - switch instanceId { - case PreviewData.instance1.instanceId: - PreviewData.instance1 - case PreviewData.instance2.instanceId: - PreviewData.instance2 - default: - PreviewData.instance1 - } + PreviewData.instanceMap["\(worldId):\(instanceId)"] ?? PreviewData.instance } } diff --git a/harmonie/Views/Location/LocationCardView.swift b/harmonie/Views/Location/LocationCardView.swift index 4454ddb..905be05 100644 --- a/harmonie/Views/Location/LocationCardView.swift +++ b/harmonie/Views/Location/LocationCardView.swift @@ -21,7 +21,7 @@ struct LocationCardView: View { if isFailure { EmptyView() } else { - locationCardContent(instance: instance ?? PreviewData.instance()) + locationCardContent(instance: instance ?? PreviewData.instance) .redacted(reason: isRequesting ? .placeholder : []) .task { if case let .id(id) = location.location { From 59a4b19ee6b57b5ce30438c78b5fb2be2a228ab0 Mon Sep 17 00:00:00 2001 From: makinosp Date: Mon, 4 Nov 2024 17:33:21 +0900 Subject: [PATCH 14/15] fix: issue that screen size initial value --- harmonie/Views/ContentView.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/harmonie/Views/ContentView.swift b/harmonie/Views/ContentView.swift index 2134aa2..2473540 100644 --- a/harmonie/Views/ContentView.swift +++ b/harmonie/Views/ContentView.swift @@ -32,8 +32,15 @@ struct ContentView: View { } } .onChange(of: geometry) { - appVM.screenSize = geometry.size + setScreenSize(geometry) + } + .onAppear { + setScreenSize(geometry) } } } + + private func setScreenSize(_ geometry: GeometryProxy) { + appVM.screenSize = geometry.size + } } From 295642e2fbd3df73733f2a2b205f6939c217f570 Mon Sep 17 00:00:00 2001 From: makinosp Date: Mon, 4 Nov 2024 17:34:36 +0900 Subject: [PATCH 15/15] feat: improvement preview data --- harmonie/Previews/Models/World.swift | 2 ++ harmonie/Previews/Services/WorldPreviewService.swift | 9 +-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/harmonie/Previews/Models/World.swift b/harmonie/Previews/Models/World.swift index 3465e41..03c1018 100644 --- a/harmonie/Previews/Models/World.swift +++ b/harmonie/Previews/Models/World.swift @@ -58,6 +58,8 @@ extension PreviewData { popularity: 5, heat: 3 ) + + static let worldList = [ bar, casino, fuji, chinatown, nightCity ] } extension World { diff --git a/harmonie/Previews/Services/WorldPreviewService.swift b/harmonie/Previews/Services/WorldPreviewService.swift index 4ef8426..5fda54c 100644 --- a/harmonie/Previews/Services/WorldPreviewService.swift +++ b/harmonie/Previews/Services/WorldPreviewService.swift @@ -14,14 +14,7 @@ final actor WorldPreviewService: APIService, WorldServiceProtocol { let client: APIClient func fetchWorld(worldId: String) async throws -> World { - switch worldId { - case PreviewData.bar.id: - PreviewData.bar - case PreviewData.casino.id: - PreviewData.casino - default: - PreviewData.bar - } + PreviewData.worldList.first { $0.id == worldId } ?? PreviewData.bar } func fetchFavoritedWorlds() async throws -> [FavoriteWorld] {