Skip to content

Commit

Permalink
Merge branch 'release/1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Starkrimson committed Jul 4, 2023
2 parents 0ba6c81 + 0edd9d8 commit a5b3e66
Show file tree
Hide file tree
Showing 40 changed files with 509 additions and 154 deletions.
24 changes: 22 additions & 2 deletions MovieDB.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
09D2E110288A454700A14D96 /* Credits.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D2E10F288A454700A14D96 /* Credits.swift */; };
09D7A009289259E500CE9C9F /* EpisodeList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D7A008289259E500CE9C9F /* EpisodeList.swift */; };
09D9A37D288A9ED200ABD638 /* CreditView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D9A37C288A9ED200ABD638 /* CreditView.swift */; };
09DA6F232A1DBAC500EC387B /* WatchlistView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09DA6F222A1DBAC500EC387B /* WatchlistView.swift */; };
09DA6F252A1DBB0400EC387B /* WatchlistReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09DA6F242A1DBB0400EC387B /* WatchlistReducer.swift */; };
09DA6F272A1DC51900EC387B /* SortMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09DA6F262A1DC51900EC387B /* SortMenu.swift */; };
09DB36982880080A00EFFC2B /* TVShow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09DB36972880080A00EFFC2B /* TVShow.swift */; };
09DB369B28800C2E00EFFC2B /* TVDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09DB369A28800C2E00EFFC2B /* TVDetailView.swift */; };
09DB369E28800D0000EFFC2B /* MovieDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09DB369D28800D0000EFFC2B /* MovieDetailView.swift */; };
Expand Down Expand Up @@ -159,6 +162,9 @@
09D2E10F288A454700A14D96 /* Credits.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Credits.swift; sourceTree = "<group>"; };
09D7A008289259E500CE9C9F /* EpisodeList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EpisodeList.swift; sourceTree = "<group>"; };
09D9A37C288A9ED200ABD638 /* CreditView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreditView.swift; sourceTree = "<group>"; };
09DA6F222A1DBAC500EC387B /* WatchlistView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchlistView.swift; sourceTree = "<group>"; };
09DA6F242A1DBB0400EC387B /* WatchlistReducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchlistReducer.swift; sourceTree = "<group>"; };
09DA6F262A1DC51900EC387B /* SortMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortMenu.swift; sourceTree = "<group>"; };
09DB36972880080A00EFFC2B /* TVShow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TVShow.swift; sourceTree = "<group>"; };
09DB369A28800C2E00EFFC2B /* TVDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TVDetailView.swift; sourceTree = "<group>"; };
09DB369D28800D0000EFFC2B /* MovieDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieDetailView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -221,6 +227,7 @@
09615957286E89140001F593 /* Discover */,
09A05A97287FE94E003A2225 /* Details */,
097D4A8F29360EA700DF3C6E /* Favourite */,
09DA6F212A1DBA6800EC387B /* Watchlist */,
09754ED729FA14F5000A3E5D /* Settings */,
0929EDA7286D93CA007C4BFB /* MovieDBApp.swift */,
09CE6D792918DCC3001E87F3 /* MovieDBReducer.swift */,
Expand Down Expand Up @@ -441,6 +448,16 @@
path = Search;
sourceTree = "<group>";
};
09DA6F212A1DBA6800EC387B /* Watchlist */ = {
isa = PBXGroup;
children = (
09DA6F222A1DBAC500EC387B /* WatchlistView.swift */,
09DA6F242A1DBB0400EC387B /* WatchlistReducer.swift */,
09DA6F262A1DC51900EC387B /* SortMenu.swift */,
);
path = Watchlist;
sourceTree = "<group>";
};
09E15D032891137F00D64488 /* MovieCollection */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -619,13 +636,15 @@
09E15D0E28913DB100D64488 /* DetailSeason.swift in Sources */,
096A1A77287BFD7500C3C412 /* Media.swift in Sources */,
09DB36A1288012D100EFFC2B /* Person.swift in Sources */,
09DA6F252A1DBB0400EC387B /* WatchlistReducer.swift in Sources */,
0929EDBA286D93CC007C4BFB /* MovieDBApp.swift in Sources */,
09615967286EC3630001F593 /* DiscoverCardRow.swift in Sources */,
09DB369E28800D0000EFFC2B /* MovieDetailView.swift in Sources */,
09CD64FF2925DB7700F45376 /* EpisodeReducer.swift in Sources */,
09754ED929FA150F000A3E5D /* SettingsView.swift in Sources */,
096A1A73287BDAA500C3C412 /* DiscoverReducer.swift in Sources */,
09992B1A288E724300320342 /* ImageGridView.swift in Sources */,
09DA6F232A1DBAC500EC387B /* WatchlistView.swift in Sources */,
09CE6D862918FAB3001E87F3 /* SearchResultsView.swift in Sources */,
09D7A009289259E500CE9C9F /* EpisodeList.swift in Sources */,
0929EDBE286D93CC007C4BFB /* Persistence.swift in Sources */,
Expand All @@ -636,6 +655,7 @@
09DB369B28800C2E00EFFC2B /* TVDetailView.swift in Sources */,
09F02634288542FE009DAC1F /* DetailMaterial.swift in Sources */,
09CD64FD2925DB3B00F45376 /* EpisodeView.swift in Sources */,
09DA6F272A1DC51900EC387B /* SortMenu.swift in Sources */,
097CED472885124F00115FC6 /* DetailOverview.swift in Sources */,
09615959286E89240001F593 /* DiscoverView.swift in Sources */,
09754EDB29FA1B8F000A3E5D /* ExternalLinkSettings.swift in Sources */,
Expand Down Expand Up @@ -844,7 +864,7 @@
"@executable_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = com.starkrimson.MovieDB;
PRODUCT_NAME = MovieDB;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -883,7 +903,7 @@
"@executable_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = com.starkrimson.MovieDB;
PRODUCT_NAME = MovieDB;
SDKROOT = iphoneos;
Expand Down
6 changes: 3 additions & 3 deletions MovieDBTests/FavouriteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class FavouriteTests: XCTestCase {
)

let favourites = [
Favourite(context: PersistenceController.preview.container.viewContext)
CDFavourite(context: PersistenceController.preview.container.viewContext)
]

store.dependencies.persistenceClient.favouriteList = { _, _ in favourites }
Expand Down Expand Up @@ -51,8 +51,8 @@ final class FavouriteTests: XCTestCase {
await store.receive(.fetchFavouriteList)
await store.receive(.fetchFavouriteListDone(.success([])))

await store.send(.binding(.set(\.$sortByKeyPath, \Favourite.releaseDate))) {
$0.sortByKeyPath = \Favourite.releaseDate
await store.send(.binding(.set(\.$sortByKeyPath, \CDFavourite.releaseDate))) {
$0.sortByKeyPath = \CDFavourite.releaseDate
}
await store.receive(.fetchFavouriteList)
await store.receive(.fetchFavouriteListDone(.success([])))
Expand Down
2 changes: 2 additions & 0 deletions MovieDBTests/MovieDBTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ final class MovieDBTests: XCTestCase {

_ = await store.send(.fetchDetails)
await store.receive(.favouriteResult(.success(nil)))
await store.receive(.watchResult(.success(nil)))
await store.receive(.fetchDetailsResponse(.success(.movie(mockMovies[0])))) {
$0.status = .normal
$0.detail = .movie(.init(mockMovies[0]))
Expand All @@ -61,6 +62,7 @@ final class MovieDBTests: XCTestCase {
$0.status = .loading
}
await store.receive(.favouriteResult(.success(nil)))
await store.receive(.watchResult(.success(nil)))
await store.receive(.fetchDetailsResponse(.success(.tvShow(mockTVShows[0])))) {
$0.status = .normal
$0.detail = .tvShow(.init(mockTVShows[0]))
Expand Down
22 changes: 11 additions & 11 deletions Shared/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
{
"images" : [
{
"filename" : "TheMovieDB.png",
"filename" : "mdb-iOS.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"filename" : "TheMovieDB-1 9.png",
"filename" : "MDB 9.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"filename" : "TheMovieDB-1 8.png",
"filename" : "MDB 8.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"filename" : "TheMovieDB-1 7.png",
"filename" : "MDB 7.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"filename" : "TheMovieDB-1 6.png",
"filename" : "MDB 6.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"filename" : "TheMovieDB-1 5.png",
"filename" : "MDB 5.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"filename" : "TheMovieDB-1 3.png",
"filename" : "MDB 4.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"filename" : "TheMovieDB-1 4.png",
"filename" : "MDB 3.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"filename" : "TheMovieDB-1 2.png",
"filename" : "MDB 2.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"filename" : "TheMovieDB-1 1.png",
"filename" : "MDB 1.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"filename" : "TheMovieDB-1.png",
"filename" : "MDB.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 31 additions & 11 deletions Shared/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,39 @@ struct ContentView: View {

let tabs: [(title: String, items: [MovieDBReducer.Tab])] = [
("MovieDB", [.discover, .movies, .tvShows, .people]),
("LIBRARY".localized, [.favourite])
("LIBRARY".localized, [.favourite, .watchlist])
]

var body: some View {
WithViewStore(store) {
$0
} content: { viewStore in
NavigationSplitView {
List(
selection: viewStore.binding(
get: { $0.selectedTab },
send: MovieDBReducer.Action.tabSelected
)
) {
ForEach(tabs, id: \.title) { section in
Section(section.title) {
ForEach(section.items) { item in
Label(item.rawValue.localized, systemImage: item.systemImage)
VStack {
List(
selection: viewStore.binding(
get: { $0.selectedTab },
send: MovieDBReducer.Action.tabSelected
)
) {
ForEach(tabs, id: \.title) { section in
Section(section.title) {
ForEach(section.items) { item in
Label(item.rawValue.localized, systemImage: item.systemImage)
}
}
}
}
Spacer()
Link(destination: URL(string: "https://www.themoviedb.org")!) {
HStack(spacing: 3) {
Image(systemName: "globe")
Text("themoviedb.org")
}
.font(.footnote)
.foregroundColor(.secondary)
.padding(.bottom, 6)
}
}
.searchable(
text: viewStore.binding(\.search.$query),
Expand Down Expand Up @@ -95,6 +107,14 @@ struct ContentView: View {
)
)

case .watchlist:
WatchlistView(
store: store.scope(
state: \.watchlist,
action: MovieDBReducer.Action.watchlist
)
)

case .none:
EmptyView()
}
Expand Down
54 changes: 41 additions & 13 deletions Shared/Details/State/DetailReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ struct DetailReducer: ReducerProtocol {

var status: ViewStatus = .loading

var favourite: Favourite?

var favourite: CDFavourite?
var isFavourite: Bool { favourite != nil }

var watchItem: CDWatch?
var isInWatchList: Bool { watchItem != nil }
}

enum DetailState: Equatable, Hashable {
Expand All @@ -124,7 +126,10 @@ struct DetailReducer: ReducerProtocol {
case fetchDetailsResponse(TaskResult<DetailModel>)

case markAsFavourite
case favouriteResult(TaskResult<Favourite?>)
case favouriteResult(TaskResult<CDFavourite?>)

case addToWatchList
case watchResult(TaskResult<CDWatch?>)
}

@Dependency(\.dbClient) var dbClient
Expand All @@ -137,19 +142,24 @@ struct DetailReducer: ReducerProtocol {
switch action {
case .fetchDetails:
state.status = .loading
return .merge(
return .concatenate(
.task { [id = state.media.id] in
await .favouriteResult(TaskResult<CDFavourite?> {
try persistenceClient.favouriteItem(id)
})
},
.task { [id = state.media.id] in
await .watchResult(TaskResult<CDWatch?> {
try persistenceClient.watchItem(id)
})
},
.task { [media = state.media] in
await .fetchDetailsResponse(TaskResult<DetailModel> {
try await dbClient.details(media.mediaType ?? .movie, media.id ?? 0)
})
}
.animation()
.cancellable(id: DetailID.self),
.task { [id = state.media.id] in
await .favouriteResult(TaskResult<Favourite?> {
try persistenceClient.favouriteItem(id)
})
}
.cancellable(id: DetailID.self)
)

case .fetchDetailsResponse(.success(let detail)):
Expand All @@ -171,11 +181,11 @@ struct DetailReducer: ReducerProtocol {

case.markAsFavourite:
return .task { [media = state.media, favourite = state.favourite] in
await .favouriteResult(TaskResult<Favourite?> {
await .favouriteResult(TaskResult<CDFavourite?> {
if let favourite {
return try persistenceClient.favourite(.remove(favourite))
return try persistenceClient.deleteFromDatabase(favourite) as? CDFavourite
}
return try persistenceClient.favourite(.favourite(media))
return try persistenceClient.addItemToDatabase(.favourite(media)) as? CDFavourite
})
}

Expand All @@ -186,6 +196,24 @@ struct DetailReducer: ReducerProtocol {
case .favouriteResult(.failure(let error)):
customDump(error)
return .none

case .addToWatchList:
return .task { [media = state.media, watchItem = state.watchItem] in
await .watchResult(TaskResult<CDWatch?> {
if let watchItem {
return try persistenceClient.deleteFromDatabase(watchItem) as? CDWatch
}
return try persistenceClient.addItemToDatabase(.watch(media)) as? CDWatch
})
}

case .watchResult(.success(let watch)):
state.watchItem = watch
return .none

case .watchResult(.failure(let error)):
customDump(error)
return .none
}
}
}
Expand Down
Loading

0 comments on commit a5b3e66

Please sign in to comment.