From d2b84afead9aff244dbf31cba9a7b24d4a979f46 Mon Sep 17 00:00:00 2001 From: makinosp Date: Fri, 15 Nov 2024 23:34:32 +0900 Subject: [PATCH] refact: code refactoring --- .../Setting/Profile/ProfileEditView.swift | 86 ++++++++++--------- harmonie/Views/Setting/SettingsView.swift | 2 +- harmonie/Views/UserDetail/NoteEditView.swift | 2 +- .../UserDetail/UserDetailView+Actions.swift | 20 ----- .../UserDetailView+LocationSection.swift | 24 +++--- .../UserDetailView+OverlayViews.swift | 4 +- .../Views/UserDetail/UserDetailView.swift | 13 ++- .../Views/World/WorldPresentationView.swift | 2 +- harmonie/Views/World/WorldView+Toolbar.swift | 2 +- 9 files changed, 75 insertions(+), 80 deletions(-) delete mode 100644 harmonie/Views/UserDetail/UserDetailView+Actions.swift diff --git a/harmonie/Views/Setting/Profile/ProfileEditView.swift b/harmonie/Views/Setting/Profile/ProfileEditView.swift index 07c7523d..b1d0cca7 100644 --- a/harmonie/Views/Setting/Profile/ProfileEditView.swift +++ b/harmonie/Views/Setting/Profile/ProfileEditView.swift @@ -86,60 +86,64 @@ struct ProfileEditView: View { } } - @ViewBuilder private var languageSection: some View { - Section("Language") { - ForEach(profileEditVM.editingUserInfo.tags.languageTags) { tag in - Text(tag.description) - .swipeActions { - Button(role: .destructive) { - profileEditVM.removeTag(tag) - } label: { - Text("Delete") + private var languageSection: some View { + Group { + Section("Language") { + ForEach(profileEditVM.editingUserInfo.tags.languageTags) { tag in + Text(tag.description) + .swipeActions { + Button(role: .destructive) { + profileEditVM.removeTag(tag) + } label: { + Text("Delete") + } } - } + } } - } - Section { - Button { - isPresentedLanguagePicker = true - } label: { - Label { - Text("Add") - } icon: { - IconSet.plusCircleFilled.icon.symbolRenderingMode(.multicolor) + Section { + Button { + isPresentedLanguagePicker = true + } label: { + Label { + Text("Add") + } icon: { + IconSet.plusCircleFilled.icon.symbolRenderingMode(.multicolor) + } } } + .listSectionSpacing(.compact) } - .listSectionSpacing(.compact) } - @ViewBuilder private var bioLinksSection: some View { - Section("Social Links") { - ForEach(profileEditVM.editingUserInfo.bioLinks) { url in - Link(destination: url) { - Label(url.description, systemImage: IconSet.link.systemName) - } - .swipeActions { - Button(role: .destructive) { - profileEditVM.removeUrl(url) - } label: { - Text("Delete") + private var bioLinksSection: some View { + Group { + Section("Social Links") { + ForEach(profileEditVM.editingUserInfo.bioLinks) { url in + Link(destination: url) { + Label(url.description, systemImage: IconSet.link.systemName) + } + .swipeActions { + Button(role: .destructive) { + profileEditVM.removeUrl(url) + } label: { + Text("Delete") + } } } } - } - Section { - Button { - isPresentedURLEditor = true - } label: { - Label { - Text("Add") - } icon: { - IconSet.plusCircleFilled.icon.symbolRenderingMode(.multicolor) + Section { + Button { + isPresentedURLEditor = true + } label: { + Label { + Text("Add") + } icon: { + IconSet.plusCircleFilled.icon.symbolRenderingMode(.multicolor) + } } } + .listSectionSpacing(.compact) } - .listSectionSpacing(.compact) } @ToolbarContentBuilder private var toolbarContents: some ToolbarContent { diff --git a/harmonie/Views/Setting/SettingsView.swift b/harmonie/Views/Setting/SettingsView.swift index ec34aa17..ec15b0a0 100644 --- a/harmonie/Views/Setting/SettingsView.swift +++ b/harmonie/Views/Setting/SettingsView.swift @@ -76,7 +76,7 @@ struct SettingsView: View { } } - var aboutThisApp: some View { + private var aboutThisApp: some View { List { LabeledContent { Text(BundleUtil.appName) diff --git a/harmonie/Views/UserDetail/NoteEditView.swift b/harmonie/Views/UserDetail/NoteEditView.swift index a9361f08..d5fc90c3 100644 --- a/harmonie/Views/UserDetail/NoteEditView.swift +++ b/harmonie/Views/UserDetail/NoteEditView.swift @@ -60,7 +60,7 @@ struct NoteEditView: View { } } - func saveAction() async { + private func saveAction() async { defer { isRequesting = false } isRequesting = true do { diff --git a/harmonie/Views/UserDetail/UserDetailView+Actions.swift b/harmonie/Views/UserDetail/UserDetailView+Actions.swift deleted file mode 100644 index 4ad3f1e9..00000000 --- a/harmonie/Views/UserDetail/UserDetailView+Actions.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// UserDetailView+Actions.swift -// Harmonie -// -// Created by makinosp on 2024/08/11. -// - -import VRCKit - -extension UserDetailView { - func fetchInstance(id: String) async { - do { - defer { isRequesting = false } - isRequesting = true - instance = try await appVM.services.instanceService.fetchInstance(location: id) - } catch { - appVM.handleError(error) - } - } -} diff --git a/harmonie/Views/UserDetail/UserDetailView+LocationSection.swift b/harmonie/Views/UserDetail/UserDetailView+LocationSection.swift index 75616721..c3775d00 100644 --- a/harmonie/Views/UserDetail/UserDetailView+LocationSection.swift +++ b/harmonie/Views/UserDetail/UserDetailView+LocationSection.swift @@ -10,6 +10,18 @@ import SwiftUI import VRCKit extension UserDetailView { + var locationSection: some View { + GroupBox("Location") { + HStack { + SquareURLImage(imageUrl: locationImageUrl) + Text(locationDescription) + .font(.headline) + } + .redacted(reason: isRequesting ? .placeholder : []) + } + .groupBoxStyle(.card) + } + private var locationDescription: String { if let instance = instance { instance.world.name @@ -36,16 +48,4 @@ extension UserDetailView { Const.offlineImageUrl } } - - var locationSection: some View { - GroupBox("Location") { - HStack { - SquareURLImage(imageUrl: locationImageUrl) - Text(locationDescription) - .font(.headline) - } - .redacted(reason: isRequesting ? .placeholder : []) - } - .groupBoxStyle(.card) - } } diff --git a/harmonie/Views/UserDetail/UserDetailView+OverlayViews.swift b/harmonie/Views/UserDetail/UserDetailView+OverlayViews.swift index 2d92257f..aa243a46 100644 --- a/harmonie/Views/UserDetail/UserDetailView+OverlayViews.swift +++ b/harmonie/Views/UserDetail/UserDetailView+OverlayViews.swift @@ -47,7 +47,7 @@ extension UserDetailView { } } - var status: some View { + private var status: some View { Label { Text(statusDescription) } icon: { @@ -61,7 +61,7 @@ extension UserDetailView { .font(.subheadline) } - var trustRankLabel: some View { + private var trustRankLabel: some View { Label { Text(user.trustRank.description) } icon: { diff --git a/harmonie/Views/UserDetail/UserDetailView.swift b/harmonie/Views/UserDetail/UserDetailView.swift index e5723072..7b995b03 100644 --- a/harmonie/Views/UserDetail/UserDetailView.swift +++ b/harmonie/Views/UserDetail/UserDetailView.swift @@ -55,7 +55,7 @@ struct UserDetailView: View { } } - @ToolbarContentBuilder var toolbar: some ToolbarContent { + @ToolbarContentBuilder private var toolbar: some ToolbarContent { ToolbarItem { UserDetailToolbarMenu(user: user) } } @@ -76,6 +76,17 @@ struct UserDetailView: View { activitySection } } + + private func fetchInstance(id: String) async { + do { + defer { isRequesting = false } + isRequesting = true + let service = appVM.services.instanceService + instance = try await service.fetchInstance(location: id) + } catch { + appVM.handleError(error) + } + } } #Preview { diff --git a/harmonie/Views/World/WorldPresentationView.swift b/harmonie/Views/World/WorldPresentationView.swift index 60447618..abb0b5a8 100644 --- a/harmonie/Views/World/WorldPresentationView.swift +++ b/harmonie/Views/World/WorldPresentationView.swift @@ -12,7 +12,7 @@ import VRCKit @MemberwiseInit struct WorldPresentationView: View { @Environment(AppViewModel.self) var appVM - @State var world: World? + @State private var world: World? @Init(.internal) private let id: String var body: some View { diff --git a/harmonie/Views/World/WorldView+Toolbar.swift b/harmonie/Views/World/WorldView+Toolbar.swift index 51385d30..73a5c8c5 100644 --- a/harmonie/Views/World/WorldView+Toolbar.swift +++ b/harmonie/Views/World/WorldView+Toolbar.swift @@ -64,7 +64,7 @@ extension WorldView { } } - func updateFavoriteAction(world: World, group: FavoriteGroup) async { + private func updateFavoriteAction(world: World, group: FavoriteGroup) async { isRequesting = true defer { isRequesting = false } do {