MCPcopy Create free account
hub / github.com/emwalker/digraph / makeUpsertTopic

Function makeUpsertTopic

client/src/mutations/upsertTopicMutation.ts:117–161  ·  view source on GitHub ↗
({
  ignoreEvent, makeAlert, name, onMatchingSynonym, selectedRepoId, setName, parentTopicId,
  updateTopicId,
}: Props<E>)

Source from the content-addressed store, hash-verified

115}
116
117export function makeUpsertTopic<E>({
118 ignoreEvent, makeAlert, name, onMatchingSynonym, selectedRepoId, setName, parentTopicId,
119 updateTopicId,
120}: Props<E>) {
121 const upsertTopic = useMutation<upsertTopicMutation>(query)[0]
122
123 const onCompleted = useCallback(((response: ResponseType) => {
124 const alerts = response.upsertTopic?.alerts || []
125 const matchingTopics = response.upsertTopic?.matchingTopics || []
126 const addAlert = window.flashMessages?.addAlert
127 if (addAlert == null) return
128
129 for (const alert of alerts)
130 addAlert(makeAlert(alert, matchingTopics))
131 }), [makeAlert])
132
133 return useCallback(
134 (event: E) => {
135 if (ignoreEvent && ignoreEvent(event)) return
136
137 if (!selectedRepoId) {
138 console.log('repo not selected')
139 return
140 }
141
142 upsertTopic({
143 onCompleted,
144 updater: makeUpdater(parentTopicId),
145 optimisticUpdater: makeOptimisticUpdater(parentTopicId, name),
146 variables: {
147 input: {
148 name,
149 onMatchingSynonym,
150 parentTopicId,
151 repoId: selectedRepoId,
152 updateTopicId,
153 },
154 },
155 })
156
157 setName?.('')
158 },
159 [upsertTopic, selectedRepoId, parentTopicId, name, setName, makeUpdater, makeOptimisticUpdater],
160 )
161}

Callers 3

AddTopicFunction · 0.90
CreateTopicFunction · 0.90
UpdateTopicFunction · 0.90

Calls 2

makeOptimisticUpdaterFunction · 0.85
makeUpdaterFunction · 0.70

Tested by

no test coverage detected