mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-25 17:51:01 +00:00
Share + Fixed logged out mode
This commit is contained in:
parent
6e8ed998d4
commit
7068ad90bb
5 changed files with 54 additions and 32 deletions
|
@ -4,6 +4,7 @@ import Env
|
|||
import Network
|
||||
|
||||
struct TimelineTab: View {
|
||||
@EnvironmentObject private var client: Client
|
||||
@StateObject private var routeurPath = RouterPath()
|
||||
|
||||
var body: some View {
|
||||
|
@ -12,13 +13,14 @@ struct TimelineTab: View {
|
|||
.withAppRouteur()
|
||||
.withSheetDestinations(sheetDestinations: $routeurPath.presentedSheet)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
Button {
|
||||
routeurPath.presentedSheet = .statusEditor(replyToStatus: nil)
|
||||
} label: {
|
||||
Image(systemName: "square.and.pencil")
|
||||
if client.isAuth {
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
Button {
|
||||
routeurPath.presentedSheet = .statusEditor(replyToStatus: nil)
|
||||
} label: {
|
||||
Image(systemName: "square.and.pencil")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,10 +11,11 @@ public protocol AnyStatus {
|
|||
var reblogsCount: Int { get }
|
||||
var favouritesCount: Int { get }
|
||||
var card: Card? { get }
|
||||
var favourited: Bool { get }
|
||||
var reblogged: Bool { get }
|
||||
var favourited: Bool? { get }
|
||||
var reblogged: Bool? { get }
|
||||
var pinned: Bool? { get }
|
||||
var emojis: [Emoji] { get }
|
||||
var url: URL? { get }
|
||||
}
|
||||
|
||||
public struct Status: AnyStatus, Codable, Identifiable {
|
||||
|
@ -29,10 +30,11 @@ public struct Status: AnyStatus, Codable, Identifiable {
|
|||
public let reblogsCount: Int
|
||||
public let favouritesCount: Int
|
||||
public let card: Card?
|
||||
public let favourited: Bool
|
||||
public let reblogged: Bool
|
||||
public let favourited: Bool?
|
||||
public let reblogged: Bool?
|
||||
public let pinned: Bool?
|
||||
public let emojis: [Emoji]
|
||||
public let url: URL?
|
||||
|
||||
public static func placeholder() -> Status {
|
||||
.init(id: UUID().uuidString,
|
||||
|
@ -49,7 +51,8 @@ public struct Status: AnyStatus, Codable, Identifiable {
|
|||
favourited: false,
|
||||
reblogged: false,
|
||||
pinned: false,
|
||||
emojis: [])
|
||||
emojis: [],
|
||||
url: nil)
|
||||
}
|
||||
|
||||
public static func placeholders() -> [Status] {
|
||||
|
@ -68,8 +71,9 @@ public struct ReblogStatus: AnyStatus, Codable, Identifiable {
|
|||
public let reblogsCount: Int
|
||||
public let favouritesCount: Int
|
||||
public let card: Card?
|
||||
public let favourited: Bool
|
||||
public let reblogged: Bool
|
||||
public let favourited: Bool?
|
||||
public let reblogged: Bool?
|
||||
public let pinned: Bool?
|
||||
public let emojis: [Emoji]
|
||||
public let url: URL?
|
||||
}
|
||||
|
|
|
@ -41,18 +41,24 @@ struct StatusActionsView: View {
|
|||
var body: some View {
|
||||
HStack {
|
||||
ForEach(Actions.allCases, id: \.self) { action in
|
||||
Button {
|
||||
handleAction(action: action)
|
||||
} label: {
|
||||
HStack(spacing: 2) {
|
||||
Image(systemName: action.iconName(viewModel: viewModel))
|
||||
if let count = action.count(viewModel: viewModel) {
|
||||
Text("\(count)")
|
||||
.font(.footnote)
|
||||
if action == .share {
|
||||
if let url = viewModel.status.reblog?.url ?? viewModel.status.url {
|
||||
ShareLink(item: url) {
|
||||
Image(systemName: action.iconName(viewModel: viewModel))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Button {
|
||||
handleAction(action: action)
|
||||
} label: {
|
||||
HStack(spacing: 2) {
|
||||
Image(systemName: action.iconName(viewModel: viewModel))
|
||||
if let count = action.count(viewModel: viewModel) {
|
||||
Text("\(count)")
|
||||
.font(.footnote)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if action != .share {
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,15 +18,20 @@ public class StatusRowViewModel: ObservableObject {
|
|||
public init(status: Status, isEmbed: Bool) {
|
||||
self.status = status
|
||||
self.isEmbed = isEmbed
|
||||
self.isFavourited = status.reblog?.favourited ?? status.favourited
|
||||
if let reblog = status.reblog {
|
||||
self.isFavourited = reblog.favourited == true
|
||||
self.isReblogged = reblog.reblogged == true
|
||||
} else {
|
||||
self.isFavourited = status.favourited == true
|
||||
self.isReblogged = status.reblogged == true
|
||||
}
|
||||
self.favouritesCount = status.reblog?.favouritesCount ?? status.favouritesCount
|
||||
self.isReblogged = status.reblog?.reblogged ?? status.reblogged
|
||||
self.reblogsCount = status.reblog?.reblogsCount ?? status.reblogsCount
|
||||
self.repliesCount = status.reblog?.repliesCount ?? status.repliesCount
|
||||
}
|
||||
|
||||
func favourite() async {
|
||||
guard let client else { return }
|
||||
guard let client, client.isAuth else { return }
|
||||
isFavourited = true
|
||||
favouritesCount += 1
|
||||
do {
|
||||
|
@ -39,7 +44,7 @@ public class StatusRowViewModel: ObservableObject {
|
|||
}
|
||||
|
||||
func unFavourite() async {
|
||||
guard let client else { return }
|
||||
guard let client, client.isAuth else { return }
|
||||
isFavourited = false
|
||||
favouritesCount -= 1
|
||||
do {
|
||||
|
@ -52,7 +57,7 @@ public class StatusRowViewModel: ObservableObject {
|
|||
}
|
||||
|
||||
func reblog() async {
|
||||
guard let client else { return }
|
||||
guard let client, client.isAuth else { return }
|
||||
isReblogged = true
|
||||
reblogsCount += 1
|
||||
do {
|
||||
|
@ -65,7 +70,7 @@ public class StatusRowViewModel: ObservableObject {
|
|||
}
|
||||
|
||||
func unReblog() async {
|
||||
guard let client else { return }
|
||||
guard let client, client.isAuth else { return }
|
||||
isReblogged = false
|
||||
reblogsCount -= 1
|
||||
do {
|
||||
|
@ -78,9 +83,14 @@ public class StatusRowViewModel: ObservableObject {
|
|||
}
|
||||
|
||||
private func updateFromStatus(status: Status) {
|
||||
isFavourited = status.reblog?.favourited ?? status.favourited
|
||||
if let reblog = status.reblog {
|
||||
isFavourited = reblog.favourited == true
|
||||
isReblogged = reblog.reblogged == true
|
||||
} else {
|
||||
isFavourited = status.favourited == true
|
||||
isReblogged = status.reblogged == true
|
||||
}
|
||||
favouritesCount = status.reblog?.favouritesCount ?? status.favouritesCount
|
||||
isReblogged = status.reblog?.reblogged ?? status.reblogged
|
||||
reblogsCount = status.reblog?.reblogsCount ?? status.reblogsCount
|
||||
repliesCount = status.reblog?.repliesCount ?? status.repliesCount
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public struct TimelineView: View {
|
|||
.navigationTitle(filter?.title() ?? viewModel.timeline.title())
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
if filter == nil {
|
||||
if filter == nil, client.isAuth {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
timelineFilterButton
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue