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

Pakettien päivittäminen | antti/update-packages #60

Open
wants to merge 62 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d927a38
Install @tanstack/eslint-plugin-query and @tanstack/react-query
anttiasmala Nov 1, 2024
bc8b7d9
Change TODO.md files TODO section
anttiasmala Nov 1, 2024
7015d15
Create queryClient and add QueryClientProvider. They're in _app.tsx f…
anttiasmala Nov 1, 2024
97fdb8e
Create a component of GiftList. Make it to be used instead of hard co…
anttiasmala Nov 1, 2024
e7f9739
Add a small cool loading dot loop and change text fetching text to be…
anttiasmala Nov 1, 2024
13b9c74
Add an TODO task to TODO.md
anttiasmala Nov 1, 2024
16e086f
Move useQuery to Home function. Move a lot of useStates to GiftList c…
anttiasmala Nov 1, 2024
8ac9971
Add file utils/utilFunctions.ts that includes util functions. Mostly …
anttiasmala Nov 5, 2024
046c930
Added a comment and left a test sleep function that will be clarifyin…
anttiasmala Nov 5, 2024
b45e952
ESLint and fixes
anttiasmala Nov 5, 2024
bb0ad82
Remove deleteExpiredSessionsLoop function, does not work with Vercel'…
anttiasmala Nov 5, 2024
626b5df
Add tanstack to eslintrc.json. Rules are recommended by Tanstack
anttiasmala Nov 18, 2024
cb430a8
Remove unnecessary useEffect in '/pages/index.tsx'
anttiasmala Nov 18, 2024
583cf68
Remove unnecessary console.logs in /pages/index.tsx
anttiasmala Nov 18, 2024
0f714cc
ESLint changes. Make loading dot animation 2 seconds long instead of …
anttiasmala Nov 18, 2024
625f082
Change queryKey and queryFn. giftQuery is now its own variable instea…
anttiasmala Nov 18, 2024
37fc468
Change back the variable declarations from useQuery
anttiasmala Nov 18, 2024
48e9f37
Move the useQuery to /utils/apiRequests.ts
anttiasmala Nov 18, 2024
4d44f2b
Remove an unnecessary function. Change the useQuery to use freshly cr…
anttiasmala Nov 18, 2024
c9e7f7b
Remove couple useStates and change them to use useGetGifts' data vari…
anttiasmala Nov 18, 2024
5349549
Remove async. It broke React
anttiasmala Nov 18, 2024
9dafd1d
Add invalidateQueries into /pages/index.tsx
anttiasmala Nov 20, 2024
0f3cc99
Add try/catch block into /utils/apiRequests.ts
anttiasmala Nov 20, 2024
0bf8b11
Change return false to return an empty array to fix an error with gif…
anttiasmala Nov 20, 2024
148aeb0
Remove refreshGiftList function and change them to queryClient.invali…
anttiasmala Nov 20, 2024
05b2e18
Remove parameters from GiftList component. Change it to use useGetGif…
anttiasmala Nov 20, 2024
6c0c903
Create a type for queryKeys
anttiasmala Nov 20, 2024
9d11db1
Add a new function invalidateSingleQueryKey. It will be same as using…
anttiasmala Nov 20, 2024
5302753
Remove a few parameters, and remove props from GiftList component tha…
anttiasmala Nov 20, 2024
90f08e2
Remove refreshGiftList function and change them to use new invalidate…
anttiasmala Nov 20, 2024
ad1126f
ESLint and fixes
anttiasmala Nov 20, 2024
616d940
Change one more queryClient.invalidateQueries to use custom-made quer…
anttiasmala Nov 20, 2024
7f336bc
Merge branch main into antti/add-tanstack-library
anttiasmala Nov 20, 2024
70d5167
Remove invalidateQueryKeys functions. Add a new object to types.ts th…
anttiasmala Dec 9, 2024
45c2b5d
Remove try/catch block inside /utils/apiRequests.ts
anttiasmala Dec 9, 2024
eb9f5b9
Create a new file to hooks folder that will follow Tanstack query errors
anttiasmala Dec 9, 2024
2ca5d5c
Change useCatchQueryErrors to require only error parameter
anttiasmala Dec 10, 2024
28dd9fe
Change the way error parameter in useCatchQueryErrors is handled and …
anttiasmala Dec 10, 2024
5c75de7
ESLint and fixes
anttiasmala Dec 10, 2024
7fa6f73
Change queryKey inside useGetGifts function to use QueryKeys.GIFTS in…
anttiasmala Dec 10, 2024
2a4df4b
Change the ID toast.update updates inside /utils/handleToasts.ts
anttiasmala Dec 11, 2024
ea15d3b
Update Minor packages and test everything works
anttiasmala Dec 12, 2024
b596690
Update Prisma client and Prisma packages
anttiasmala Dec 15, 2024
0512334
Add ### before userUUID and giftUUID 'variables'. Without them some r…
anttiasmala Dec 15, 2024
757f5e2
update small packages that have come during this branch
anttiasmala Dec 19, 2024
3092188
Update NextJS and packages relating to it. Update react-toastify and …
anttiasmala Dec 21, 2024
ddd22cf
Update packages on the laptop as well
anttiasmala Dec 22, 2024
ec2e718
Update more packages
anttiasmala Dec 23, 2024
7818a6d
Add eslint-disable-next-line lines to prevent ESLint running
anttiasmala Dec 23, 2024
c61dda6
Install a new library eslint-plugin-n. Old eslint-plugin-node does no…
anttiasmala Dec 23, 2024
9c8f0a1
Change node/no-missing-import to n/no-missing-import
anttiasmala Dec 23, 2024
22b9c6d
Updated minor updates that had come during updating
anttiasmala Dec 25, 2024
44e146a
Update dotenv-cli package. It has major update. However I could not f…
anttiasmala Dec 25, 2024
b1e912f
Update TODO.md
anttiasmala Dec 25, 2024
7d40537
Lower the prisma version back to 5.20.0 due to lucia-auth requiring i…
anttiasmala Dec 25, 2024
e74251b
Update more packages
anttiasmala Jan 9, 2025
d3140ef
Remove eslint-disable-next-lines. Change ~/styles/ to ../styles/ to p…
anttiasmala Jan 15, 2025
0eab8b1
Remove .eslintrc.json and add eslint.config.mjs. Remove the soon be d…
anttiasmala Jan 15, 2025
d5543f6
Update more packages
anttiasmala Jan 15, 2025
6a936d4
Update eslint-config-prettier. No breaking things found during testing
anttiasmala Jan 15, 2025
fa92377
Add more details of non updated packages and add a checklist for test…
anttiasmala Jan 15, 2025
773ed65
Remove commented config inside eslint.config.mjs
anttiasmala Jan 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@
"root": true,
"extends": [
"eslint:recommended",
"plugin:node/recommended",
"plugin:n/recommended",
"plugin:import/recommended",
"next/core-web-vitals",
"plugin:prettier/recommended"
],
"rules": {
// Without 'modules' ignored would get 'Import and export declarations are
// not supported yet' error in all ts files
/*
"node/no-unsupported-features/es-syntax": [
"error",
{ "ignores": ["modules"] }
],
*/

// didn't get this working for now. I tried to allow "styles/globals.css" and make everything
// else throw an error. Added a couple eslint-disable-next-line lines to fix the problem for now


/*
"n/no-extraneous-import": ["error", {
"allowModules": ["@styles/globals.css"]
}],
*/

anttiasmala marked this conversation as resolved.
Show resolved Hide resolved
// No React component definitions allowed inside components
"react/no-unstable-nested-components": "warn",

Expand All @@ -40,10 +52,12 @@
"sourceType": "module",
"ecmaFeatures": { "jsx": true }
},
"plugins": ["@tanstack/query"],
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/typescript"
"plugin:import/typescript",
"plugin:@tanstack/eslint-plugin-query/recommended"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Liittyy tanstack-brancheihin, jonka pohjalta väsäsin tätä branchia

],
"rules": {
// 'tsc' already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/291)
Expand All @@ -52,7 +66,8 @@
"no-undef": "off",

// Handled by import/typescript
"node/no-missing-import": "off",
//"node/no-missing-import": "off",
"n/no-missing-import": "off",

anttiasmala marked this conversation as resolved.
Show resolved Hide resolved
// Disable some rules which are difficult for beginners
"@typescript-eslint/no-unsafe-assignment": "warn",
Expand Down
14 changes: 11 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@

# Jokin sivu (esimerkiksi asetuksiin), joka näyttää kaikki aktiiviset (miksei epäaktiiviset) Sessionit. Myöskin Sessionin poistomahdollisuus voitaisiin lisätä

# Enter-näppäimellä EditModalin ja DeleteModalin hyväksyminen
# Enter-näppäimellä EditModalin (DONE) ja DeleteModalin hyväksyminen

### </IDEOITA>

TODO:

Laitetaan nappulat yms käyttämään tanstack-kirjastoa. Ratkaisee samalla yhden ideoista
https://www.npmjs.com/package/@tanstack/react-query
Jos tulee virhe vaikka lahjoja hakiessa, ehkä jokin nappula olisi hyvä tehdä, jolla voisi mahdollisesti kokeilla hakea uudestaan lahjoja

Kun lisää uuden lahjan / kun lahjoja haetaan, järjestetään ne uusin -> vanhin. Myöhemmin voidaan lisätä käyttäjälle mahdollisuus valita miten lahjat haluaa järjestää (vaikka vanhin -> uusin, aakkosjärjestys, ymsyms)

Tässä toteutustapa:

const sortedArrayNewestToOldest = gifts.sort(
(a, b) =>
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
);
2 changes: 2 additions & 0 deletions api.rest
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Content-Type: application/json


# GIFT REQUESTS
###
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

###-merkit lisätty, jottei @giftUUID ja @userUUID eivät riko niiden alla / yllä olevia requesteja


@giftUUID = cba86307-8f50-4038-bc79-c05cef4fafc1

Expand Down Expand Up @@ -72,6 +73,7 @@ DELETE {{baseUrl}}/gifts/{{giftUUID}}

# USER REQUESTS

###
@userUUID = 26ab195c-5f56-4831-bedd-07725e8012ff

###
Expand Down
17 changes: 9 additions & 8 deletions components/DeleteModal.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import { Dispatch, SetStateAction } from 'react';
import { Gift } from '~/shared/types';
import { Gift, QueryKeys } from '~/shared/types';
import { Modal } from './Modal';
import { Button } from './Button';
import { deleteGift } from '~/utils/apiRequests';
import { handleError } from '~/utils/handleError';
import { handleErrorToast } from '~/utils/handleToasts';
import { useQueryClient } from '@tanstack/react-query';

type DeleteModal = {
gift: Gift;
refreshGiftList: () => void;
setIsModalOpen: Dispatch<SetStateAction<boolean>>;
};

export function DeleteModal({
gift,
refreshGiftList,
setIsModalOpen,
}: DeleteModal) {
export function DeleteModal({ gift, setIsModalOpen }: DeleteModal) {
const queryClient = useQueryClient();

async function handleDeletion() {
try {
await deleteGift(gift.uuid);
} catch (e) {
handleErrorToast(handleError(e));
}
refreshGiftList();
await queryClient.invalidateQueries({
queryKey: QueryKeys.GIFTS,
});

setIsModalOpen(false);
}

Expand Down
14 changes: 6 additions & 8 deletions components/EditModal.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
import { Dispatch, FormEvent, SetStateAction, useState } from 'react';
import { Gift } from '~/shared/types';
import { Gift, QueryKeys } from '~/shared/types';
import { Modal } from './Modal';
import { Button } from './Button';
import { updateGift } from '~/utils/apiRequests';
import { Input } from './Input';
import { handleError } from '~/utils/handleError';
import { handleErrorToast } from '~/utils/handleToasts';
import { useQueryClient } from '@tanstack/react-query';

type EditModal = {
gift: Gift;
refreshGiftList: () => void;
setIsModalOpen: Dispatch<SetStateAction<boolean>>;
};

export function EditModal({
gift,
refreshGiftList,
setIsModalOpen,
}: EditModal) {
export function EditModal({ gift, setIsModalOpen }: EditModal) {
const [giftReceiver, setGiftReceiver] = useState(gift.receiver);
const [giftName, setGiftName] = useState(gift.gift);

const queryClient = useQueryClient();

async function handleEdit(e: FormEvent<HTMLElement>) {
e.preventDefault();
try {
await updateGift(gift.uuid, { receiver: giftReceiver, gift: giftName });
} catch (e) {
handleErrorToast(handleError(e));
}
refreshGiftList();
await queryClient.invalidateQueries({ queryKey: QueryKeys.GIFTS });
setIsModalOpen(false);
}
return (
Expand Down
20 changes: 20 additions & 0 deletions hooks/useCatchQueryErrors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useEffect } from 'react';
import { handleError } from '~/utils/handleError';
import { handleErrorToast } from '~/utils/handleToasts';

export function useCatchQueryErrors(error: Error | null) {
// Otetaan isError-parametri pois ja jätetään vain error-parametri ja tehdään seuraava tarkistus:
/*
if(!error) return

handleErrorToast(handleError(error))
return
*/
// tai jotain vastaavaa

useEffect(() => {
if (!error) return;

handleErrorToast(handleError(error));
}, [error]);
}
Loading
Loading