monkeytype/frontend
torturado 44a67db9fc
feat(commandline): add download screenshot command (@torturado) (#6532)
### Description

This Pull Request introduces the functionality to download the result
screenshot directly as a PNG file, in addition to the existing option to
copy it to the clipboard.

This is achieved by:
1.  Refactoring the screenshot logic in `test-ui.ts`.
2. Adding a new `Download screenshot` command to the result screen
command list.

**Changes Made:**

*   **`frontend/src/ts/test/test-ui.ts`**:
* Created an internal function `generateScreenshotCanvas` that
encapsulates UI preparation, canvas generation with `html2canvas`, and
UI restoration.
* Modified the exported `screenshot` function to use
`generateScreenshotCanvas` and **only** handle copying the resulting
Blob to the clipboard (with the fallback of opening in a new tab).
* Added a new exported function `getScreenshotBlob` that uses
`generateScreenshotCanvas` and returns the resulting image Blob.
*   **`frontend/src/ts/commandline/lists/result-screen.ts`**:
* Renamed the `saveScreenshot` command to `copyScreenshot` (updating
`id`, `icon`, and `alias`) to more accurately reflect its action. It
still uses `TestUI.screenshot()`.
* Added a new `downloadScreenshot` command (`id`, `display`, `icon`,
`alias`) that:
        *   Calls `TestUI.getScreenshotBlob()` to get the image data.
        *   If a Blob is obtained, creates a temporary object URL.
* Creates a temporary `<a>` element, sets the `href` to the object URL,
and the `download` attribute with a filename (e.g.,
`monkeytype-result-TIMESTAMP.png`).
        *   Simulates a click on the link to initiate the file download.
        *   Revokes the object URL.
        *   Displays success or error notifications.

### Checks

- [ ] Adding quotes?
- [ ] Make sure to include translations for the quotes in the
description (or another comment) so we can verify their content.
- [ ] Adding a language or a theme?
- [ ] If is a language, did you edit `_list.json`, `_groups.json` and
add `languages.json`?
  - [ ] If is a theme, did you add the theme.css?
- Also please add a screenshot of the theme, it would be extra awesome
if you do so!
- [ ] Check if any open issues are related to this PR; if so, be sure to
tag them below.
- [x] Make sure the PR title follows the Conventional Commits standard.
(https://www.conventionalcommits.org for more info)
- [ ] Make sure to include your GitHub username prefixed with @ inside
parentheses at the end of the PR title. <!-- Remember to add your
username here! -->

---------

Co-authored-by: fehmer <3728838+fehmer@users.noreply.github.com>
Co-authored-by: Miodec <jack@monkeytype.com>
2025-05-07 16:21:30 +02:00
..
__tests__ refactor: move languages to contracts (@fehmer) (#6497) 2025-05-07 14:02:27 +02:00
docker fix: local development using docker not working with pnpm (@fehmer) (#6401) 2025-03-26 13:11:02 +01:00
scripts refactor: move languages to contracts (@fehmer) (#6497) 2025-05-07 14:02:27 +02:00
src feat(commandline): add download screenshot command (@torturado) (#6532) 2025-05-07 16:21:30 +02:00
static impr(quotes): add Indonesian quotes (@siily-g) (#6522) 2025-05-07 15:47:09 +02:00
.eslintrc.cjs
.firebaserc_example
.oxlintrc.json refactor: enable ban-ts-comment rule 2025-04-16 19:15:30 +02:00
firebase.json
gulpfile.js chore: add oxlint (@miodec) (#6455) 2025-04-16 17:18:50 +02:00
knip.json
package.json build(deps-dev): bump vite from 6.3.0 to 6.3.4 in /frontend (#6510) 2025-05-02 19:50:40 +02:00
tsconfig.json refactor: remove global type namespaces (@miodec) (#5907) 2024-09-23 15:34:16 +02:00
vite.config.dev.js chore: add oxlint (@miodec) (#6455) 2025-04-16 17:18:50 +02:00
vite.config.js chore: add sentry 2025-04-29 17:36:23 +02:00
vite.config.prod.js chore: try to use auto commit detection again 2025-05-03 12:02:51 +02:00
vitest.config.js refactor: move funboxes to a shared package (@miodec) (#6063) 2024-12-04 16:11:07 +01:00