Skip to content

Commit

Permalink
fix: watchEpisodeAction and updateAction being swapped
Browse files Browse the repository at this point in the history
  • Loading branch information
Hejsil committed Aug 20, 2024
1 parent fd079a8 commit 670969c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -370,25 +370,26 @@ fn watchingAction(_: *List, list_entry: *List.Entry, _: Database.Entry) void {
}

fn watchEpisodeAction(_: *List, list_entry: *List.Entry, database_entry: Database.Entry) void {
switch (list_entry.status) {
.complete => list_entry.episodes = database_entry.episodes,
.dropped, .on_hold, .plan_to_watch, .watching => list_entry.watched = 0,
if (list_entry.episodes < database_entry.episodes) {
list_entry.episodes += 1;
list_entry.status = .watching;
if (list_entry.episodes == database_entry.episodes) {
list_entry.status = .complete;
list_entry.watched += 1;
}
}
}

fn removeAction(list: *List, list_entry: *List.Entry, _: Database.Entry) void {
const index = (@intFromPtr(list_entry) - @intFromPtr(list.entries.items.ptr)) / @sizeOf(List.Entry);
const index = (@intFromPtr(list_entry) - @intFromPtr(list.entries.items.ptr)) /
@sizeOf(List.Entry);
_ = list.entries.swapRemove(index);
}

fn updateAction(_: *List, list_entry: *List.Entry, database_entry: Database.Entry) void {
if (list_entry.episodes < database_entry.episodes) {
list_entry.episodes += 1;
list_entry.status = .watching;
if (list_entry.episodes == database_entry.episodes) {
list_entry.status = .complete;
list_entry.watched += 1;
}
switch (list_entry.status) {
.complete => list_entry.episodes = database_entry.episodes,
.dropped, .on_hold, .plan_to_watch, .watching => list_entry.watched = 0,
}
}

Expand Down

0 comments on commit 670969c

Please sign in to comment.