Skip to content

Commit

Permalink
Merge branch 'preview'
Browse files Browse the repository at this point in the history
  • Loading branch information
pdelfan committed Sep 6, 2024
2 parents 2ab1317 + 3596284 commit a6e39d9
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 93 deletions.
30 changes: 15 additions & 15 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@atproto/api": "^0.12.24",
"@atproto/api": "^0.13.5",
"@emoji-mart/data": "^1.1.2",
"@emoji-mart/react": "^1.1.1",
"@radix-ui/react-dialog": "^1.0.5",
Expand Down
15 changes: 15 additions & 0 deletions src/app/dashboard/user/[handle]/(post)/post/[id]/quotes/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Layout from "@/containers/Layout";
import type { Metadata } from "next";

export const metadata: Metadata = {
title: "Ouranos — Quotes",
description: "Quotes for this post",
};

export default function RepostedByLayout({
children,
}: {
children: React.ReactNode;
}) {
return <Layout>{children}</Layout>;
}
21 changes: 21 additions & 0 deletions src/app/dashboard/user/[handle]/(post)/post/[id]/quotes/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import QuotesContainer from "@/containers/thread/QuotesContainer";

interface Props {
params: {
id: string;
handle: string;
};
}

export default function Page(props: Props) {
const { id, handle } = props.params;

return (
<section>
<h2 className="text-skin-base mb-2 px-3 text-2xl font-semibold md:px-0">
Quotes
</h2>
<QuotesContainer handle={handle} id={id} />
</section>
);
}
18 changes: 16 additions & 2 deletions src/components/dataDisplay/postActions/PostActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default function PostActions(props: Props) {
const { deletePost } = useDeletePost({ post: post });
const { liked, toggleLike, likeCount } = useLike({ post: post });
const { reposted, toggleRepost, repostCount } = useRepost({ post: post });
const quoteCount = post.quoteCount ?? 0;
const { muted, toggleMuteUser } = useMuteUser({ author: post.author });
const clipboard = useClipboard({ copiedTimeout: 3500 });
const { openComposer } = useComposerControls();
Expand Down Expand Up @@ -72,7 +73,7 @@ export default function PostActions(props: Props) {
{repostCount > 0 && (
<Link
href={`/dashboard/user/${post.author.handle}/post/${getPostId(
post.uri,
post.uri
)}/reposted-by`}
className="text-skin-base flex gap-1 font-semibold"
>
Expand All @@ -82,10 +83,23 @@ export default function PostActions(props: Props) {
</span>
</Link>
)}
{quoteCount > 0 && (
<Link
href={`/dashboard/user/${post.author.handle}/post/${getPostId(
post.uri
)}/quotes`}
className="text-skin-base flex gap-1 font-semibold"
>
{abbreviateNumber(quoteCount)}
<span className="text-skin-tertiary font-medium">
Quote{quoteCount > 1 && "s"}
</span>
</Link>
)}
{likeCount > 0 && (
<Link
href={`/dashboard/user/${post.author.handle}/post/${getPostId(
post.uri,
post.uri
)}/liked-by`}
className="text-skin-base flex gap-1 font-semibold"
>
Expand Down
89 changes: 89 additions & 0 deletions src/containers/thread/QuotesContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"use client";

import useAgent from "@/lib/hooks/bsky/useAgent";
import { useInfiniteQuery } from "@tanstack/react-query";
import { Fragment } from "react";
import EndOfFeed from "@/components/feedback/endOfFeed/EndOfFeed";
import FeedAlert from "@/components/feedback/feedAlert/FeedAlert";
import FeedPostSkeleton from "@/components/contentDisplay/feedPost/FeedPostSkeleton";
import SearchPost from "@/components/contentDisplay/searchPost/SearchPost";
import LoadingSpinner from "@/components/status/loadingSpinner/LoadingSpinner";
import InfiniteScroll from "react-infinite-scroll-component";
import { getPostQuotes } from "@/lib/api/bsky/feed";

interface Props {
id: string;
handle: string;
}

export default function QuotesContainer(props: Props) {
const { id, handle } = props;
const agent = useAgent();

const {
status,
data: quotes,
error,
isLoading,
isFetching,
isFetchingNextPage,
hasNextPage,
fetchNextPage,
} = useInfiniteQuery({
queryKey: ["postQuotes", id],
queryFn: async ({ pageParam }) => {
const { data } = await agent.resolveHandle({ handle });
if (!data) return;
const uri = `at://${data.did}/app.bsky.feed.post/${id}`;
return getPostQuotes(agent, uri, pageParam);
},
initialPageParam: "",
getNextPageParam: (lastPage) => lastPage?.cursor,
});

const dataLength = quotes?.pages.reduce(
(acc, page) => acc + (page?.posts.length ?? 0),
0
);

const isEmpty = !isFetching && !isFetchingNextPage && dataLength === 0;

return (
<div>
<InfiniteScroll
dataLength={dataLength ?? 0}
next={fetchNextPage}
hasMore={hasNextPage}
loader={<LoadingSpinner />}
scrollThreshold={0.8}
className="no-scrollbar flex flex-col"
>
{quotes?.pages
.flatMap((page) => page?.posts)
.map((post, i) => (
<Fragment key={i}>
{post && <SearchPost key={i} post={post} />}
</Fragment>
))}
</InfiniteScroll>

{isFetching && !isFetchingNextPage && <FeedPostSkeleton />}
{isEmpty && !hasNextPage && (
<div className="border-skin-base border-t">
<FeedAlert
variant="empty"
message="No one has quoted this post... yet"
/>
</div>
)}
{error && (
<FeedAlert variant="badResponse" message="Something went wrong" />
)}
{!isEmpty &&
!error &&
!isFetching &&
!hasNextPage &&
!isFetchingNextPage && <EndOfFeed />}
</div>
);
}
28 changes: 14 additions & 14 deletions src/lib/api/bsky/actor/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
BskyAgent,
AtpAgent,
BskyFeedViewPreference,
LabelPreference,
BskyThreadViewPreference,
Expand All @@ -9,7 +9,7 @@ import { ContentFilterLabel } from "../../../../../types/feed";

export const getProfile = async (
handle: string | undefined,
agent?: BskyAgent,
agent?: AtpAgent,
) => {
if (!handle) return;
if (!agent) agent = await getAgent();
Expand All @@ -27,7 +27,7 @@ export const getSuggestions = async () => {
};

export const searchProfiles = async (
agent: BskyAgent,
agent: AtpAgent,
term: string,
cursor: string,
) => {
Expand All @@ -42,7 +42,7 @@ export const searchProfiles = async (
};

export const searchProfilesTypehead = async (
agent: BskyAgent,
agent: AtpAgent,
term: string,
) => {
try {
Expand All @@ -59,7 +59,7 @@ export const searchPosts = async (
term: string,
cursor: string,
sort: "latest" | "top",
agent?: BskyAgent,
agent?: AtpAgent,
) => {
if (!agent) agent = await getAgent();
try {
Expand All @@ -78,7 +78,7 @@ export const searchPosts = async (
}
};

export const getPreferences = async (agent?: BskyAgent) => {
export const getPreferences = async (agent?: AtpAgent) => {
if (!agent) agent = await getAgent();
const prefs = await agent.app.bsky.actor.getPreferences();
if (!prefs.success) throw new Error("Could not get preferences");
Expand All @@ -87,15 +87,15 @@ export const getPreferences = async (agent?: BskyAgent) => {

export const updateThreadViewPreferences = async (
pref: Partial<BskyThreadViewPreference>,
agent?: BskyAgent,
agent?: AtpAgent,
) => {
if (!agent) agent = await getAgent();
const prefs = await agent.setThreadViewPrefs(pref);
return prefs;
};
export const updateHomeFeedPreferences = async (
pref: Partial<BskyFeedViewPreference>,
agent?: BskyAgent,
agent?: AtpAgent,
) => {
if (!agent) agent = await getAgent();
const prefs = await agent.setFeedViewPrefs("home", pref);
Expand All @@ -104,7 +104,7 @@ export const updateHomeFeedPreferences = async (

export const updateIsAdultContentEnabled = async (
value: boolean,
agent?: BskyAgent,
agent?: AtpAgent,
) => {
if (!agent) agent = await getAgent();
const prefs = await agent.setAdultContentEnabled(value);
Expand All @@ -114,21 +114,21 @@ export const updateIsAdultContentEnabled = async (
export const updateContentFilterPreferences = async (
pref: ContentFilterLabel,
value: LabelPreference,
agent?: BskyAgent,
agent?: AtpAgent,
) => {
if (!agent) agent = await getAgent();
const prefs = await agent.setContentLabelPref(pref, value);
return prefs;
};

export const muteUser = async (did: string, agent?: BskyAgent) => {
export const muteUser = async (did: string, agent?: AtpAgent) => {
if (!agent) agent = await getAgent();
const mute = await agent.mute(did);
if (!mute.success) throw new Error("Could not mute user");
return mute.success;
};

export const unMuteUser = async (did: string, agent?: BskyAgent) => {
export const unMuteUser = async (did: string, agent?: AtpAgent) => {
if (!agent) agent = await getAgent();
const mute = await agent.unmute(did);
if (!mute.success) throw new Error("Could not unmute user");
Expand All @@ -138,7 +138,7 @@ export const unMuteUser = async (did: string, agent?: BskyAgent) => {
export const blockUser = async (
viewerDid: string,
did: string,
agent?: BskyAgent,
agent?: AtpAgent,
) => {
if (!agent) agent = await getAgent();
const res = await agent.app.bsky.graph.block.create(
Expand All @@ -152,7 +152,7 @@ export const blockUser = async (
export const unBlockUser = async (
viewerDid: string,
rkey: string,
agent?: BskyAgent,
agent?: AtpAgent,
) => {
if (!agent) agent = await getAgent();
await agent.app.bsky.graph.block.delete({ rkey: rkey, repo: viewerDid });
Expand Down
10 changes: 5 additions & 5 deletions src/lib/api/bsky/agent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BskyAgent } from "@atproto/api";
import { AtpAgent } from "@atproto/api";
import { redirect } from "next/navigation";
import { getSessionFromServer } from "../auth/session";

export const createAgent = () => {
const at = new BskyAgent({
const at = new AtpAgent({
service: "https://bsky.social",
});

Expand All @@ -12,7 +12,7 @@ export const createAgent = () => {

export const getBskySession = async () => {
// TODO: allow PDS URL — using bsky.social for now
const at = new BskyAgent({
const at = new AtpAgent({
service: "https://bsky.social",
});

Expand All @@ -29,6 +29,6 @@ export const getBskySession = async () => {
};

export const getAgent = async () => {
const bskyAgent = await getBskySession();
return bskyAgent;
const atpAgent = await getBskySession();
return atpAgent;
};
Loading

0 comments on commit a6e39d9

Please sign in to comment.