Channels caching

This commit is contained in:
Arkadiusz Fal
2022-12-14 00:07:32 +01:00
parent d9622cf24c
commit 3b31f21c81
18 changed files with 151 additions and 18 deletions

View File

@@ -133,7 +133,18 @@ struct ChannelVideosView: View {
}
#endif
.onAppear {
resource?.loadIfNeeded()
if let channel,
let cache = ChannelsCacheModel.shared.retrieve(channel.cacheKey),
store.item.isNil
{
store.replace(cache)
}
resource?.loadIfNeeded()?.onSuccess { response in
if let channel: Channel = response.typedContent() {
ChannelsCacheModel.shared.store(channel)
}
}
}
.onChange(of: contentType) { _ in
resource?.load()

View File

@@ -121,7 +121,7 @@ struct FavoriteItemView: View {
Group {
switch item.section {
case let .channel(_, id, name):
ChannelVideosView(channel: .init(id: id, name: name))
ChannelVideosView(channel: .init(app: .invidious, id: id, name: name))
case let .channelPlaylist(_, id, title):
ChannelPlaylistView(playlist: .init(id: id, title: title))
case let .playlist(_, id):
@@ -140,7 +140,7 @@ struct FavoriteItemView: View {
func itemButtonAction() {
switch item.section {
case let .channel(_, id, name):
NavigationModel.shared.openChannel(.init(id: id, name: name), navigationStyle: navigationStyle)
NavigationModel.shared.openChannel(.init(app: .invidious, id: id, name: name), navigationStyle: navigationStyle)
case let .channelPlaylist(_, id, title):
NavigationModel.shared.openChannelPlaylist(.init(id: id, title: title), navigationStyle: navigationStyle)
case .subscriptions:

View File

@@ -15,7 +15,7 @@ struct ChannelsView: View {
ForEach(subscriptions.all) { channel in
NavigationLink(destination: ChannelVideosView(channel: channel).modifier(PlayerOverlayModifier())) {
HStack {
if let url = channel.thumbnailURL {
if let url = channel.thumbnailURLOrCached {
ThumbnailView(url: url)
.frame(width: 35, height: 35)
.clipShape(RoundedRectangle(cornerRadius: 35))

View File

@@ -74,8 +74,11 @@ struct VideoBanner: View {
HStack {
HStack {
if !inChannelView {
ThumbnailView(url: video?.channel.thumbnailURL)
if !inChannelView,
let video,
let url = video.channel.thumbnailURLOrCached
{
ThumbnailView(url: url)
.frame(width: 30, height: 30)
.clipShape(Circle())
}

View File

@@ -166,8 +166,18 @@ struct VideoCell: View {
videoDetail(video.displayTitle, lineLimit: 5)
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
if !channelOnThumbnail, !inChannelView {
channelControl(badge: false)
HStack(spacing: 12) {
if !inChannelView,
let video,
let url = video.channel.thumbnailURLOrCached
{
ThumbnailView(url: url)
.frame(width: 30, height: 30)
.clipShape(Circle())
}
if !channelOnThumbnail, !inChannelView {
channelControl(badge: false)
}
}
if additionalDetailsAvailable {
@@ -271,6 +281,15 @@ struct VideoCell: View {
.padding(.bottom, 4)
HStack(spacing: 8) {
if !inChannelView,
let video,
let url = video.channel.thumbnailURLOrCached
{
ThumbnailView(url: url)
.frame(width: 30, height: 30)
.clipShape(Circle())
}
if let date = video.publishedDate {
HStack(spacing: 2) {
Text(date)
@@ -512,7 +531,7 @@ struct VideoCell_Preview: PreviewProvider {
#if os(macOS)
.frame(maxWidth: 300, maxHeight: 250)
#elseif os(iOS)
.frame(maxWidth: 300, maxHeight: 200)
.frame(maxWidth: 600, maxHeight: 200)
#endif
.injectFixtureEnvironmentObjects()
}