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

Function updateCachedPlugin

packages/shared/src/hooks/vote/useVotePlugin.ts:26–51  ·  view source on GitHub ↗
(
  client: QueryClient,
  id: string,
  vote: UserVote,
)

Source from the content-addressed store, hash-verified

24};
25
26const updateCachedPlugin = (
27 client: QueryClient,
28 id: string,
29 vote: UserVote,
30): UserVote | undefined => {
31 let previousVote: UserVote | undefined;
32 const update = (plugin: Plugin): Plugin => {
33 if (plugin.id !== id) {
34 return plugin;
35 }
36
37 previousVote = plugin.userVote ?? UserVote.None;
38
39 return applyPluginVote(plugin, vote);
40 };
41
42 client.setQueriesData<Plugin[]>(
43 { queryKey: [RequestKey.Plugins] },
44 (plugins) => plugins?.map(update),
45 );
46 client.setQueriesData<Plugin>({ queryKey: [RequestKey.Plugin] }, (plugin) =>
47 plugin ? update(plugin) : plugin,
48 );
49
50 return previousVote;
51};
52
53interface UseVotePlugin {
54 toggleUpvote: (plugin: Plugin) => Promise<void>;

Callers 1

onMutateFunction · 0.85

Calls 1

updateFunction · 0.70

Tested by

no test coverage detected