Skip to content

Commit 2cf5087

Browse files
committed
fix: update adjacent feed API response handling
1 parent 0278244 commit 2cf5087

2 files changed

Lines changed: 8 additions & 24 deletions

File tree

client/src/api/client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
TimelineItem,
1414
CreateFeedRequest,
1515
UpdateFeedRequest,
16+
AdjacentFeedResponse,
1617
UserProfile,
1718
UpdateProfileRequest,
1819
Tag,
@@ -134,6 +135,7 @@ export type {
134135
TimelineItem,
135136
CreateFeedRequest,
136137
UpdateFeedRequest,
138+
AdjacentFeedResponse,
137139
UserProfile,
138140
UpdateProfileRequest,
139141
Tag,
@@ -313,8 +315,8 @@ class FeedAPI {
313315
}
314316

315317
// GET /api/feed/adjacent/:id
316-
async adjacent(id: number | string): Promise<ApiResponse<{ prev: Feed | null; next: Feed | null }>> {
317-
return this.http.get<{ prev: Feed | null; next: Feed | null }>(`/api/feed/adjacent/${id}`);
318+
async adjacent(id: number | string): Promise<ApiResponse<AdjacentFeedResponse>> {
319+
return this.http.get<AdjacentFeedResponse>(`/api/feed/adjacent/${id}`);
318320
}
319321

320322
// POST /api/feed/top/:id

client/src/components/adjacent_feed.tsx

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,21 @@
1+
import type { AdjacentFeed, AdjacentFeedResponse } from "@rin/api";
12
import {useEffect, useState} from "react";
23
import { client } from "../app/runtime";
34
import {timeago} from "../utils/timeago.ts";
45
import {Link} from "wouter";
56
import {useTranslation} from "react-i18next";
67

7-
export type AdjacentFeed = {
8-
id: number;
9-
title: string | null;
10-
summary?: string;
11-
hashtags?: {
12-
id: number;
13-
name: string;
14-
}[];
15-
createdAt: Date | string;
16-
updatedAt: Date | string;
17-
};
18-
export type AdjacentFeeds = {
19-
nextFeed: AdjacentFeed | null;
20-
previousFeed: AdjacentFeed | null;
21-
};
22-
238
export function AdjacentSection({id, setError}: { id: string, setError: (error: string) => void }) {
24-
const [adjacentFeeds, setAdjacentFeeds] = useState<AdjacentFeeds>();
9+
const [adjacentFeeds, setAdjacentFeeds] = useState<AdjacentFeedResponse>();
2510

2611
useEffect(() => {
2712
client.feed
2813
.adjacent(id)
2914
.then(({data, error}) => {
3015
if (error) {
3116
setError(error.value as string);
32-
} else if (data) {
33-
setAdjacentFeeds({
34-
nextFeed: data.next,
35-
previousFeed: data.prev
36-
});
17+
} else if (data && typeof data !== "string") {
18+
setAdjacentFeeds(data);
3719
}
3820
});
3921
}, [id, setError]);

0 commit comments

Comments
 (0)