Skip to content

Commit

Permalink
refactor: Remove optimistic navigation store and related logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Mar 6, 2025
1 parent 783077b commit 0d70f27
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
10 changes: 3 additions & 7 deletions apps/web/src/components/Post/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import getAccount from "@hey/helpers/getAccount";
import getPostData from "@hey/helpers/getPostData";
import { isRepost } from "@hey/helpers/postHelpers";
import {
type AnyPostFragment,
PageSize,
PostReferenceType,
PostVisibilityFilter,
Expand All @@ -29,7 +28,6 @@ import { createTrackedSelector } from "react-tracked";
import Custom404 from "src/pages/404";
import Custom500 from "src/pages/500";
import { useAccountStatus } from "src/store/non-persisted/useAccountStatus";
import { useOptimisticNavigation } from "src/store/non-persisted/useOptimisticNavigation";
import { useAccountStore } from "src/store/persisted/useAccountStore";
import { create } from "zustand";
import FullPost from "./FullPost";
Expand Down Expand Up @@ -58,13 +56,11 @@ const ViewPost: NextPage = () => {

const { currentAccount } = useAccountStore();
const { isSuspended } = useAccountStatus();
const { preLoadedPosts } = useOptimisticNavigation();

const showQuotes = pathname === "/posts/[id]/quotes";
const preLoadedPost = preLoadedPosts.find((p) => p.id === id);

const { data, error, loading } = usePostQuery({
skip: !id || preLoadedPost?.id,
skip: !id,
variables: { request: { post: id } }
});

Expand All @@ -86,15 +82,15 @@ const ViewPost: NextPage = () => {
return <PublicationPageShimmer publicationList={showQuotes} />;
}

if (!preLoadedPost && !data?.post) {
if (!data?.post) {
return <Custom404 />;
}

if (error) {
return <Custom500 />;
}

const post = preLoadedPost || (data?.post as AnyPostFragment);
const post = data?.post;
const targetPost = isRepost(post) ? post.repostOf : post;
const canComment =
targetPost.operations?.canComment.__typename ===
Expand Down
3 changes: 0 additions & 3 deletions apps/web/src/components/Shared/PostWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { AnyPostFragment } from "@hey/indexer";
import { useRouter } from "next/router";
import type { FC, ReactNode } from "react";
import { useOptimisticNavigation } from "src/store/non-persisted/useOptimisticNavigation";

interface PostWrapperProps {
children: ReactNode | ReactNode[];
Expand All @@ -14,13 +13,11 @@ const PostWrapper: FC<PostWrapperProps> = ({
className = "",
post
}) => {
const { preLoadedPosts, setPreLoadedPosts } = useOptimisticNavigation();
const { push } = useRouter();

const handleClick = () => {
const selection = window.getSelection();
if (!selection || selection.toString().length === 0) {
setPreLoadedPosts([...preLoadedPosts, post]);
push(`/posts/${post.id}`);
}
};
Expand Down
15 changes: 0 additions & 15 deletions apps/web/src/store/non-persisted/useOptimisticNavigation.ts

This file was deleted.

0 comments on commit 0d70f27

Please sign in to comment.