Skip to content

Commit 10d0450

Browse files
committed
clean code
1 parent a3581be commit 10d0450

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

routers/web/repo/setting/webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func checkHookType(ctx *context.Context) string {
121121
// WebhooksNew render creating webhook page
122122
func WebhooksNew(ctx *context.Context) {
123123
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
124-
124+
125125
// Create a new webhook with default meta settings
126126
newWebhook := &webhook.Webhook{HookEvent: &webhook_module.HookEvent{}}
127127
// Initialize meta settings with default values
@@ -215,7 +215,7 @@ func createWebhook(ctx *context.Context, params webhookParams) {
215215
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
216216
ctx.Data["PageIsSettingsHooks"] = true
217217
ctx.Data["PageIsSettingsHooksNew"] = true
218-
218+
219219
// Create a webhook with default meta settings for template rendering
220220
newWebhook := &webhook.Webhook{HookEvent: &webhook_module.HookEvent{}}
221221
if err := newWebhook.SetMetaSettings(webhook.DefaultMetaSettings()); err != nil {

web_src/js/features/repo-settings-webhook.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,30 @@
22
* Webhook settings functionality
33
*/
44

5-
function toggleLimitField(fieldName: string, enabled: boolean): void {
6-
const field = document.querySelector<HTMLInputElement>(`input[name="${fieldName}"]`);
7-
if (field) {
8-
field.disabled = !enabled;
9-
}
5+
import {toggleElemClass} from '../utils/dom.ts';
6+
7+
function setupOptimizationToggle(enableFieldName: string, limitFieldName: string): void {
8+
const enableCheckbox = document.querySelector<HTMLInputElement>(`input[name="${enableFieldName}"]`);
9+
if (!enableCheckbox) return;
10+
11+
enableCheckbox.addEventListener('change', (e) => {
12+
const target = e.target as HTMLInputElement;
13+
const limitField = document.querySelector<HTMLInputElement>(`input[name="${limitFieldName}"]`);
14+
if (limitField) {
15+
limitField.disabled = !target.checked;
16+
// Use toggleElemClass to show/hide the limit field container
17+
const limitFieldContainer = limitField.closest('.field');
18+
if (limitFieldContainer) {
19+
toggleElemClass(limitFieldContainer, 'tw-hidden', !target.checked);
20+
}
21+
}
22+
});
1023
}
1124

1225
export function initRepoSettingsWebhook(): void {
1326
if (!document.querySelector('.page-content.repository.settings.webhook')) return;
1427

15-
// Add event listeners for payload optimization checkboxes
16-
const filesEnableCheckbox = document.querySelector<HTMLInputElement>('input[name="payload_optimization_files_enable"]');
17-
const commitsEnableCheckbox = document.querySelector<HTMLInputElement>('input[name="payload_optimization_commits_enable"]');
18-
19-
if (filesEnableCheckbox) {
20-
filesEnableCheckbox.addEventListener('change', (e) => {
21-
const target = e.target as HTMLInputElement;
22-
toggleLimitField('payload_optimization_files_limit', target.checked);
23-
});
24-
}
25-
26-
if (commitsEnableCheckbox) {
27-
commitsEnableCheckbox.addEventListener('change', (e) => {
28-
const target = e.target as HTMLInputElement;
29-
toggleLimitField('payload_optimization_commits_limit', target.checked);
30-
});
31-
}
28+
// Setup payload optimization toggles
29+
setupOptimizationToggle('payload_optimization_files_enable', 'payload_optimization_files_limit');
30+
setupOptimizationToggle('payload_optimization_commits_enable', 'payload_optimization_commits_limit');
3231
}

0 commit comments

Comments
 (0)