MCPcopy Index your code
hub / github.com/refined-github/refined-github / addButton

Function addButton

source/features/status-subscription.tsx:147–189  ·  view source on GitHub ↗
(subscriptionButton: HTMLButtonElement)

Source from the content-addressed store, hash-verified

145}
146
147async function addButton(subscriptionButton: HTMLButtonElement): Promise<void> {
148 const previousRghButton = $optional('.rgh-status-subscription', subscriptionButton.parentElement!);
149 const issue = await fetchIssueData();
150 const {id, viewerThreadSubscriptionFormAction, viewerCustomSubscriptionEvents} = issue.repository.issue;
151 const isSubscribed = viewerThreadSubscriptionFormAction === 'UNSUBSCRIBE';
152 const status: SubscriptionStatus = isSubscribed
153 ? (viewerCustomSubscriptionEvents.length > 0 ? 'status' : 'all')
154 : 'none';
155
156 const getOnClick = (target: SubscriptionStatus) => async (event: React.MouseEvent) => {
157 closestElement('fieldset', event.currentTarget).disabled = true;
158 await updateSubscription(target, id);
159 void addButton(subscriptionButton);
160 };
161
162 subscriptionButton.after(
163 // Use `fieldset` so that it can be disabled
164 <fieldset className="rgh-status-subscription BtnGroup d-flex width-full">
165 {tooltipped(
166 {label: 'Unsubscribe', direction: 'sw'},
167 <Button onClick={getOnClick('none')} {...(status === 'none' && disableAttributes)}>
168 <BellSlashIcon /> None
169 </Button>,
170 )}
171 {tooltipped(
172 {label: 'Subscribe to all events', direction: 'sw'},
173 <Button onClick={getOnClick('all')} {...(status === 'all' && disableAttributes)}>
174 <BellIcon /> All
175 </Button>,
176 )}
177 {tooltipped(
178 {label: multilineAriaLabel('Subscribe just to status changes', '(closing, reopening, merging)'), direction: 'sw'},
179 <Button onClick={getOnClick('status')} {...(status === 'status' && disableAttributes)}>
180 <IssueReopenedIcon /> Status
181 </Button>,
182 )}
183 </fieldset>,
184 );
185
186 // Would be missing on the first run
187 previousRghButton?.remove();
188 subscriptionButton.hidden = true;
189}
190
191function init(signal: AbortSignal): void {
192 // Repos you're ignoring can't be subscribed to, so the button is disabled

Callers 1

getOnClickFunction · 0.70

Calls 5

fetchIssueDataFunction · 0.85
tooltippedFunction · 0.85
getOnClickFunction · 0.85
multilineAriaLabelFunction · 0.85
removeMethod · 0.80

Tested by

no test coverage detected