MCPcopy Create free account
hub / github.com/dailydotdev/apps / updateReadingHistoryPost

Function updateReadingHistoryPost

packages/shared/src/hooks/useReadingHistory.ts:50–75  ·  view source on GitHub ↗
(
  client: QueryClient,
  user: LoggedUser | undefined,
  postId: string,
  manipulate: (post: ReadHistoryPost) => Partial<ReadHistoryPost>,
)

Source from the content-addressed store, hash-verified

48};
49
50export const updateReadingHistoryPost = (
51 client: QueryClient,
52 user: LoggedUser | undefined,
53 postId: string,
54 manipulate: (post: ReadHistoryPost) => Partial<ReadHistoryPost>,
55): (() => void) =>
56 updateReadingHistoryQueries(client, user, (data) => ({
57 ...data,
58 pages: data.pages.map((page) => ({
59 ...page,
60 readHistory: {
61 ...page.readHistory,
62 edges: page.readHistory.edges.map((edge) =>
63 edge.node.post.id === postId
64 ? {
65 ...edge,
66 node: {
67 ...edge.node,
68 post: { ...edge.node.post, ...manipulate(edge.node.post) },
69 },
70 }
71 : edge,
72 ),
73 },
74 })),
75 }));
76
77const isSameRead = (a?: Date | string, b?: Date | string): boolean =>
78 !!a && !!b && new Date(a).getTime() === new Date(b).getTime();

Callers 3

ReadingHistoryPostPaneFunction · 0.90
useReadHistoryVotePostFunction · 0.90

Calls 1

Tested by

no test coverage detected