mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 04:04:07 +00:00
Add support for Piped accounts and subscriptions
This commit is contained in:
@@ -52,7 +52,7 @@ struct FavoriteItemView: View {
|
||||
.opacity(dragging?.id == item.id ? 0.5 : 1)
|
||||
.onAppear {
|
||||
resource?.addObserver(store)
|
||||
resource?.loadIfNeeded()
|
||||
resource?.load()
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.onDrag {
|
||||
|
@@ -15,7 +15,7 @@ struct AccountsMenuView: View {
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Label(model.current?.name ?? "Select Account", systemImage: "person.crop.circle")
|
||||
Label(model.current?.description ?? "Select Account", systemImage: "person.crop.circle")
|
||||
.labelStyle(.titleAndIcon)
|
||||
}
|
||||
.disabled(instances.isEmpty)
|
||||
|
@@ -30,9 +30,6 @@ struct AppSidebarPlaylists: View {
|
||||
newPlaylistButton
|
||||
.padding(.top, 8)
|
||||
}
|
||||
.onAppear {
|
||||
playlists.load()
|
||||
}
|
||||
}
|
||||
|
||||
var newPlaylistButton: some View {
|
||||
|
@@ -22,8 +22,5 @@ struct AppSidebarSubscriptions: View {
|
||||
.id("channel\(channel.id)")
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
subscriptions.load()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,8 @@ import SwiftUI
|
||||
struct Sidebar: View {
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<PlaylistsModel> private var playlists
|
||||
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
||||
|
||||
var body: some View {
|
||||
ScrollViewReader { scrollView in
|
||||
@@ -13,12 +15,25 @@ struct Sidebar: View {
|
||||
AppSidebarRecents()
|
||||
.id("recentlyOpened")
|
||||
|
||||
if accounts.signedIn {
|
||||
AppSidebarSubscriptions()
|
||||
AppSidebarPlaylists()
|
||||
if accounts.api.signedIn {
|
||||
if accounts.app.supportsSubscriptions {
|
||||
AppSidebarSubscriptions()
|
||||
}
|
||||
|
||||
if accounts.app.supportsUserPlaylists {
|
||||
AppSidebarPlaylists()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
subscriptions.load()
|
||||
playlists.load()
|
||||
}
|
||||
.onChange(of: accounts.signedIn) { _ in
|
||||
subscriptions.load(force: true)
|
||||
playlists.load(force: true)
|
||||
}
|
||||
.onChange(of: navigation.sidebarSectionChanged) { _ in
|
||||
scrollScrollViewToItem(scrollView: scrollView, for: navigation.tabSelection)
|
||||
}
|
||||
|
@@ -6,11 +6,13 @@ struct AccountForm: View {
|
||||
var selectedAccount: Binding<Account?>?
|
||||
|
||||
@State private var name = ""
|
||||
@State private var sid = ""
|
||||
@State private var username = ""
|
||||
@State private var password = ""
|
||||
|
||||
@State private var isValid = false
|
||||
@State private var isValidated = false
|
||||
@State private var isValidating = false
|
||||
@State private var validationError: String?
|
||||
@State private var validationDebounce = Debounce()
|
||||
|
||||
@FocusState private var focused: Bool
|
||||
@@ -67,21 +69,42 @@ struct AccountForm: View {
|
||||
#endif
|
||||
}
|
||||
.onAppear(perform: initializeForm)
|
||||
.onChange(of: sid) { _ in validate() }
|
||||
.onChange(of: username) { _ in validate() }
|
||||
.onChange(of: password) { _ in validate() }
|
||||
}
|
||||
|
||||
var formFields: some View {
|
||||
Group {
|
||||
TextField("Name", text: $name, prompt: Text("Account Name (optional)"))
|
||||
.focused($focused)
|
||||
if !instance.app.accountsUsePassword {
|
||||
TextField("Name", text: $name, prompt: Text("Account Name (optional)"))
|
||||
.focused($focused)
|
||||
}
|
||||
|
||||
TextField("SID", text: $sid, prompt: Text("Invidious SID Cookie"))
|
||||
TextField("Username", text: $username, prompt: usernamePrompt)
|
||||
|
||||
if instance.app.accountsUsePassword {
|
||||
SecureField("Password", text: $password, prompt: Text("Password"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var usernamePrompt: Text {
|
||||
switch instance.app {
|
||||
case .invidious:
|
||||
return Text("SID Cookie")
|
||||
default:
|
||||
return Text("Username")
|
||||
}
|
||||
}
|
||||
|
||||
var footer: some View {
|
||||
HStack {
|
||||
AccountValidationStatus(isValid: $isValid, isValidated: $isValidated, isValidating: $isValidating, error: .constant(nil))
|
||||
AccountValidationStatus(
|
||||
isValid: $isValid,
|
||||
isValidated: $isValidated,
|
||||
isValidating: $isValidating,
|
||||
error: $validationError
|
||||
)
|
||||
|
||||
Spacer()
|
||||
|
||||
@@ -106,7 +129,9 @@ struct AccountForm: View {
|
||||
isValid = false
|
||||
validationDebounce.invalidate()
|
||||
|
||||
guard !sid.isEmpty else {
|
||||
let passwordIsValid = instance.app.accountsUsePassword ? !password.isEmpty : true
|
||||
|
||||
guard !username.isEmpty, passwordIsValid else {
|
||||
validator.reset()
|
||||
return
|
||||
}
|
||||
@@ -114,7 +139,7 @@ struct AccountForm: View {
|
||||
isValidating = true
|
||||
|
||||
validationDebounce.debouncing(1) {
|
||||
validator.validateInvidiousAccount()
|
||||
validator.validateAccount()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +148,7 @@ struct AccountForm: View {
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountsModel.add(instance: instance, name: name, sid: sid)
|
||||
let account = AccountsModel.add(instance: instance, name: name, username: username, password: password)
|
||||
selectedAccount?.wrappedValue = account
|
||||
|
||||
dismiss()
|
||||
@@ -133,11 +158,12 @@ struct AccountForm: View {
|
||||
AccountValidator(
|
||||
app: .constant(instance.app),
|
||||
url: instance.apiURL,
|
||||
account: Account(instanceID: instance.id, url: instance.apiURL, sid: sid),
|
||||
id: $sid,
|
||||
account: Account(instanceID: instance.id, url: instance.apiURL, username: username, password: password),
|
||||
id: $username,
|
||||
isValid: $isValid,
|
||||
isValidated: $isValidated,
|
||||
isValidating: $isValidating
|
||||
isValidating: $isValidating,
|
||||
error: $validationError
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@@ -17,8 +17,8 @@ struct AccountValidationStatus: View {
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
Text(isValid ? "Connected successfully" : "Connection failed")
|
||||
if !isValid && !error.isNil {
|
||||
Text(error!)
|
||||
if let error = error, !isValid {
|
||||
Text(error)
|
||||
.font(.caption2)
|
||||
.foregroundColor(.secondary)
|
||||
.truncationMode(.tail)
|
||||
|
@@ -52,7 +52,7 @@ struct SettingsView: View {
|
||||
.tag(Tabs.services)
|
||||
}
|
||||
.padding(20)
|
||||
.frame(width: 400, height: 310)
|
||||
.frame(width: 400, height: 380)
|
||||
#else
|
||||
NavigationView {
|
||||
List {
|
||||
|
@@ -39,8 +39,13 @@ struct SubscriptionsView: View {
|
||||
fileprivate func loadResources(force: Bool = false) {
|
||||
feed?.addObserver(store)
|
||||
|
||||
if let request = force ? accounts.api.home?.load() : accounts.api.home?.loadIfNeeded() {
|
||||
request.onSuccess { _ in
|
||||
if accounts.app == .invidious {
|
||||
// Invidious for some reason won't refresh feed until homepage is loaded
|
||||
if let request = force ? accounts.api.home?.load() : accounts.api.home?.loadIfNeeded() {
|
||||
request.onSuccess { _ in
|
||||
loadFeed(force: force)
|
||||
}
|
||||
} else {
|
||||
loadFeed(force: force)
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user