Skip to content

Commit

Permalink
Refactor and cleanup various toast messages (#1699)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Nov 11, 2024
1 parent a777e38 commit af8791a
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 201 deletions.
19 changes: 9 additions & 10 deletions src/features/comment/useCommentActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ import {
} from "#/helpers/lemmy";
import { getVoteErrorMessage } from "#/helpers/lemmyErrors";
import { useBuildGeneralBrowseLink } from "#/helpers/routes";
import { postLocked, saveError, saveSuccess } from "#/helpers/toastMessages";
import {
commentDeleteFailed,
commentDeleted,
postLocked,
saveError,
saveSuccess,
} from "#/helpers/toastMessages";
import useAppToast from "#/helpers/useAppToast";
import { useOptimizedIonRouter } from "#/helpers/useOptimizedIonRouter";
import store, { useAppDispatch } from "#/store";
Expand Down Expand Up @@ -204,19 +210,12 @@ export default function useCommentActions({
try {
await dispatch(deleteComment(comment.id));
} catch (error) {
presentToast({
message:
"Problem deleting comment. Please try again.",
color: "danger",
});
presentToast(commentDeleteFailed);

throw error;
}

presentToast({
message: "Comment deleted!",
color: "primary",
});
presentToast(commentDeleted);
})();
},
},
Expand Down
6 changes: 3 additions & 3 deletions src/features/community/list/CommunityListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export default function CommunityListItem({

try {
await dispatch(followCommunity(false, community.id));
presentToast(buildSuccessSubscribing(true, getHandle(community)));
presentToast(buildSuccessSubscribing(true));
} catch (error) {
presentToast(buildProblemSubscribing(true, getHandle(community)));
presentToast(buildProblemSubscribing(true));
throw error;
}
}
Expand All @@ -83,7 +83,7 @@ export default function CommunityListItem({

dispatch(removeFavorite(communityHandle));

presentToast(buildFavorited(isFavorite, communityHandle));
presentToast(buildFavorited(isFavorite));
}

const slideActions = (() => {
Expand Down
10 changes: 5 additions & 5 deletions src/features/community/useCommunityActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ export default function useCommunityActions(

try {
await dispatch(followCommunity(!isSubscribed, communityId));
presentToast(buildSuccessSubscribing(isSubscribed, communityHandle));
presentToast(buildSuccessSubscribing(isSubscribed));
} catch (error) {
presentToast(buildProblemSubscribing(isSubscribed, communityHandle));
presentToast(buildProblemSubscribing(isSubscribed));
throw error;
}
};
Expand All @@ -121,7 +121,7 @@ export default function useCommunityActions(
dispatch(removeFavorite(communityHandle));
}

presentToast(buildFavorited(isFavorite, communityHandle));
presentToast(buildFavorited(isFavorite));
};

const block = async () => {
Expand Down Expand Up @@ -161,7 +161,7 @@ export default function useCommunityActions(
handler: () => {
(async () => {
await _block();
presentToast(buildBlocked(!isBlocked, communityHandle));
presentToast(buildBlocked(!isBlocked));
})();
},
},
Expand All @@ -175,7 +175,7 @@ export default function useCommunityActions(
db.setSetting("has_presented_block_nsfw_tip", true);
} else {
await _block();
presentToast(buildBlocked(!isBlocked, communityHandle));
presentToast(buildBlocked(!isBlocked));
}
};

Expand Down
11 changes: 6 additions & 5 deletions src/features/moderation/ModqueueItemActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { modRemovePost } from "#/features/post/postSlice";
import { isPost } from "#/helpers/lemmy";
import {
commentApproved,
commentRemoved,
commentRemovedMod,
commentRestored,
postApproved,
postRemoved,
postRemovedMod,
postRestored,
} from "#/helpers/toastMessages";
import useAppToast from "#/helpers/useAppToast";
Expand Down Expand Up @@ -42,7 +42,8 @@ export default function ModqueueItemActions({
const action = isPost(item) ? resolvePostReport : resolveCommentReport;
await dispatch(action(id));

if (remove) presentToast(isPost(item) ? postRemoved : commentRemoved);
if (remove)
presentToast(isPost(item) ? postRemovedMod : commentRemovedMod);
else presentToast(isPost(item) ? postApproved : commentApproved);

return;
Expand All @@ -54,8 +55,8 @@ export default function ModqueueItemActions({

const toastMessage = (() => {
if (remove) {
if (isPost(item)) return postRemoved;
else return commentRemoved;
if (isPost(item)) return postRemovedMod;
else return commentRemovedMod;
} else {
if (isPost(item)) return postRestored;
else return commentRestored;
Expand Down
6 changes: 3 additions & 3 deletions src/features/moderation/useCommentModActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
buildBanned,
commentApproved,
commentDistinguished,
commentRemoved,
commentRemovedMod,
} from "#/helpers/toastMessages";
import useAppToast from "#/helpers/useAppToast";
import store, { useAppDispatch } from "#/store";
Expand Down Expand Up @@ -103,7 +103,7 @@ export default function useCommentModActions(commentView: CommentView) {
(async () => {
await dispatch(modRemoveComment(comment.id, true));

presentToast(commentRemoved);
presentToast(commentRemovedMod);
})();
},
}
Expand Down Expand Up @@ -134,7 +134,7 @@ export default function useCommentModActions(commentView: CommentView) {
modRemoveComment(comment.id, true, reason),
);

presentToast(commentRemoved);
presentToast(commentRemovedMod);
})();
},
},
Expand Down
6 changes: 3 additions & 3 deletions src/features/moderation/usePostModActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
buildLocked,
buildStickied,
postApproved,
postRemoved,
postRemovedMod,
postRestored,
} from "#/helpers/toastMessages";
import useAppToast from "#/helpers/useAppToast";
Expand Down Expand Up @@ -80,7 +80,7 @@ export default function usePostModActions(post: PostView) {
(async () => {
await dispatch(modRemovePost(post.post.id, true));

presentToast(postRemoved);
presentToast(postRemovedMod);
})();
},
}
Expand Down Expand Up @@ -109,7 +109,7 @@ export default function usePostModActions(post: PostView) {
(async () => {
await dispatch(modRemovePost(post.post.id, true, reason));

presentToast(postRemoved);
presentToast(postRemovedMod);
})();
},
},
Expand Down
17 changes: 3 additions & 14 deletions src/features/post/crosspost/create/CreateCrosspostDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from "@ionic/react";
import { css } from "@linaria/core";
import { styled } from "@linaria/react";
import { checkmark } from "ionicons/icons";
import { CommunityView, PostView } from "lemmy-js-client";
import { useContext, useEffect, useState } from "react";

Expand All @@ -21,6 +20,7 @@ import { buildPostLink } from "#/helpers/appLinkBuilder";
import { isNative } from "#/helpers/device";
import { buildCrosspostBody, getHandle } from "#/helpers/lemmy";
import { useBuildGeneralBrowseLink } from "#/helpers/routes";
import { crosspostFailed, crosspostSuccess } from "#/helpers/toastMessages";
import useAppToast from "#/helpers/useAppToast";
import useClient from "#/helpers/useClient";
import { useOptimizedIonRouter } from "#/helpers/useOptimizedIonRouter";
Expand Down Expand Up @@ -129,11 +129,7 @@ export default function CreateCrosspostDialog({
community_id: community.community.id,
});
} catch (error) {
presentToast({
message: "Failed to create crosspost",
color: "danger",
centerText: true,
});
presentToast(crosspostFailed);
throw error;
} finally {
setLoading(false);
Expand All @@ -152,14 +148,7 @@ export default function CreateCrosspostDialog({

onDismiss();

presentToast({
message: "Crossposted!",
color: "primary",
position: "top",
centerText: true,
fullscreen: true,
icon: checkmark,
});
presentToast(crosspostSuccess);
}

return (
Expand Down
17 changes: 7 additions & 10 deletions src/features/post/new/PostEditorRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { css } from "@linaria/core";
import { styled } from "@linaria/react";
import { startCase } from "es-toolkit";
import { accessibility, cameraOutline, checkmark } from "ionicons/icons";
import { accessibility, cameraOutline } from "ionicons/icons";
import { Post } from "lemmy-js-client";
import { useEffect, useMemo, useState } from "react";

Expand All @@ -32,7 +32,11 @@ import {
import { isAndroid } from "#/helpers/device";
import { getHandle, getRemoteHandle } from "#/helpers/lemmy";
import { useBuildGeneralBrowseLink } from "#/helpers/routes";
import { problemFetchingTitle } from "#/helpers/toastMessages";
import {
postCreated,
postEdited,
problemFetchingTitle,
} from "#/helpers/toastMessages";
import { isUrlImage, isValidUrl } from "#/helpers/url";
import useAppToast from "#/helpers/useAppToast";
import useClient from "#/helpers/useClient";
Expand Down Expand Up @@ -299,14 +303,7 @@ export default function PostEditorRoot({

dispatch(receivedPosts([postResponse.post_view]));

presentToast({
message: existingPost ? "Post edited!" : "Post created!",
color: "primary",
position: "top",
centerText: true,
fullscreen: true,
icon: checkmark,
});
presentToast(existingPost ? postEdited : postCreated);

setCanDismiss(true);

Expand Down
20 changes: 12 additions & 8 deletions src/features/post/shared/usePostActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
arrowUpOutline,
bookmarkOutline,
cameraOutline,
checkmark,
eyeOffOutline,
eyeOutline,
flagOutline,
Expand Down Expand Up @@ -39,6 +38,10 @@ import {
} from "#/helpers/lemmy";
import { getVoteErrorMessage } from "#/helpers/lemmyErrors";
import { useBuildGeneralBrowseLink } from "#/helpers/routes";
import {
postDeleteFailed,
postDeleted as postDeletedToast,
} from "#/helpers/toastMessages";
import { postLocked, saveError, saveSuccess } from "#/helpers/toastMessages";
import useAppToast from "#/helpers/useAppToast";
import { useOptimizedIonRouter } from "#/helpers/useOptimizedIonRouter";
Expand Down Expand Up @@ -166,14 +169,15 @@ export default function usePostActions(post: PostView) {
role: "destructive",
handler: () => {
(async () => {
await dispatch(deletePost(post.post.id));
try {
await dispatch(deletePost(post.post.id));
} catch (error) {
presentToast(postDeleteFailed);

throw error;
}

presentToast({
message: "Post deleted",
color: "success",
centerText: true,
icon: checkmark,
});
presentToast(postDeletedToast);
})();
},
},
Expand Down
5 changes: 2 additions & 3 deletions src/features/report/Report.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CommentView, PostView, PrivateMessageView } from "lemmy-js-client";
import { useImperativeHandle, useState } from "react";

import { isLemmyError } from "#/helpers/lemmyErrors";
import { buildReported } from "#/helpers/toastMessages";
import useAppToast from "#/helpers/useAppToast";
import useClient from "#/helpers/useClient";

Expand Down Expand Up @@ -78,9 +79,7 @@ export default function Report({
throw error;
}

presentToast({
message: `${type} reported!`,
});
if (type) presentToast(buildReported(type));
}

const submitCustomReason = async function (
Expand Down
2 changes: 1 addition & 1 deletion src/features/share/asImage/ShareAsImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export default function ShareAsImage({ data, header }: ShareAsImageProps) {
setBlob(() => blob ?? undefined);
} catch (error) {
presentToast({
message: "Error rendering image.",
message: "Error rendering image",
});

throw error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useEffect, useState } from "react";
import { Centered, Spinner } from "#/features/auth/login/LoginNav";
import { editComment } from "#/features/comment/commentSlice";
import { isIosTheme } from "#/helpers/device";
import { commentEdited } from "#/helpers/toastMessages";
import useAppToast from "#/helpers/useAppToast";
import { useAppDispatch } from "#/store";

Expand Down Expand Up @@ -61,13 +62,7 @@ export default function CommentEditPage({
setLoading(false);
}

presentToast({
message: "Comment edited!",
color: "primary",
position: "top",
centerText: true,
fullscreen: true,
});
presentToast(commentEdited);

setCanDismiss(true);
dismiss(comment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Centered, Spinner } from "#/features/auth/login/LoginNav";
import { receivedComments } from "#/features/comment/commentSlice";
import { isIosTheme } from "#/helpers/device";
import { isLemmyError } from "#/helpers/lemmyErrors";
import { commentPosted } from "#/helpers/toastMessages";
import useAppToast from "#/helpers/useAppToast";
import useClient from "#/helpers/useClient";
import { getClient } from "#/services/lemmy";
Expand Down Expand Up @@ -216,13 +217,7 @@ export default function CommentReplyPage({
}

if (!silentError) {
presentToast({
message: "Comment posted!",
color: "primary",
position: "top",
centerText: true,
fullscreen: true,
});
presentToast(commentPosted);
}

if (reply) dispatch(receivedComments([reply]));
Expand Down
Loading

0 comments on commit af8791a

Please sign in to comment.