Skip to content

Commit

Permalink
お気に入り追加機能拡張
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuz0u committed Feb 19, 2021
1 parent 02c2d34 commit 570998b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 20 deletions.
4 changes: 2 additions & 2 deletions EhPanda.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = EhPanda/EhPanda.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 39;
CURRENT_PROJECT_VERSION = 40;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 9SKQ7QTZ74;
ENABLE_PREVIEWS = YES;
Expand All @@ -660,7 +660,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = EhPanda/EhPanda.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 39;
CURRENT_PROJECT_VERSION = 40;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 9SKQ7QTZ74;
ENABLE_PREVIEWS = YES;
Expand Down
2 changes: 1 addition & 1 deletion EhPanda/データフロー/AppAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ enum AppAction {
case fetchMoreMangaContents(id: String)
case fetchMoreMangaContentsDone(result: Result<(Identity, PageNumber, [MangaContent]), AppError>)

case addFavorite(id: String)
case addFavorite(id: String, favIndex: Int)
case deleteFavorite(id: String)
case sendDownloadCommand(id: String, resolution: String)
case sendDownloadCommandDone(result: Result<Resp?, AppError>)
Expand Down
3 changes: 2 additions & 1 deletion EhPanda/データフロー/AppCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,11 @@ struct FetchMoreMangaContentsCommand: AppCommand {
struct AddFavoriteCommand: AppCommand {
let id: String
let token: String
let favIndex: Int

func execute(in store: Store) {
let sToken = SubscriptionToken()
AddFavoriteRequest(id: id, token: token)
AddFavoriteRequest(id: id, token: token, favIndex: favIndex)
.publisher
.receive(on: DispatchQueue.main)
.sink { completion in
Expand Down
4 changes: 2 additions & 2 deletions EhPanda/データフロー/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -683,9 +683,9 @@ class Store: ObservableObject {
}

// MARK: アカウント活動
case .addFavorite(let id):
case .addFavorite(let id, let favIndex):
let token = appState.cachedList.items?[id]?.token ?? ""
appCommand = AddFavoriteCommand(id: id, token: token)
appCommand = AddFavoriteCommand(id: id, token: token, favIndex: favIndex)
case .deleteFavorite(let id):
appCommand = DeleteFavoriteCommand(id: id)

Expand Down
3 changes: 2 additions & 1 deletion EhPanda/ネットワーク/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,12 @@ struct MangaContentsRequest {
struct AddFavoriteRequest {
let id: String
let token: String
let favIndex: Int

var publisher: AnyPublisher<Any, AppError> {
let url = Defaults.URL.addFavorite(id: id, token: token)
let parameters: [String: String] = [
"favcat": "0",
"favcat": "\(favIndex)",
"favnote": "",
"apply": "Add to Favorites",
"update": "1"
Expand Down
51 changes: 38 additions & 13 deletions EhPanda/ビュー/詳細情報/DetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,14 @@ private struct HeaderView: View {
let manga: Manga
let detail: MangaDetail

var settings: AppState.Settings {
store.appState.settings
}
var setting: Setting? {
store.appState.settings.setting
settings.setting
}
var user: User? {
settings.user
}

var isFavored: Bool {
Expand Down Expand Up @@ -374,10 +380,30 @@ private struct HeaderView: View {
}
Spacer()
if exx {
Image(systemName: isFavored ? "heart.fill" : "heart")
.imageScale(.large)
.foregroundColor(.accentColor)
.onTapGesture(perform: onFavoriteTap)
if isFavored {
Button(action: onFavoriteDelete) {
Image(systemName: "heart.fill")
.imageScale(.large)
.foregroundColor(.accentColor)
}
} else {
if let user = user,
let names = user.favoriteNames
{
Menu {
ForEach(0..<names.count - 1) { index in
Button(user.getFavNameFrom(index)) {
onFavoriteAdd(index)
}
}
} label: {
Image(systemName: "heart")
.imageScale(.large)
.foregroundColor(.accentColor)
}
}

}
}
Button(action: {}) {
NavigationLink(destination: ContentView(id: manga.id)) {
Expand All @@ -397,16 +423,15 @@ private struct HeaderView: View {
}
}

func onFavoriteTap() {
if isFavored {
deleteFavorite()
} else {
addFavorite()
}
func onFavoriteAdd(_ index: Int) {
addFavorite(index)
}
func onFavoriteDelete() {
deleteFavorite()
}

func addFavorite() {
store.dispatch(.addFavorite(id: manga.id))
func addFavorite(_ index: Int) {
store.dispatch(.addFavorite(id: manga.id, favIndex: index))
}
func deleteFavorite() {
store.dispatch(.deleteFavorite(id: manga.id))
Expand Down

0 comments on commit 570998b

Please sign in to comment.