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

Muokkaus-näppäin json-serveriin #9

Merged
merged 28 commits into from
Feb 2, 2024
Merged

Conversation

anttiasmala
Copy link
Collaborator

Muokkaus-nappula. Muutama lisäasia lisätty myös, kuten ESC-näppäin sulkee muokkaus-modalin. Klikatessaan muokkaus-modalissa olevaa Input-elementtiä menee kursori tekstin eteen eikä taakse automaattisesti. Myöskin jos lahjaa ei löydykkään palvelimelta, Axios-errorin ei pitäisi enää heittää fatal-erroria

Antti Asmala and others added 23 commits December 19, 2023 12:09
…es to be more clarifying which modal they're refering to. Created a new button for modifying the gift. Changed the way how jsonServerFunctions are exported.
…t should only get one gift due to IDs should be individual
…e as the function itself. Removed an unnecessary check from the server if the gift that should be deleted exists. Added a catch method to check if got an error while deleting the gift
…iftListRefreshFunction to refreshGiftList to match with the function name itself. Created a new useEffect to that takes key inputs. If ESC-key is pressed, closes the modal and refreshes the giftlist. Changed the way how gifts are getting updated. Added some basic styling into SVG images
Copy link

vercel bot commented Jan 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lahjalista ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 2, 2024 8:24am

Copy link
Owner

@samuliasmala samuliasmala left a comment

Choose a reason for hiding this comment

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

Muokkausnappula toimi hienost! 👍 Muutama koodin tyyliin liittyvä muutosehdotus.

Klikatessaan muokkaus-modalissa olevaa Input-elementtiä menee kursori tekstin eteen eikä taakse automaattisesti.

Mulla tämä toimii hienosti, eli kursori menee just siihen mihin hiirellä klikkaan.

async function handleEdit(e: FormEvent<HTMLElement>) {
e.preventDefault();

const newGift = gift;
Copy link
Owner

Choose a reason for hiding this comment

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

Tässä newGift ei ole kopio vaan viittaa samaan objektiin muistissa. Sen seurauksena seuraavalla rivillä muokkaat alkuperäistä objektia eli muokkaat funktion parametria mikä ei ole hyvä, Täältä kannattaa lukea lisää value vs reference erosta, on tärkeä JavaScriptin käsite.

Copy link
Collaborator Author

@anttiasmala anttiasmala Feb 1, 2024

Choose a reason for hiding this comment

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

Hyvä nosto! En edes tajunnut tuota!

const newGift = Object.assign({}, gift);

Tuo näyttäisi kopioivan, kun testailin. 👍

Edit: poistin lopulta tuon newGiftin, sitä ei pitäisi tarvita Patch-methodin takia 👍

Copy link
Owner

@samuliasmala samuliasmala Feb 1, 2024

Choose a reason for hiding this comment

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

Jos kopioitava objekti ei sisällä sisäkkäisiä objekteja, niin silloin teen kopion näin (sama tulos kuin sun Object.assignilla):

const newGift = { ...gift};

Jos taas kopioitavassa objektissa on sisäkkäisiä objekteja, niin ne eivät kopioidu tuolla. Silloin helpointa on käyttää structuredClone funktiota:

const newGift = structuredClone(gift);

Mut tässä näitä ei tosiaan enää tarvitse, kun siirryit käyttämään patch-metodia.

…ng ESC will not refresh giftlist. Changed the way how updateGift gets its data. Added a try/catch block
try {
await removeGift(gift.id);
} catch (e) {
console.log(e);
Copy link
Owner

Choose a reason for hiding this comment

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

Tämä console.log on mielestäni tarpeeton, kun alla lokitetaan joka tapauksessa.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oli näköjään testi console.log jäänyt siihen 😅

async function handleEdit(e: FormEvent<HTMLElement>) {
e.preventDefault();

const newGift = gift;
Copy link
Owner

@samuliasmala samuliasmala Feb 1, 2024

Choose a reason for hiding this comment

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

Jos kopioitava objekti ei sisällä sisäkkäisiä objekteja, niin silloin teen kopion näin (sama tulos kuin sun Object.assignilla):

const newGift = { ...gift};

Jos taas kopioitavassa objektissa on sisäkkäisiä objekteja, niin ne eivät kopioidu tuolla. Silloin helpointa on käyttää structuredClone funktiota:

const newGift = structuredClone(gift);

Mut tässä näitä ei tosiaan enää tarvitse, kun siirryit käyttämään patch-metodia.

Copy link
Owner

@samuliasmala samuliasmala left a comment

Choose a reason for hiding this comment

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

Yksi mahdollisesti tarpeeton console.log, muuten valmis.

@anttiasmala anttiasmala merged commit 9ac02bb into main Feb 2, 2024
5 checks passed
@samuliasmala samuliasmala deleted the antti/json-server-edit-button branch February 2, 2024 09:15
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