-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Eric Andrews <[email protected]>
- Loading branch information
1 parent
7d694ab
commit 06ed65e
Showing
8 changed files
with
127 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Mlem/App/Utility/Extensions/Content Models/Community1Providing+Extensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// Community1Providing+Extensions.swift | ||
// Mlem | ||
// | ||
// Created by Sjmarf on 05/05/2024. | ||
// | ||
|
||
import Foundation | ||
import MlemMiddleware | ||
|
||
extension Community1Providing { | ||
private var self2: (any Community2Providing)? { self as? any Community2Providing } | ||
|
||
var subscribeAction: BasicAction { | ||
let isOn: Bool = self2?.subscribed ?? false | ||
return .init( | ||
isOn: isOn, | ||
label: isOn ? "Unsubscribe" : "Subscribe", | ||
color: isOn ? .green : .red, | ||
icon: isOn ? Icons.unsubscribe : Icons.subscribe, | ||
barIcon: Icons.subscribe, | ||
swipeIcon1: isOn ? Icons.unsubscribePerson : Icons.subscribePerson, | ||
swipeIcon2: isOn ? Icons.unsubscribePersonFill : Icons.subscribePersonFill, | ||
callback: api.willSendToken ? self2?.toggleSubscribe : nil | ||
) | ||
} | ||
|
||
var favoriteAction: BasicAction { | ||
let isOn: Bool = self2?.favorited ?? false | ||
return .init( | ||
isOn: isOn, | ||
label: isOn ? "Unfavorite" : "Favorite", | ||
color: .blue, | ||
icon: isOn ? Icons.unfavorite : Icons.favorite, | ||
barIcon: Icons.favorite, | ||
menuIcon: isOn ? Icons.favoriteFill : Icons.favorite, | ||
swipeIcon1: isOn ? Icons.unfavorite : Icons.favorite, | ||
swipeIcon2: isOn ? Icons.unfavoriteFill : Icons.favoriteFill, | ||
callback: api.willSendToken ? self2?.toggleFavorite : nil | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// SubscriptionListView.swift | ||
// Mlem | ||
// | ||
// Created by Sjmarf on 11/05/2024. | ||
// | ||
|
||
import MlemMiddleware | ||
import SwiftUI | ||
|
||
private struct SubscriptionListSection: Identifiable { | ||
let label: String | ||
let communities: [Community2] | ||
|
||
var id: String { label } | ||
} | ||
|
||
private extension SubscriptionList { | ||
var visibleSections: [SubscriptionListSection] { | ||
var sections: [SubscriptionListSection] = .init() | ||
if !favorites.isEmpty { | ||
sections.append(.init(label: "Favorites", communities: favorites)) | ||
} | ||
for section in alphabeticSections.sorted(by: { $0.key ?? "~" < $1.key ?? "~" }) { | ||
sections.append(.init(label: section.key ?? "#", communities: section.value)) | ||
} | ||
return sections | ||
} | ||
} | ||
|
||
struct SubscriptionListView: View { | ||
@Environment(AppState.self) var appState | ||
|
||
var body: some View { | ||
List { | ||
ForEach(appState.firstAccount.subscriptions?.visibleSections ?? .init()) { section in | ||
Section(section.label) { | ||
ForEach(section.communities) { community in | ||
HStack { | ||
Text(community.name) | ||
Spacer() | ||
let action = community.favoriteAction | ||
Button(action: action.callback ?? {}) { | ||
Image(systemName: action.menuIcon) | ||
.foregroundStyle(action.isOn ? action.color : .primary) | ||
} | ||
.buttonStyle(EmptyButtonStyle()) | ||
.disabled(action.callback == nil) | ||
.opacity(action.callback == nil ? 0.5 : 1) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
.listStyle(.plain) | ||
.navigationTitle("Subscription List") | ||
.navigationBarTitleDisplayMode(.inline) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
// | ||
|
||
import Dependencies | ||
import MlemMiddleware | ||
import SwiftUI | ||
|
||
struct ProfileView: View { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters