Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💄 feat: text glow when there's unread message #161

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Swiftcord/Views/Server/ChannelButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ struct ChannelButton: View, Equatable {
}

let channel: Channel
var unread: Bool
@Binding var selectedCh: Channel?

var body: some View {
if channel.type == .dm || channel.type == .groupDM {
DMButton(dm: channel, selectedCh: $selectedCh)
DMButton(dm: channel, unread: unread, selectedCh: $selectedCh)
.buttonStyle(DiscordChannelButton(isSelected: selectedCh?.id == channel.id))
.controlSize(.large)
} else {
GuildChButton(channel: channel, selectedCh: $selectedCh)
GuildChButton(channel: channel, unread: unread, selectedCh: $selectedCh)
.buttonStyle(DiscordChannelButton(isSelected: selectedCh?.id == channel.id))
}
}
}

struct GuildChButton: View {
let channel: Channel
var unread: Bool
@Binding var selectedCh: Channel?

@EnvironmentObject var serverCtx: ServerContext
Expand All @@ -48,12 +50,14 @@ struct GuildChButton: View {
.padding(.vertical, 5)
.padding(.horizontal, 4)
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundColor(unread ? Color(nsColor: .labelColor) : .gray)
}
}
}

struct DMButton: View {
let dm: Channel // swiftlint:disable:this identifier_name
var unread: Bool
@Binding var selectedCh: Channel?

@EnvironmentObject var gateway: DiscordGateway
Expand Down Expand Up @@ -82,6 +86,7 @@ struct DMButton: View {
.font(.caption)
}
}
.foregroundColor(unread ? Color(nsColor: .labelColor) : .gray)
Spacer()
}
.padding(.horizontal, 6)
Expand Down
12 changes: 10 additions & 2 deletions Swiftcord/Views/Server/ChannelList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@ struct ChannelList: View {
@AppStorage("nsfwShown") var nsfwShown: Bool = true
@EnvironmentObject var serverCtx: ServerContext
@EnvironmentObject var gateway: DiscordGateway

private func hasUnreadMsg(for channel: Channel) -> Bool {
if let lastID = gateway.readState[channel.id]?.last_message_id, let _chLastID = channel.last_message_id, let chLastID = Int(_chLastID), lastID.intValue < chLastID {
return true
} else {
return false
}
}

@_transparent @_optimize(speed) @ViewBuilder
private func item(for channel: Channel) -> some View {
ChannelButton(channel: channel, selectedCh: $selCh)
ChannelButton(channel: channel, unread: hasUnreadMsg(for: channel), selectedCh: $selCh)
.equatable()
.listRowInsets(.init(top: 1, leading: 0, bottom: 1, trailing: 0))
.listRowBackground(Spacer().overlay(alignment: .leading) {
// Check if we should show unread indicator
if let lastID = gateway.readState[channel.id]?.last_message_id, let _chLastID = channel.last_message_id, let chLastID = Int(_chLastID), lastID.intValue < chLastID {
if hasUnreadMsg(for: channel) {
Circle().fill(.primary).frame(width: 8, height: 8).offset(x: 2)
}
})
Expand Down