diff --git a/changelog.d/feedback-dialog.changed.md b/changelog.d/feedback-dialog.changed.md new file mode 100644 index 00000000..a2afe05c --- /dev/null +++ b/changelog.d/feedback-dialog.changed.md @@ -0,0 +1 @@ +Feedback is now a global dialog opened from the footer, so sending a note no longer leaves the page. The Settings form remains as the no-JavaScript fallback and keeps the feedback history, the duplicate feedback button in the About card is gone, and submitting returns to the page the note was written on. diff --git a/public/app.css b/public/app.css index c0a06491..155b7463 100644 --- a/public/app.css +++ b/public/app.css @@ -1168,6 +1168,8 @@ a.list-row:hover strong { color: var(--accent); } .repos-head { align-items: center; gap: 12px; margin-bottom: 12px; } .repos-head h2 { margin: 0; } .add-repo-dialog { width: min(680px, calc(100vw - 32px)); max-height: min(80vh, 720px); overflow: auto; border: 1px solid var(--line-strong); border-radius: var(--radius-md); padding: 22px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); } +.feedback-dialog { width: min(560px, calc(100vw - 32px)); } +.feedback-dialog .dialog-head .link { font-size: 20px; line-height: 1; } .add-repo-dialog::backdrop { background: rgba(0, 0, 0, 0.62); } .add-repo-dialog .dialog-head { position: sticky; top: 0; z-index: 1; align-items: center; background: var(--panel); padding-bottom: 8px; } .add-repo-dialog .dialog-head h2 { margin: 0; } diff --git a/public/app.js b/public/app.js index 3c3ac4e1..75d482c2 100644 --- a/public/app.js +++ b/public/app.js @@ -243,9 +243,12 @@ dialog.addEventListener('close', () => clearDialogHash(dialog)) }) document.querySelectorAll('[data-open-dialog]').forEach((button) => { - button.addEventListener('click', () => { + button.addEventListener('click', (event) => { const dialog = document.getElementById(button.getAttribute('data-open-dialog') ?? '') if (dialog === null || !openDialog(dialog)) return + // The trigger may be an : the href is the + // no-JavaScript fallback, so the enhancement must stop the navigation. + event.preventDefault() if (location.hash !== `#${dialog.id}`) history.replaceState(null, '', `${location.pathname}${location.search}#${dialog.id}`) }) }) diff --git a/src/app.ts b/src/app.ts index 68abde51..e56aa67b 100644 --- a/src/app.ts +++ b/src/app.ts @@ -4482,7 +4482,12 @@ export async function buildApp(options: BuildOptions): Promise { const kind = body.kind === 'bug' || body.kind === 'other' ? body.kind : 'feedback' const message = redact((body.message ?? '').trim()).slice(0, 2000) const page = (body.page ?? '').trim().slice(0, 200) - if (message === '') return reply.redirect(`/settings?error=${encodeURIComponent('请填写反馈内容。')}#feedback`) + const returnTo = safeLocalPath(body.returnTo, '/settings') + const back = (key: 'notice' | 'error', text: string): string => { + const target = withMessageParam(returnTo, key, text) + return returnTo.startsWith('/settings') ? `${target}#feedback` : target + } + if (message === '') return reply.redirect(back('error', '请填写反馈内容。')) const id = randomId('fb') const createdAt = new Date().toISOString() const publishConsent = body.publishConsent === '1' @@ -4497,10 +4502,10 @@ export async function buildApp(options: BuildOptions): Promise { ...feedbackMail({ id, login: viewer.user.login, kind, message, page, createdAt }), ...(replyTo === '' ? {} : { replyTo }), }) - return reply.redirect(`/settings?notice=${encodeURIComponent('反馈已发送,谢谢。')}#feedback`) + return reply.redirect(back('notice', '反馈已发送,谢谢。')) } catch (error) { log.error('feedback mail failed', { id, error: redact(String(error)) }) - return reply.redirect(`/settings?error=${encodeURIComponent('反馈已保存,但通知邮件发送失败;请稍后再试。')}#feedback`) + return reply.redirect(back('error', '反馈已保存,但通知邮件发送失败;请稍后再试。')) } }) diff --git a/src/views/layout.ts b/src/views/layout.ts index 222831ff..c2f9bfaa 100644 --- a/src/views/layout.ts +++ b/src/views/layout.ts @@ -272,13 +272,45 @@ export function layout(options: LayoutOptions): string {
` const brandSmall = locale === 'zh' ? '羽巢' : '' + // Feedback is a global action, not a Settings section. The dialog uses the + // existing [data-open-dialog] pattern; the footer link keeps /settings#feedback + // as the no-JavaScript fallback and the inline form remains on Settings. + const onSettings = cleanPath === '/settings' || cleanPath.startsWith('/settings/') + const feedbackViewer = viewer !== undefined && viewer !== null && viewer.user.status === 'approved' && !onSettings ? viewer : null + const feedbackHref = onSettings ? '#feedback' : '/settings#feedback' + const feedbackAttrs = feedbackViewer === null ? '' : ' data-open-dialog="feedback-dialog" aria-haspopup="dialog" aria-controls="feedback-dialog"' + const feedbackDialog = feedbackViewer === null ? '' : `` const footer = `
` @@ -310,6 +342,7 @@ export function layout(options: LayoutOptions): string { ${body} ${footer} + ${feedbackDialog}
diff --git a/src/views/pages.ts b/src/views/pages.ts index 53eac655..29008c7e 100644 --- a/src/views/pages.ts +++ b/src/views/pages.ts @@ -2309,7 +2309,7 @@ export function settingsPage(input: { -