Skip to content
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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Conversation

zner0L
Copy link

@zner0L zner0L commented Oct 16, 2024

Based on #10, which should be merged first.

@zner0L zner0L changed the title Auto reload ProceedingLandingPage while analysis is running Make content more navigable and accessible Oct 16, 2024
Comment on lines +59 to +60
if (response === 'none' && new Date() < calculateDeadline(proceeding.noticeSent))
return new Response('Give the developer until the end of the deadline to respond.', { status: 400 });
Copy link
Member

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
Copy link
Member

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}`);
Copy link
Member

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.

Copy link
Member

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`)}>

Comment on lines +25 to +31
options={(['yes', 'no'] as const).reduce(
(agg, p) =>
Object.assign(agg, {
[p]: t('common', p),
}),
{},
)}
Copy link
Member

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.

Comment on lines +14 to +15
const isChecked = (p: string) =>
(complainantIsUserOfApp === true && p === 'yes') || (complainantIsUserOfApp === false && p === 'no');
Copy link
Member

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>;
Copy link
Member

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>
Copy link
Member

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 });
Copy link
Member

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.)

Comment on lines +118 to +122
const updated = await e.update(e.Proceeding, () => ({
// eslint-disable-next-line camelcase
filter_single: { token },
set,
}));
Copy link
Member

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 });
Copy link
Member

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'
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants