From 7f083496881511c9fb57c6dd29fcc68afecc0727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Tue, 6 Feb 2024 09:56:43 +0100 Subject: [PATCH] uveden umjetni delay --- app/lib/actions/locationActions.ts | 9 +++++++++ app/lib/asyncTimeout.ts | 2 ++ 2 files changed, 11 insertions(+) create mode 100644 app/lib/asyncTimeout.ts diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index 3db4f29..efad42c 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -8,6 +8,7 @@ import { withUser } from '@/app/lib/auth'; import { AuthenticatedUser } from '../types/next-auth'; import { gotoHome } from './navigationActions'; import { Noto_Sans_Tamil_Supplement } from 'next/font/google'; +import { asyncTimeout } from '../asyncTimeout'; export type State = { errors?: { @@ -81,6 +82,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat }); } + await asyncTimeout(1000); + if(yearMonth) await gotoHome(yearMonth); return { @@ -109,6 +112,8 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu }) .toArray(); + await asyncTimeout(1000); + return(locations); }) @@ -126,6 +131,8 @@ export const fetchLocationById = withUser(async (user:AuthenticatedUser, locatio return(null); } + await asyncTimeout(1000); + return(billLocation); }) @@ -138,5 +145,7 @@ export const deleteLocationById = withUser(async (user:AuthenticatedUser, locati // find a location with the given locationID const post = await dbClient.collection("lokacije").deleteOne({ _id: locationID, userId }); + await asyncTimeout(1000); + await gotoHome(yearMonth) }) \ No newline at end of file diff --git a/app/lib/asyncTimeout.ts b/app/lib/asyncTimeout.ts new file mode 100644 index 0000000..c65d4ae --- /dev/null +++ b/app/lib/asyncTimeout.ts @@ -0,0 +1,2 @@ + +export const asyncTimeout = (ms: number = 1000) => new Promise(resolve => setTimeout(resolve, ms)); \ No newline at end of file