Skip to content

Commit

Permalink
Add useAppToast, add haptics, present below app navigation bars
Browse files Browse the repository at this point in the history
Resolves #147
  • Loading branch information
aeharding committed Oct 12, 2023
1 parent c4e14fc commit d3026cc
Show file tree
Hide file tree
Showing 29 changed files with 249 additions and 238 deletions.
4 changes: 2 additions & 2 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,7 +47,7 @@
"@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/core": "npm:voyager-ionic-core@^7.5.0",
"@ionic/react": "^7.4.3",
"@ionic/react-router": "^7.4.3",
"@reduxjs/toolkit": "^1.9.7",
Expand Down
30 changes: 15 additions & 15 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
14 changes: 4 additions & 10 deletions src/features/comment/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import {
buildCommentsTreeWithMissing,
} from "../../helpers/lemmy";
import CommentTree from "./CommentTree";
import {
IonRefresher,
IonRefresherContent,
IonSpinner,
useIonToast,
} from "@ionic/react";
import { IonRefresher, IonRefresherContent, IonSpinner } from "@ionic/react";
import styled from "@emotion/styled";
import { css } from "@emotion/react";
import { CommentSortType, CommentView, Person } from "lemmy-js-client";
Expand All @@ -32,6 +27,7 @@ import { CommentsContext } from "./CommentsContext";
import { jwtSelector } from "../auth/authSlice";
import { defaultCommentDepthSelector } from "../settings/settingsSlice";
import { isSafariFeedHackEnabled } from "../../pages/shared/FeedContent";
import useAppToast from "../../helpers/useAppToast";

const centerCss = css`
position: relative;
Expand Down Expand Up @@ -92,7 +88,7 @@ export default forwardRef<CommentsHandle, CommentsProps>(function Comments(
);
const client = useClient();
const [isListAtTop, setIsListAtTop] = useState<boolean>(true);
const [present] = useIonToast();
const presentToast = useAppToast();
const defaultCommentDepth = useAppSelector(defaultCommentDepthSelector);

const highlightedCommentId = commentPath
Expand Down Expand Up @@ -151,10 +147,8 @@ export default forwardRef<CommentsHandle, CommentsProps>(function Comments(
});
} catch (error) {
if (reqPostId === postId && reqCommentId === commentId)
present({
presentToast({
message: "Problem fetching comments. Please try again.",
duration: 3500,
position: "bottom",
color: "danger",
});

Expand Down
Loading

0 comments on commit d3026cc

Please sign in to comment.