Skip to content

Commit

Permalink
Improve user item
Browse files Browse the repository at this point in the history
  • Loading branch information
morajabi committed Dec 13, 2024
1 parent 6d2f70a commit 8686814
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
5 changes: 5 additions & 0 deletions apple/InlineKit/Sources/InlineKit/Models/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,9 @@ public extension User {
static func fromTimestamp(from: Int) -> Date {
return Date(timeIntervalSince1970: Double(from))
}

func isCurrentUser() -> Bool {
return self.id == Auth.shared.getCurrentUserId()
}
}

32 changes: 27 additions & 5 deletions apple/InlineMac/Views/Sidebar/UserItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,30 @@ struct UserItem: View {
UserAvatar(user: user, size: Theme.sidebarIconSize)
.padding(.trailing, Theme.sidebarIconSpacing)

VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 3) {
if selected {
text.foregroundColor(.white)
} else {
text.foregroundStyle(
appearsActive ? .primary : .tertiary
)
}
}.animation(.easeInOut(duration: 0.1), value: selected)

// Should we show this in home? probably not, but in space we need it
if user.isCurrentUser() {
if selected {
Text("(You)").foregroundColor(.white.opacity(0.6))
} else {
Text("(You)").foregroundStyle(
appearsActive ? .tertiary : .quaternary
)
}
}
}
.transaction { transaction in
transaction.disablesAnimations = true
}

Spacer()
}
.onHover { isHovered = $0 }
Expand Down Expand Up @@ -74,13 +89,20 @@ struct UserItemButtonStyle: ButtonStyle {
.contentShape(.interaction, .rect(cornerRadius: Theme.sidebarItemRadius))
.padding(.horizontal, Theme.sidebarItemPadding)
.background {
RoundedRectangle(cornerRadius: Theme.sidebarItemRadius)
.fill(backgroundColor(configuration))
Group {
RoundedRectangle(cornerRadius: Theme.sidebarItemRadius)
.fill(backgroundColor(configuration))
}.transaction { transaction in
if selected {
transaction.disablesAnimations = true
transaction.animation = .none
}
}
}
// Optional: Add subtle scale effect when pressed
.scaleEffect(!selected && configuration.isPressed ? 0.98 : 1.0)
// Optional: Add smooth animation for press state
.animation(.easeInOut(duration: 0.1), value: configuration.isPressed)
.animation(.easeInOut(duration: 0.15), value: configuration.isPressed)
}

private func backgroundColor(_ configuration: Configuration) -> Color {
Expand Down

0 comments on commit 8686814

Please sign in to comment.