Skip to content

Comments

Implement paste event for image file input#138

Closed
KavyanshKhaitan2 wants to merge 4 commits intohackclub:stagingfrom
KavyanshKhaitan2:patch-1
Closed

Implement paste event for image file input#138
KavyanshKhaitan2 wants to merge 4 commits intohackclub:stagingfrom
KavyanshKhaitan2:patch-1

Conversation

@KavyanshKhaitan2
Copy link
Contributor

Add paste functionality for image uploads in project description.

ArcaEge and others added 2 commits February 1, 2026 16:04
Add paste functionality for image uploads in project description.
@ArcaEge
Copy link
Collaborator

ArcaEge commented Feb 7, 2026

Let me have a look

@ArcaEge ArcaEge changed the base branch from main to staging February 7, 2026 22:29
Copy link
Collaborator

@ArcaEge ArcaEge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'd need to put this inside an onMount(() => {}) because of server side rendering

@KavyanshKhaitan2
Copy link
Contributor Author

okay.

Add DOMContentLoaded event listener for paste area and file input.
@KavyanshKhaitan2
Copy link
Contributor Author

@ArcaEge please review this again.


let formPending = $state(false);

onMount(() => {

This comment was marked as outdated.

<label class="flex flex-col gap-1">
Description
<CharCountedTextarea
id="description"

This comment was marked as outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do i do this?


onMount(() => {

document.addEventListener('DOMContentLoaded', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for DOMContentLoaded since this is inside onMount

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Don't really do js so don't know lol.

Removed unnecessary DOMContentLoaded event listener.

let formPending = $state(false);

onMount(() => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The component will crash on initialization due to a missing onMount import. It also contains a null pointer exception for non-project owners.
Severity: CRITICAL

Suggested Fix

Import onMount from 'svelte' at the top of the script block: import { onMount } from 'svelte';. Additionally, add a null check inside the onMount callback to ensure fileInput is not null before adding an event listener to it.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/routes/dashboard/projects/[id]/+page.svelte#L41

Potential issue: The `onMount` lifecycle function is called on line 41 but is not
imported from 'svelte'. This will cause a `ReferenceError` when the component is
initialized, preventing it from rendering. Additionally, even if the import were
present, the code within `onMount` attempts to access an element with `id="imagefield"`
without checking if it exists. This element is only rendered if the current user is the
project owner. For any other user, `document.getElementById('imagefield')` will return
`null`, causing a `TypeError` when the code attempts to call `addEventListener` on it.

Comment on lines +46 to +49
pasteArea.addEventListener('paste', (event) => {
// Prevent the default paste behavior (e.g., pasting into the contenteditable div as text/html)
// Access the clipboard data items
const items = event.clipboardData.items;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The paste event handler for the description field is missing event.preventDefault(), causing image filenames to be incorrectly inserted into the textarea upon paste.
Severity: MEDIUM

Suggested Fix

Add event.preventDefault(); inside the 'paste' event listener callback in the onMount function. This will prevent the browser's default behavior of inserting the filename into the textarea.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/routes/dashboard/projects/[id]/+page.svelte#L46-L49

Potential issue: A 'paste' event listener is attached to the description textarea to
handle image pasting. However, the implementation is missing a call to
`event.preventDefault()`. The developer's intent, as stated in a code comment, was to
prevent the default paste behavior. Without this call, when a user pastes an image, the
browser's default action will still occur, which for a `<textarea>` is to insert the
image's filename as text. This results in the description field being polluted with the
filename.

Copy link
Collaborator

@ArcaEge ArcaEge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this at all to see if it works?

@KavyanshKhaitan2
Copy link
Contributor Author

I have NO IDEA how to run nextjs lol.

If you want, you can push changes to this branch. That's possible for ya.

@KavyanshKhaitan2
Copy link
Contributor Author

Im more of a Python or Django person.

@ArcaEge
Copy link
Collaborator

ArcaEge commented Feb 11, 2026

I think I'm going to close this in favour of #147

@ArcaEge ArcaEge closed this Feb 11, 2026
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