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

Function useUserStack

packages/shared/src/features/profile/hooks/useUserStack.ts:25–115  ·  view source on GitHub ↗
(user: PublicProfile | null)

Source from the content-addressed store, hash-verified

23const selectStack = (data: ProfileShowcase) => data.userStack;
24
25export function useUserStack(user: PublicProfile | null) {
26 const { isOwner } = useProfilePreview(user);
27 const { logEvent } = useLogContext();
28
29 const {
30 queryKey,
31 invalidate: invalidateQuery,
32 ...query
33 } = useProfileShowcase(user, selectStack);
34
35 const stackItems = useMemo(
36 () => query.data?.edges?.map(({ node }) => node) ?? [],
37 [query.data],
38 );
39 const canAddMore = stackItems.length < MAX_STACK_ITEMS;
40
41 // Group items by section
42 const groupedBySection = useMemo(() => {
43 const groups: Record<string, UserStack[]> = {};
44 stackItems.forEach((item) => {
45 if (!groups[item.section]) {
46 groups[item.section] = [];
47 }
48 groups[item.section].push(item);
49 });
50 return groups;
51 }, [stackItems]);
52
53 const addMutation = useMutation({
54 mutationFn: (input: AddUserStackInput) => addUserStack(input),
55 onSuccess: (_, input) => {
56 invalidateQuery();
57 logEvent({
58 event_name: LogEvent.AddUserStack,
59 target_id: input.title,
60 extra: JSON.stringify({ section: input.section }),
61 });
62 },
63 });
64
65 const updateMutation = useMutation({
66 mutationFn: ({ id, input }: { id: string; input: UpdateUserStackInput }) =>
67 updateUserStack(id, input),
68 onSuccess: (_, { id }) => {
69 invalidateQuery();
70 logEvent({
71 event_name: LogEvent.UpdateUserStack,
72 extra: JSON.stringify({ id }),
73 });
74 },
75 });
76
77 const deleteMutation = useMutation({
78 mutationFn: (id: string) => deleteUserStack(id),
79 onSuccess: (_, id) => {
80 invalidateQuery();
81 logEvent({
82 event_name: LogEvent.RemoveUserStack,

Callers 3

MentionedToolsWidgetFunction · 0.90
ProfileUserStackFunction · 0.90

Calls 9

useProfilePreviewFunction · 0.90
useLogContextFunction · 0.90
useProfileShowcaseFunction · 0.90
addUserStackFunction · 0.90
updateUserStackFunction · 0.90
deleteUserStackFunction · 0.90
reorderUserStackFunction · 0.90
logEventFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected