Skip to content

Commit

Permalink
Code improvements: Feature/ Add series to link related articles
Browse files Browse the repository at this point in the history
  • Loading branch information
RangerCreaky committed Oct 18, 2024
1 parent 75400e5 commit ab67084
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/(app)/create/[[...paramsArr]]/_client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const Create = () => {

const { mutate: seriesUpdate, status: seriesStatus } = api.series.update.useMutation({
onError(error) {
toast.error("Error auto-saving");
toast.error("Error updating series");
Sentry.captureException(error);
}
});
Expand Down Expand Up @@ -234,19 +234,30 @@ const Create = () => {
if (!formData.id) {
await create({ ...formData });
} else {
let saveSuccess = false;
try {
await save({ ...formData, id: postId });
saveSuccess = true;
} catch (error) {
toast.error("Error saving post.");
Sentry.captureException(error);
}

let seriesUpdateSuccess = false;
try {
await seriesUpdate({ postId, seriesName: formData.seriesName });
toast.success("Saved");
if(formData?.seriesName){
await seriesUpdate({ postId, seriesName: formData.seriesName });
}
seriesUpdateSuccess = true;
} catch (error) {
toast.error("Error updating series.");
Sentry.captureException(error);
}

if(saveSuccess && seriesUpdateSuccess){
toast.success("Saved");
}

setSavedTime(
new Date().toLocaleString(undefined, {
dateStyle: "medium",
Expand Down

0 comments on commit ab67084

Please sign in to comment.