Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useAppToast, add haptics, present below app navigation bars #764

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"pnpm": {
"overrides": {
"@ionic/core": "npm:voyager-ionic-core@^7.4.3"
"@ionic/core": "npm:voyager-ionic-core@^7.5.0"
}
},
"dependencies": {
Expand Down Expand Up @@ -47,9 +47,9 @@
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@github/markdown-toolbar-element": "^2.2.1",
"@ionic/core": "npm:voyager-ionic-core@^7.4.3",
"@ionic/react": "^7.4.3",
"@ionic/react-router": "^7.4.3",
"@ionic/core": "npm:voyager-ionic-core@^7.5.0",
"@ionic/react": "^7.5.0",
"@ionic/react-router": "^7.5.0",
"@reduxjs/toolkit": "^1.9.7",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "^14.0.0",
Expand Down
50 changes: 25 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 16 additions & 24 deletions src/features/auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
IonRadio,
IonSpinner,
IonList,
useIonToast,
IonText,
IonRouterLink,
useIonModal,
Expand All @@ -28,6 +27,7 @@ import { preventPhotoswipeGalleryFocusTrap } from "../gallery/GalleryImg";
import { getCustomServers } from "../../services/app";
import { isNative } from "../../helpers/device";
import { Browser } from "@capacitor/browser";
import useAppToast from "../../helpers/useAppToast";

const JOIN_LEMMY_URL = "https://join-lemmy.org/instances";

Expand All @@ -53,7 +53,7 @@ export default function Login({
}: {
onDismiss: (data?: string | null | undefined | number, role?: string) => void;
}) {
const [present] = useIonToast();
const presentToast = useAppToast();
const dispatch = useAppDispatch();
const [servers] = useState(getCustomServers());
const [server, setServer] = useState(servers[0]);
Expand Down Expand Up @@ -104,23 +104,21 @@ export default function Login({

async function submit() {
if (!server && !customServer) {
present({
message: `Please enter your instance domain name`,
duration: 3500,
position: "bottom",
presentToast({
message: "Please enter your instance domain name",
color: "danger",
fullscreen: true,
});
return;
}

if (!serverConfirmed) {
if (customServer) {
if (!customServerHostname) {
present({
presentToast({
message: `${customServer} is not a valid server URL. Please try again`,
duration: 3500,
position: "bottom",
color: "danger",
fullscreen: true,
});

return;
Expand All @@ -130,11 +128,10 @@ export default function Login({
try {
await getClient(customServerHostname).getSite({});
} catch (error) {
present({
presentToast({
message: `Problem connecting to ${customServerHostname}. Please try again`,
duration: 3500,
position: "bottom",
color: "danger",
fullscreen: true,
});

throw error;
Expand All @@ -148,21 +145,19 @@ export default function Login({
}

if (!username || !password) {
present({
presentToast({
message: "Please fill out username and password fields",
duration: 3500,
position: "bottom",
color: "danger",
fullscreen: true,
});
return;
}

if (!totp && needsTotp) {
present({
presentToast({
message: `Please enter your second factor authentication code for ${username}`,
duration: 3500,
position: "bottom",
color: "danger",
fullscreen: true,
});
return;
}
Expand All @@ -183,11 +178,10 @@ export default function Login({
setPassword("");
}

present({
presentToast({
message: getLoginErrorMessage(error, server ?? customServer),
duration: 3500,
position: "bottom",
color: "danger",
fullscreen: true,
});

throw error;
Expand All @@ -196,10 +190,8 @@ export default function Login({
}

onDismiss();
present({
presentToast({
message: "Login successful",
duration: 2000,
position: "bottom",
color: "success",
});
}
Expand Down
24 changes: 8 additions & 16 deletions src/features/comment/CommentEllipsis.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import styled from "@emotion/styled";
import {
IonIcon,
useIonActionSheet,
useIonRouter,
useIonToast,
} from "@ionic/react";
import { IonIcon, useIonActionSheet, useIonRouter } from "@ionic/react";
import {
arrowDownOutline,
arrowUndoOutline,
Expand Down Expand Up @@ -36,6 +31,7 @@ import { handleSelector, isDownvoteEnabledSelector } from "../auth/authSlice";
import { CommentsContext } from "./CommentsContext";
import { deleteComment, saveComment, voteOnComment } from "./commentSlice";
import useCollapseRootComment from "./useCollapseRootComment";
import useAppToast from "../../helpers/useAppToast";

const StyledIonIcon = styled(IonIcon)`
padding: 8px 12px;
Expand All @@ -57,7 +53,7 @@ export default function MoreActions({
const dispatch = useAppDispatch();
const { prependComments } = useContext(CommentsContext);
const myHandle = useAppSelector(handleSelector);
const [present] = useIonToast();
const presentToast = useAppToast();
const [presentActionSheet] = useIonActionSheet();
const [presentSecondaryActionSheet] = useIonActionSheet();
const collapseRootComment = useCollapseRootComment(commentView, rootIndex);
Expand Down Expand Up @@ -105,7 +101,7 @@ export default function MoreActions({
try {
await dispatch(voteOnComment(comment.id, myVote === 1 ? 0 : 1));
} catch (error) {
present(voteError);
presentToast(voteError);
}
})();
},
Expand All @@ -123,7 +119,7 @@ export default function MoreActions({
voteOnComment(comment.id, myVote === -1 ? 0 : -1),
);
} catch (error) {
present(voteError);
presentToast(voteError);
}
})();
},
Expand All @@ -139,7 +135,7 @@ export default function MoreActions({
try {
await dispatch(saveComment(comment.id, !mySaved));
} catch (error) {
present(saveError);
presentToast(saveError);
}
})();
},
Expand Down Expand Up @@ -168,21 +164,17 @@ export default function MoreActions({
try {
await dispatch(deleteComment(comment.id));
} catch (error) {
present({
presentToast({
message:
"Problem deleting comment. Please try again.",
duration: 3500,
position: "bottom",
color: "danger",
});

throw error;
}

present({
presentToast({
message: "Comment deleted!",
duration: 3500,
position: "bottom",
color: "primary",
});
})();
Expand Down
13 changes: 5 additions & 8 deletions src/features/comment/CommentExpander.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import CommentHr from "./CommentHr";
import { useContext, useState } from "react";
import { CommentsContext } from "./CommentsContext";
import useClient from "../../helpers/useClient";
import { IonIcon, IonSpinner, useIonToast } from "@ionic/react";
import { IonIcon, IonSpinner } from "@ionic/react";
import { chevronDown } from "ionicons/icons";
import AnimateHeight from "react-animate-height";
import { MAX_DEFAULT_COMMENT_DEPTH } from "../../helpers/lemmy";
import { css } from "@emotion/react";
import useAppToast from "../../helpers/useAppToast";

const MoreRepliesBlock = styled.div<{ hidden: boolean }>`
display: flex;
Expand Down Expand Up @@ -53,7 +54,7 @@ export default function CommentExpander({
missing,
collapsed,
}: CommentExpanderProps) {
const [present] = useIonToast();
const presentToast = useAppToast();
const { appendComments } = useContext(CommentsContext);
const client = useClient();
const [loading, setLoading] = useState(false);
Expand All @@ -72,10 +73,8 @@ export default function CommentExpander({
max_depth: Math.max((depth += 2), MAX_DEFAULT_COMMENT_DEPTH),
});
} catch (error) {
present({
presentToast({
message: "Problem fetching more comments. Please try again.",
duration: 3500,
position: "bottom",
color: "danger",
});
throw error;
Expand All @@ -84,10 +83,8 @@ export default function CommentExpander({
}

if (response.comments.length === 0) {
present({
presentToast({
message: `Uh-oh. Looks like Lemmy returned 0 comments, but there's actually ${missing}`,
duration: 3500,
position: "bottom",
color: "danger",
});
return;
Expand Down
Loading