Skip to content

Commit

Permalink
Merge branch 'develop' into fix/e2e-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnAllenTech committed Oct 14, 2024
2 parents fc64a92 + 42cf381 commit 0ae6105
Show file tree
Hide file tree
Showing 23 changed files with 300 additions and 1,167 deletions.
5 changes: 3 additions & 2 deletions app/(app)/saved/_client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import ArticleLoading from "@/components/ArticlePreview/ArticleLoading";

const SavedPosts = () => {
const {
data: bookmarks,
data: bookmarksData,
refetch,
status: bookmarkStatus,
} = api.post.myBookmarks.useQuery();
} = api.post.myBookmarks.useQuery({});
const bookmarks = bookmarksData?.bookmarks || [];

const { mutate: bookmark } = api.post.bookmark.useMutation({
onSettled() {
Expand Down
14 changes: 13 additions & 1 deletion components/ArticlePreview/ArticlePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from "@headlessui/react";
import { api } from "@/server/trpc/react";
import { signIn, useSession } from "next-auth/react";
import { toast } from "sonner";

type ButtonOptions = {
label: string;
Expand Down Expand Up @@ -55,8 +56,12 @@ const ArticlePreview: NextPage<Props> = ({
bookmarkedInitialState = false,
}) => {
const [bookmarked, setIsBookmarked] = useState(bookmarkedInitialState);
const howManySavedToShow = 3;
const { data: bookmarksData, refetch } = api.post.myBookmarks.useQuery({
limit: howManySavedToShow,
});
const { data: session } = useSession();

const bookmarks = bookmarksData?.bookmarks;
const dateTime = Temporal.Instant.from(new Date(date).toISOString());
const readableDate = dateTime.toLocaleString(["en-IE"], {
year: "numeric",
Expand All @@ -69,6 +74,13 @@ const ArticlePreview: NextPage<Props> = ({
onSettled() {
setIsBookmarked((isBookmarked) => !isBookmarked);
},
onSuccess: () => {
refetch();
},
onError: (error) => {
toast.error("Failed to update bookmark");
Sentry.captureException(error);
},
});

const bookmarkPost = async (postId: string, setBookmarked = true) => {
Expand Down
Loading

0 comments on commit 0ae6105

Please sign in to comment.