Skip to content

Commit

Permalink
Replaced get_discussion with get_content_replies in a waves
Browse files Browse the repository at this point in the history
  • Loading branch information
dkildar committed Jan 29, 2025
1 parent 4388f27 commit a66f8d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
24 changes: 11 additions & 13 deletions src/api/queries/waves/get-waves-by-host-query.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { EcencyQueriesManager, QueryIdentifiers } from "@/core/react-query";
import * as bridgeApi from "@/api/bridge";
import { ProfileFilter } from "@/enums";
import { WaveEntry } from "@/entities";
import { Entry, WaveEntry } from "@/entities";
import { client } from "@/api/hive";

async function getThreads(host: string, pageParam?: WaveEntry) {
let nextThreadContainers = (
Expand All @@ -22,38 +23,35 @@ async function getThreads(host: string, pageParam?: WaveEntry) {
return [];
}

const threadItems = await bridgeApi.getDiscussion(host, nextThreadContainers[0].permlink);
const items = (await client.call("condenser_api", "get_content_replies", [
host,
nextThreadContainers[0].permlink
])) as Entry[];
// const threadItems = await bridgeApi.getDiscussion(host, nextThreadContainers[0].permlink);

// If no discussion need to fetch next container
if (Object.values(threadItems || {}).length === 1) {
if (items.length === 0) {
return getThreads(host, nextThreadContainers[0]);
}

return [threadItems, nextThreadContainers] as const;
return [items, nextThreadContainers] as const;
}

export const getWavesByHostQuery = (host: string) =>
EcencyQueriesManager.generateClientServerInfiniteQuery({
queryKey: [QueryIdentifiers.THREADS, host],
queryFn: async ({ pageParam }) => {
const [items, nextThreadContainers] = await getThreads(host, pageParam);
const flattenThreadItems = Object.values(items ?? {})
// Filter only parent thread items
.filter(
({ parent_author, parent_permlink }) =>
parent_author === nextThreadContainers[0].author &&
parent_permlink === nextThreadContainers[0].permlink
);

return flattenThreadItems
return items
.map(
(item) =>
({
...item,
id: item.post_id,
host,
container: nextThreadContainers[0],
parent: flattenThreadItems.find(
parent: items.find(
(i) =>
i.author === item.parent_author &&
i.permlink === item.parent_permlink &&
Expand Down
5 changes: 3 additions & 2 deletions src/app/waves/_components/waves-list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export function WavesListItem({
}: Props) {
const [grid] = useWavesGrid();

const renderAreaRef = useRef<HTMLDivElement>(null);
const rootRef = useRef<HTMLDivElement>(null);
const router = useRouter();
const { inViewport } = useInViewport(renderAreaRef);
const { inViewport } = useInViewport(rootRef);

const [showEditModal, setShowEditModal] = useState(false);

Expand Down Expand Up @@ -80,6 +80,7 @@ export function WavesListItem({

return (
<motion.div
ref={rootRef}
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ delay: i * 0.2 }}
Expand Down

0 comments on commit a66f8d9

Please sign in to comment.