mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-03-28 04:25:28 +00:00
Code cleanup
This commit is contained in:
parent
3e14a92b7d
commit
4783422b3e
8 changed files with 29 additions and 30 deletions
|
@ -176,7 +176,6 @@ extension View {
|
||||||
.environment(PushNotificationsService.shared)
|
.environment(PushNotificationsService.shared)
|
||||||
.environment(AppAccountsManager.shared.currentClient)
|
.environment(AppAccountsManager.shared.currentClient)
|
||||||
.environment(QuickLook.shared)
|
.environment(QuickLook.shared)
|
||||||
.environment(TipedUsers.shared)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func withModelContainer() -> some View {
|
func withModelContainer() -> some View {
|
||||||
|
|
|
@ -25,7 +25,6 @@ extension IceCubesApp {
|
||||||
.environment(pushNotificationsService)
|
.environment(pushNotificationsService)
|
||||||
.environment(appIntentService)
|
.environment(appIntentService)
|
||||||
.environment(\.isSupporter, isSupporter)
|
.environment(\.isSupporter, isSupporter)
|
||||||
.environment(TipedUsers.shared)
|
|
||||||
.sheet(item: $quickLook.selectedMediaAttachment) { selectedMediaAttachment in
|
.sheet(item: $quickLook.selectedMediaAttachment) { selectedMediaAttachment in
|
||||||
MediaUIView(selectedAttachment: selectedMediaAttachment,
|
MediaUIView(selectedAttachment: selectedMediaAttachment,
|
||||||
attachments: quickLook.mediaAttachments)
|
attachments: quickLook.mediaAttachments)
|
||||||
|
|
|
@ -20,7 +20,6 @@ private struct SafariRouter: ViewModifier {
|
||||||
@Environment(UserPreferences.self) private var preferences
|
@Environment(UserPreferences.self) private var preferences
|
||||||
@Environment(RouterPath.self) private var routerPath
|
@Environment(RouterPath.self) private var routerPath
|
||||||
@Environment(AppAccountsManager.self) private var appAccount
|
@Environment(AppAccountsManager.self) private var appAccount
|
||||||
@Environment(TipedUsers.self) private var tipedUsers
|
|
||||||
|
|
||||||
#if !os(visionOS)
|
#if !os(visionOS)
|
||||||
@State private var safariManager = InAppSafariManager()
|
@State private var safariManager = InAppSafariManager()
|
||||||
|
@ -38,7 +37,6 @@ private struct SafariRouter: ViewModifier {
|
||||||
guard !isSecondaryColumn else { return }
|
guard !isSecondaryColumn else { return }
|
||||||
if url.absoluteString == "icecubesapp://socialproxy" {
|
if url.absoluteString == "icecubesapp://socialproxy" {
|
||||||
safariManager.dismiss()
|
safariManager.dismiss()
|
||||||
TipedUsers.shared.tipedUserCount += 1
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let urlString = url.absoluteString.replacingOccurrences(of: AppInfo.scheme, with: "https://")
|
let urlString = url.absoluteString.replacingOccurrences(of: AppInfo.scheme, with: "https://")
|
||||||
|
@ -56,7 +54,9 @@ private struct SafariRouter: ViewModifier {
|
||||||
UIApplication.shared.open(url)
|
UIApplication.shared.open(url)
|
||||||
return .handled
|
return .handled
|
||||||
}
|
}
|
||||||
} else if url.host() == AppInfo.premiumInstance, let accountName = appAccount.currentAccount.accountName {
|
} else if url.query()?.contains("callback=") == false,
|
||||||
|
url.host() == AppInfo.premiumInstance,
|
||||||
|
let accountName = appAccount.currentAccount.accountName {
|
||||||
let newURL = url.appending(queryItems: [
|
let newURL = url.appending(queryItems: [
|
||||||
.init(name: "callback", value: "icecubesapp://socialproxy"),
|
.init(name: "callback", value: "icecubesapp://socialproxy"),
|
||||||
.init(name: "id", value: "@\(accountName)")
|
.init(name: "id", value: "@\(accountName)")
|
||||||
|
|
|
@ -337,7 +337,7 @@ struct AccountDetailHeaderView: View {
|
||||||
.padding(.bottom, 4)
|
.padding(.bottom, 4)
|
||||||
.sheet(isPresented: $isTipSheetPresented) {
|
.sheet(isPresented: $isTipSheetPresented) {
|
||||||
if let account = viewModel.account {
|
if let account = viewModel.account {
|
||||||
TipSheetView(account: account)
|
PremiumAcccountSubsciptionSheetView(account: account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,20 +6,19 @@ import WrappingHStack
|
||||||
import AppAccount
|
import AppAccount
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
struct TipSheetView: View {
|
struct PremiumAcccountSubsciptionSheetView: View {
|
||||||
@Environment(\.dismiss) private var dismiss
|
@Environment(\.dismiss) private var dismiss
|
||||||
@Environment(Theme.self) private var theme: Theme
|
@Environment(Theme.self) private var theme: Theme
|
||||||
@Environment(TipedUsers.self) private var tipedUSers: TipedUsers
|
|
||||||
@Environment(\.openURL) private var openURL
|
@Environment(\.openURL) private var openURL
|
||||||
@Environment(AppAccountsManager.self) private var appAccount: AppAccountsManager
|
@Environment(AppAccountsManager.self) private var appAccount: AppAccountsManager
|
||||||
|
|
||||||
@State private var selectedTip: Int?
|
@State private var isSubscibeSelected: Bool = false
|
||||||
|
|
||||||
private enum TipState: Int, Equatable {
|
private enum SheetState: Int, Equatable {
|
||||||
case selection, preparing, webview
|
case selection, preparing, webview
|
||||||
}
|
}
|
||||||
|
|
||||||
@State private var state: TipState = .selection
|
@State private var state: SheetState = .selection
|
||||||
@State private var animationsending: Bool = false
|
@State private var animationsending: Bool = false
|
||||||
|
|
||||||
let account: Account
|
let account: Account
|
||||||
|
@ -61,7 +60,7 @@ struct TipSheetView: View {
|
||||||
Text("Subscribe to @\(account.username) to get access to exclusive content!")
|
Text("Subscribe to @\(account.username) to get access to exclusive content!")
|
||||||
Button {
|
Button {
|
||||||
withAnimation(.easeInOut(duration: 0.5)) {
|
withAnimation(.easeInOut(duration: 0.5)) {
|
||||||
selectedTip = 500
|
isSubscibeSelected = true
|
||||||
}
|
}
|
||||||
} label: {
|
} label: {
|
||||||
Text("$5 / month")
|
Text("$5 / month")
|
||||||
|
@ -77,7 +76,7 @@ struct TipSheetView: View {
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
if selectedTip != nil {
|
if isSubscibeSelected {
|
||||||
HStack(alignment: .top) {
|
HStack(alignment: .top) {
|
||||||
Text("Subscribe")
|
Text("Subscribe")
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
|
@ -88,7 +87,6 @@ struct TipSheetView: View {
|
||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
.background(theme.tintColor.opacity(0.5))
|
.background(theme.tintColor.opacity(0.5))
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
tipedUSers.usersIds.append(account.id)
|
|
||||||
withAnimation {
|
withAnimation {
|
||||||
state = .preparing
|
state = .preparing
|
||||||
}
|
}
|
||||||
|
@ -123,9 +121,8 @@ struct TipSheetView: View {
|
||||||
.fontWeight(.bold)
|
.fontWeight(.bold)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||||
if let selectedTip,
|
if let accountName = appAccount.currentAccount.accountName,
|
||||||
let accountName = appAccount.currentAccount.accountName,
|
let url = URL(string: "https://\(AppInfo.premiumInstance)/subscribe/to/\(account.username)?callback=icecubesapp://socialproxy&id=@\(accountName)&amount=\(500)¤cy=USD") {
|
||||||
let url = URL(string: "https://\(AppInfo.premiumInstance)/subscribe/to/\(account.username)?callback=icecubesapp://socialproxy&id=@\(accountName)&amount=\(selectedTip)¤cy=USD") {
|
|
||||||
openURL(url)
|
openURL(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,13 +0,0 @@
|
||||||
import Foundation
|
|
||||||
|
|
||||||
@Observable
|
|
||||||
@MainActor
|
|
||||||
public class TipedUsers {
|
|
||||||
public var usersIds: [String] = []
|
|
||||||
|
|
||||||
public var tipedUserCount: Int = 0
|
|
||||||
|
|
||||||
static public let shared = TipedUsers()
|
|
||||||
|
|
||||||
private init() { }
|
|
||||||
}
|
|
|
@ -66,6 +66,7 @@ public struct StatusRowView: View {
|
||||||
} else {
|
} else {
|
||||||
if !isCompact && context != .detail {
|
if !isCompact && context != .detail {
|
||||||
Group {
|
Group {
|
||||||
|
StatusRowPremiumView(viewModel: viewModel)
|
||||||
StatusRowTagView(viewModel: viewModel)
|
StatusRowTagView(viewModel: viewModel)
|
||||||
StatusRowReblogView(viewModel: viewModel)
|
StatusRowReblogView(viewModel: viewModel)
|
||||||
StatusRowReplyView(viewModel: viewModel)
|
StatusRowReplyView(viewModel: viewModel)
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
import DesignSystem
|
||||||
|
import Env
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct StatusRowPremiumView: View {
|
||||||
|
let viewModel: StatusRowViewModel
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if viewModel.status.account.isProAccount {
|
||||||
|
Text("From a subscribed premium account")
|
||||||
|
.font(.scaledFootnote)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue