Skip to content

Commit

Permalink
Admin, Bot, Developer flairs in PersonView (#1506)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf authored Dec 17, 2024
1 parent bdd39c7 commit 35f9def
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2946,8 +2946,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/mlemgroup/MlemMiddleware";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.52.0;
kind = upToNextMinorVersion;
minimumVersion = 0.53.0;
};
};
CDE4AC402CA3706400981010 /* XCRemoteSwiftPackageReference "SDWebImageSwiftUI" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/mlemgroup/MlemMiddleware",
"state" : {
"revision" : "51db2875046e216fb01c8233cc43eadd147dd240",
"version" : "0.52.0"
"revision" : "a4dc838d0ff82ea76b71ee9e9568743d957e15a0",
"version" : "0.53.0"
}
},
{
Expand Down
48 changes: 48 additions & 0 deletions Mlem/App/Views/Pages/Person/PersonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Sjmarf on 30/05/2024.
//

import Flow
import LemmyMarkdownUI
import MlemMiddleware
import SwiftUI
Expand Down Expand Up @@ -36,10 +37,12 @@ struct PersonView: View {
@State private var selectedContentType: PersonContentType = .all
@State private var isAtTop: Bool = true
@State var feedLoader: PersonContentFeedLoader?
@State var isAdmin: Bool
let isProfileTab: Bool

init(person: AnyPerson, isProfileTab: Bool = false) {
self._person = .init(wrappedValue: person)
self._isAdmin = .init(wrappedValue: person.wrappedValue.isAdmin_ ?? false)
self.isProfileTab = isProfileTab

if let person1 = person.wrappedValue as? any Person1Providing, person1.api === AppState.main.firstApi {
Expand Down Expand Up @@ -114,6 +117,12 @@ struct PersonView: View {
}
return try await entity.upgrade()
}
// This prevents the admin flair from disappearing if the `ContentLoader`
// switches from an external ApiClient to the active ApiClient, e.g. when
// navigating to `PersonView` from the administrator list in `InstanceView`.
if model.wrappedValue.isAdmin_ ?? false {
isAdmin = true
}
}
.navigationTitle(isAtTop ? "" : (person.wrappedValue.displayName_ ?? person.wrappedValue.name))
.navigationBarTitleDisplayMode(.inline)
Expand All @@ -125,6 +134,7 @@ struct PersonView: View {
VStack(spacing: 0) {
VStack(spacing: Constants.main.standardSpacing) {
ProfileHeaderView(person, fallback: .person)
flairsView(person: person)
bio(person: person)
}
.padding([.horizontal], Constants.main.standardSpacing)
Expand Down Expand Up @@ -175,6 +185,27 @@ struct PersonView: View {
}
}

@ViewBuilder
func flairsView(person: any Person) -> some View {
if person.isBot || person.isMlemDeveloper || isAdmin {
HFlow(spacing: Constants.main.halfSpacing) {
if person.isMlemDeveloper {
Label("Mlem Developer", systemImage: Icons.developerFlair)
.tint(palette.colorfulAccent(4))
}
if isAdmin {
Label("\(person.host ?? "") Administrator", systemImage: Icons.adminFlair)
.tint(palette.administration)
}
if person.isBot {
Label("Bot Account", systemImage: Icons.botFlair)
.tint(palette.colorfulAccent(5))
}
}
.labelStyle(FlairLabelStyle())
}
}

@ViewBuilder
func dateLabel(person: any Person) -> some View {
ProfileDateView(profilable: person)
Expand Down Expand Up @@ -233,3 +264,20 @@ struct PersonView: View {
.padding([.horizontal, .bottom], Constants.main.standardSpacing)
}
}

private struct FlairLabelStyle: LabelStyle {
@Environment(Palette.self) private var palette

func makeBody(configuration: Configuration) -> some View {
HStack(spacing: 5) {
configuration.icon
.imageScale(.small)
configuration.title
}
.font(.footnote)
.padding(.vertical, 2)
.padding(.horizontal, 8)
.foregroundStyle(.tint)
.background(.tint.opacity(0.2), in: .capsule)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI

struct SquircleLabelStyle: LabelStyle {
@Environment(Palette.self) private var palette

func makeBody(configuration: Configuration) -> some View {
HStack(alignment: .center, spacing: 16) {
configuration.icon
Expand Down
3 changes: 3 additions & 0 deletions Mlem/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
}
}
}
},
"%@ Administrator" : {

},
"%@ has been unresponsive recently." : {

Expand Down

0 comments on commit 35f9def

Please sign in to comment.