Edit tag groups

This commit is contained in:
Thomas Ricouard 2023-08-04 12:40:21 +02:00
parent 559e1d0c83
commit 4280764733
25 changed files with 77 additions and 20 deletions

View File

@ -106,7 +106,7 @@
E9DF420129830FEC0003AAD2 /* ActionRequestHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9DF420029830FEC0003AAD2 /* ActionRequestHandler.swift */; };
E9DF420329830FEC0003AAD2 /* Action.js in Resources */ = {isa = PBXBuildFile; fileRef = E9DF420229830FEC0003AAD2 /* Action.js */; };
E9DF420729830FEC0003AAD2 /* IceCubesActionExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = E9DF41FA29830FEC0003AAD2 /* IceCubesActionExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
FA31A9AB2A66BF7C00D5F662 /* AddTagGroupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA31A9AA2A66BF7C00D5F662 /* AddTagGroupView.swift */; };
FA31A9AB2A66BF7C00D5F662 /* EditTagGroupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA31A9AA2A66BF7C00D5F662 /* EditTagGroupView.swift */; };
FAD203D02A66D8A80030A7FD /* Symbols.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD203CF2A66D8A80030A7FD /* Symbols.swift */; };
/* End PBXBuildFile section */
@ -275,7 +275,7 @@
E9DF420229830FEC0003AAD2 /* Action.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = Action.js; sourceTree = "<group>"; };
E9DF420429830FEC0003AAD2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F355EEDA297A8BD500E362C0 /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Localizable.strings; sourceTree = "<group>"; };
FA31A9AA2A66BF7C00D5F662 /* AddTagGroupView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddTagGroupView.swift; sourceTree = "<group>"; };
FA31A9AA2A66BF7C00D5F662 /* EditTagGroupView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditTagGroupView.swift; sourceTree = "<group>"; };
FAD203CF2A66D8A80030A7FD /* Symbols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Symbols.swift; sourceTree = "<group>"; };
FF8259FB298E42E000BEAB69 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Localizable.strings; sourceTree = "<group>"; };
FF8259FC298E42E000BEAB69 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/InfoPlist.strings; sourceTree = "<group>"; };
@ -407,7 +407,7 @@
children = (
9F398AB229360A4C00A889F2 /* TimelineTab.swift */,
9F7335F12967608F00AFF0BA /* AddRemoteTimelineView.swift */,
FA31A9AA2A66BF7C00D5F662 /* AddTagGroupView.swift */,
FA31A9AA2A66BF7C00D5F662 /* EditTagGroupView.swift */,
FAD203CF2A66D8A80030A7FD /* Symbols.swift */,
);
path = Timeline;
@ -839,7 +839,7 @@
9F7335F92968576500AFF0BA /* DisplaySettingsView.swift in Sources */,
9F2A540729699698009B2D7C /* SupportAppView.swift in Sources */,
9F2B92F6295AE04800DE16D0 /* Tabs.swift in Sources */,
FA31A9AB2A66BF7C00D5F662 /* AddTagGroupView.swift in Sources */,
FA31A9AB2A66BF7C00D5F662 /* EditTagGroupView.swift in Sources */,
FAD203D02A66D8A80030A7FD /* Symbols.swift in Sources */,
9F398AB329360A4C00A889F2 /* TimelineTab.swift in Sources */,
9F398AA62935FE8A00A889F2 /* AppRouter.swift in Sources */,

View File

@ -83,7 +83,7 @@ extension View {
AddRemoteTimelineView()
.withEnvironments()
case .addTagGroup:
AddTagGroupView()
EditTagGroupView()
.withEnvironments()
case let .statusEditHistory(status):
StatusEditHistoryView(statusId: status)
@ -104,6 +104,9 @@ extension View {
.withEnvironments()
case let .shareImage(image, status):
ActivityView(image: image, status: status)
case let .editTagGroup(tagGroup, onSaved):
EditTagGroupView(editingTagGroup: tagGroup, onSaved: onSaved)
.withEnvironments()
}
}
}

View File

@ -269,6 +269,9 @@ struct SettingsTabs: View {
Form {
ForEach(preferences.tagGroups, id: \.self) { group in
Label(group.title, systemImage: group.sfSymbolName)
.onTapGesture {
routerPath.presentedSheet = .editTagGroup(tagGroup: group, onSaved: nil)
}
}
.onDelete { indexes in
if let index = indexes.first {

View File

@ -7,7 +7,7 @@ import NukeUI
import Shimmer
import SwiftUI
struct AddTagGroupView: View {
struct EditTagGroupView: View {
@Environment(\.dismiss) private var dismiss
@EnvironmentObject private var preferences: UserPreferences
@ -19,6 +19,9 @@ struct AddTagGroupView: View {
@State private var newTag: String = ""
@State private var popupTagsPresented = false
private var editingTagGroup: TagGroup?
private var onSaved: ((TagGroup) -> Void)?
private var canSave: Bool {
!title.isEmpty &&
// At least have 2 tags, one main and one additional.
@ -32,6 +35,11 @@ struct AddTagGroupView: View {
case symbol
case new
}
init(editingTagGroup: TagGroup? = nil, onSaved: ((TagGroup) -> Void)? = nil) {
self.editingTagGroup = editingTagGroup
self.onSaved = onSaved
}
var body: some View {
NavigationStack {
@ -41,7 +49,7 @@ struct AddTagGroupView: View {
keywordsSection
}
.formStyle(.grouped)
.navigationTitle("timeline.filter.add-tag-groups")
.navigationTitle(editingTagGroup != nil ? "timeline.filter.edit-tag-groups" : "timeline.filter.add-tag-groups")
.navigationBarTitleDisplayMode(.inline)
.scrollContentBackground(.hidden)
.background(theme.secondaryBackgroundColor)
@ -59,6 +67,11 @@ struct AddTagGroupView: View {
}
.onAppear {
focusedField = .title
if let editingTagGroup {
title = editingTagGroup.title
sfSymbolName = editingTagGroup.sfSymbolName
tags = editingTagGroup.tags
}
}
}
}
@ -150,14 +163,22 @@ struct AddTagGroupView: View {
private func save() {
var toSave = tags
let main = toSave.removeFirst()
preferences.tagGroups.append(.init(
let tagGroup: TagGroup = .init(
title: title.trimmingCharacters(in: .whitespaces),
sfSymbolName: sfSymbolName,
main: main,
additional: toSave
))
)
if let editingTagGroup,
let index = preferences.tagGroups.firstIndex(of: editingTagGroup) {
preferences.tagGroups[index] = tagGroup
} else {
preferences.tagGroups.append(tagGroup)
}
dismiss()
onSaved?(tagGroup)
}
@ViewBuilder
@ -189,7 +210,7 @@ struct AddTagGroupView: View {
struct AddTagGroupView_Previews: PreviewProvider {
static var previews: some View {
AddTagGroupView()
EditTagGroupView()
.withEnvironments()
}
}

View File

@ -248,6 +248,7 @@
"timeline.filter.tags" = "Адсочваемыя тэгі";
"timeline.filter.tag-groups" = "Tag Groups";
"timeline.filter.add-tag-groups" = "Add tag group";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Дадаць уліковы запіс";

View File

@ -242,6 +242,7 @@
"timeline.filter.tags" = "Etiquetes seguides";
"timeline.filter.tag-groups" = "Grups d'Etiquetes";
"timeline.filter.add-tag-groups" = "Afegeix grup";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Afegeix un compte";

View File

@ -245,6 +245,7 @@
"timeline.filter.tags" = "Gefolgte Hashtags";
"timeline.filter.tag-groups" = "Taggruppen";
"timeline.filter.add-tag-groups" = "Taggruppe hinzufügen";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Konto hinzufügen";

View File

@ -246,6 +246,7 @@
"timeline.filter.tags" = "Followed Tags";
"timeline.filter.tag-groups" = "Tag Groups";
"timeline.filter.add-tag-groups" = "Add tag group";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Add Account";

View File

@ -244,6 +244,7 @@
"timeline.filter.tags" = "Followed Tags";
"timeline.filter.tag-groups" = "Tag Groups";
"timeline.filter.add-tag-groups" = "Add tag group";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Add Account";

View File

@ -244,6 +244,7 @@
"timeline.filter.tags" = "Etiquetas que sigues";
"timeline.filter.tag-groups" = "Grupos de Etiquetas";
"timeline.filter.add-tag-groups" = "Añadir grupo";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Añadir cuenta";

View File

@ -245,6 +245,7 @@
"timeline.filter.tags" = "Jarraitutako traolak";
"timeline.filter.tag-groups" = "Traola-sortak";
"timeline.filter.add-tag-groups" = "Gehitu traola-sorta";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Gehitu kontua";

View File

@ -243,6 +243,7 @@
"timeline.filter.tags" = "Tags suivis";
"timeline.filter.tag-groups" = "Tag Groups";
"timeline.filter.add-tag-groups" = "Add tag group";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Ajouter un compte";

View File

@ -242,6 +242,7 @@
"timeline.filter.tags" = "Tag seguiti";
"timeline.filter.tag-groups" = "Tag Groups";
"timeline.filter.add-tag-groups" = "Add tag group";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Aggiungi account";

View File

@ -243,6 +243,7 @@
"timeline.filter.tags" = "フォローしたタグ";
"timeline.filter.tag-groups" = "Tag Groups";
"timeline.filter.add-tag-groups" = "Add tag group";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "アカウントの追加";

View File

@ -244,6 +244,7 @@
"timeline-new-posts %lld" = "%lld개 새 글";
"timeline.filter.tag-groups" = "태그 모음";
"timeline.filter.add-tag-groups" = "태그 모음 추가";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "계정 추가";

View File

@ -243,6 +243,7 @@
"timeline.filter.tags" = "Fulgte tagger";
"timeline.filter.tag-groups" = "Tag Groups";
"timeline.filter.add-tag-groups" = "Add tag group";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Legg til konto";

View File

@ -240,6 +240,7 @@
"timeline.filter.tags" = "Gevolgde hashtags";
"timeline.filter.tag-groups" = "Tag Groups";
"timeline.filter.add-tag-groups" = "Add tag group";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Account toevoegen";

View File

@ -243,6 +243,7 @@
"timeline.filter.tags" = "Obserwowane hasztagi";
"timeline.filter.tag-groups" = "Grupy hasztagów";
"timeline.filter.add-tag-groups" = "Dodaj grupę hasztagów";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Dodaj konto";

View File

@ -243,6 +243,7 @@
"timeline.filter.tags" = "Hashtags Seguidas";
"timeline.filter.tag-groups" = "Tag Groups";
"timeline.filter.add-tag-groups" = "Add tag group";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Adicionar Conta";

View File

@ -243,6 +243,7 @@
"timeline.filter.tags" = "Takip Edilen Etiketler";
"timeline.filter.tag-groups" = "Tag Groups";
"timeline.filter.add-tag-groups" = "Add tag group";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Hesap Ekle";

View File

@ -244,6 +244,7 @@
"timeline.filter.tags" = "Хештеґи";
"timeline.filter.tag-groups" = "Tag Groups";
"timeline.filter.add-tag-groups" = "Add tag group";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "Додати обліковий запис";

View File

@ -241,6 +241,7 @@
"timeline.filter.tags" = "关注的标签";
"timeline.filter.tag-groups" = "标签组";
"timeline.filter.add-tag-groups" = "新建标签组";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "添加账户";

View File

@ -245,6 +245,7 @@
"timeline.filter.tags" = "跟隨標籤";
"timeline.filter.tag-groups" = "Tag Groups";
"timeline.filter.add-tag-groups" = "Add tag group";
"timeline.filter.edit-tag-groups" = "Edit tag group";
// MARK: Package: AppAccount
"app-account.button.add" = "新增帳號";

View File

@ -39,6 +39,7 @@ public enum SheetDestination: Identifiable {
case accountPushNotficationsSettings
case report(status: Status)
case shareImage(image: UIImage, status: Status)
case editTagGroup(tagGroup: TagGroup, onSaved: ((TagGroup) -> Void)?)
public var id: String {
switch self {
@ -61,6 +62,8 @@ public enum SheetDestination: Identifiable {
return "report"
case .shareImage:
return "shareImage"
case .editTagGroup:
return "editTagGroup"
}
}
}

View File

@ -212,20 +212,28 @@ public struct TimelineView: View {
private var tagGroupHeaderView: some View {
if let group = viewModel.tagGroup {
headerView {
ScrollView(.horizontal) {
HStack(spacing: 4) {
ForEach(group.tags, id: \.self) { tag in
Button {
routerPath.navigate(to: .hashTag(tag: tag, account: nil))
} label: {
Text("#\(tag)")
.font(.scaledHeadline)
HStack {
ScrollView(.horizontal) {
HStack(spacing: 4) {
ForEach(group.tags, id: \.self) { tag in
Button {
routerPath.navigate(to: .hashTag(tag: tag, account: nil))
} label: {
Text("#\(tag)")
.font(.scaledHeadline)
}
.buttonStyle(.plain)
}
.buttonStyle(.plain)
}
}
.scrollIndicators(.hidden)
Button("status.action.edit") {
routerPath.presentedSheet = .editTagGroup(tagGroup: group, onSaved: { group in
viewModel.timeline = .tagGroup(group)
})
}
.buttonStyle(.bordered)
}
.scrollIndicators(.hidden)
}
}
}