-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make content more navigable and accessible #16
base: main
Are you sure you want to change the base?
Conversation
073f1c6
to
1bff948
Compare
if (response === 'none' && new Date() < calculateDeadline(proceeding.noticeSent)) | ||
return new Response('Give the developer until the end of the deadline to respond.', { status: 400 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just move this up (before the if
)?
}, | ||
})) | ||
.run(client); | ||
} else return new Response('You cannot evaluate the response to this proceeding now.', { status: 400 }); // Arguably, we might fails more gracefully if we redirect to /p/ here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My beautiful early return. :'(
@@ -36,27 +21,5 @@ if (proceeding.state !== 'awaitingComplaint') return new Response('You cannot se | |||
const state = proceeding.complaintState; | |||
if (!state || !isValidComplaintState(state)) throw new Error('This should never happen.'); | |||
|
|||
const { developerName, privacyPolicyUrl, complaintAuthority } = proceeding; | |||
return Astro.redirect(`/p/${token}/complain/${state}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that we're keeping the alias and it always redirects you to the correct page, but we should still update all existing links here to avoid the unnecessary redirect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. I see now that you already did this in most places and only missed one:
<a class="button button-primary" href={absUrl(`/p/${token}/complain`)}> |
options={(['yes', 'no'] as const).reduce( | ||
(agg, p) => | ||
Object.assign(agg, { | ||
[p]: t('common', p), | ||
}), | ||
{}, | ||
)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean… I love a good reduce
as much as the next person, but for two very simple properties it's a bit silly (it's literally more code than just writing out the object! :D) and obfuscates the semantics.
const isChecked = (p: string) => | ||
(complainantIsUserOfApp === true && p === 'yes') || (complainantIsUserOfApp === false && p === 'no'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused.
</div> | ||
|
||
<script> | ||
const forms = document.getElementsByClassName('astro-radio-form') as HTMLCollectionOf<HTMLFormElement>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this run for every form on the page, causing multiple event handlers to be registered if there are multiple forms? You know the ID of 'your' form, you only need to add it to that one.
</div> | ||
)) | ||
} | ||
<button type="submit" class="button sr-only">{t('common', 'continue')}</button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also needs to be visible to users with JS disabled.
.run(client); | ||
if (!proceeding) return new Response('Invalid token.', { status: 403 }); | ||
|
||
if (proceeding.state !== 'awaitingComplaint') return new Response('You answer this question now.', { status: 400 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You, answer this question now! :'D (I know this was my fault.)
const updated = await e.update(e.Proceeding, () => ({ | ||
// eslint-disable-next-line camelcase | ||
filter_single: { token }, | ||
set, | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are only constructing the query but not executing it.
return redirect(`/p/${token}/complain/${updatedProceeding?.complaintState || ''}`); | ||
} catch (error) { | ||
if (error instanceof z.ZodError) { | ||
return new Response('Zod validation of your request failed.', { status: 401 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hitting this when trying to answer askIsUserOfApp
.
ZodError: [
{
"expected": "'yes' | 'no'",
"received": "undefined",
"code": "invalid_type",
"path": [
"answer"
],
"message": "Required"
}
]
at get error [as error] (file:///home/benni/coding/JS/tweasel/platform/node_modules/zod/lib/index.mjs:587:31)
at ZodEffects.parse (file:///home/benni/coding/JS/tweasel/platform/node_modules/zod/lib/index.mjs:692:22)
at Module.POST (/home/benni/coding/JS/tweasel/platform/src/pages/p/[token]/complain/[question]/answer.ts:51:10)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async renderEndpoint (file:///home/benni/coding/JS/tweasel/platform/node_modules/astro/dist/runtime/server/endpoint.js:34:20)
at async lastNext (file:///home/benni/coding/JS/tweasel/platform/node_modules/astro/dist/core/render-context.js:125:23)
at async file:///home/benni/coding/JS/tweasel/platform/node_modules/astro/dist/i18n/middleware.js:49:22
at async callMiddleware (file:///home/benni/coding/JS/tweasel/platform/node_modules/astro/dist/core/middleware/callMiddleware.js:21:10)
at async RenderContext.render (file:///home/benni/coding/JS/tweasel/platform/node_modules/astro/dist/core/render-context.js:161:22)
at async handleRoute (file:///home/benni/coding/JS/tweasel/platform/node_modules/astro/dist/vite-plugin-astro-server/route.js:157:16)
at async run (file:///home/benni/coding/JS/tweasel/platform/node_modules/astro/dist/vite-plugin-astro-server/request.js:40:14)
at async runWithErrorHandling (file:///home/benni/coding/JS/tweasel/platform/node_modules/astro/dist/vite-plugin-astro-server/controller.js:64:5)
at async handleRequest (file:///home/benni/coding/JS/tweasel/platform/node_modules/astro/dist/vite-plugin-astro-server/request.js:34:3) {
issues: [
{
expected: "'yes' | 'no'",
received: 'undefined',
code: 'invalid_type',
path: [Array],
message: 'Required'
}
],
addIssue: [Function (anonymous)],
addIssues: [Function (anonymous)],
errors: [
{
expected: "'yes' | 'no'",
received: 'undefined',
code: 'invalid_type',
path: [Array],
message: 'Required'
}
]
}
Based on #10, which should be merged first.