({
ignoreEvent, makeAlert, name, onMatchingSynonym, selectedRepoId, setName, parentTopicId,
updateTopicId,
}: Props<E>)
| 115 | } |
| 116 | |
| 117 | export 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 | } |
no test coverage detected