From 670969cfbfcc8cc361c1198acbcf57a0c922d516 Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Tue, 20 Aug 2024 13:20:25 +0200 Subject: [PATCH] fix: watchEpisodeAction and updateAction being swapped --- src/main.zig | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main.zig b/src/main.zig index 7b82cb8..f2ce937 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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, } }