11import { createSlice , createAsyncThunk } from '@reduxjs/toolkit' ;
2- import { HttpClient } from '../../utils/httpClient' ;
2+ import { HttpClient , getDataAPIUrl } from '../../utils/httpClient' ;
33import SearchState from './SearchState' ;
44import Sample from '../../types/Sample' ;
55
@@ -8,7 +8,7 @@ const delay = (ms: number | undefined) => new Promise(resolve => setTimeout(reso
88
99// async search total samples
1010export const getTotalSamplesAsync = createAsyncThunk < number > ( 'search/getTotalSamples' , async ( ) => {
11- const response = await HttpClient . get ( `${ import . meta . env . VITE_API_URL } countSamples` , {
11+ const response = await HttpClient . get ( `${ getDataAPIUrl ( ) } countSamples` , {
1212 withCredentials : false ,
1313 headers : {
1414 'Content-Type' : 'application/json' ,
@@ -20,7 +20,7 @@ export const getTotalSamplesAsync = createAsyncThunk<number>('search/getTotalSam
2020
2121// async list all samples
2222export const getAllSamplesAsync = createAsyncThunk < Sample [ ] > ( 'search/getAllSamplesAsync' , async ( ) => {
23- const response = await HttpClient . get ( `${ import . meta . env . VITE_API_URL } samples` , {
23+ const response = await HttpClient . get ( `${ getDataAPIUrl ( ) } samples` , {
2424 withCredentials : false ,
2525 headers : {
2626 'Content-Type' : 'application/json' ,
@@ -32,7 +32,7 @@ export const getAllSamplesAsync = createAsyncThunk<Sample[]>('search/getAllSampl
3232
3333// async list latest samples
3434export const getLatestSamplesAsync = createAsyncThunk < Sample [ ] > ( 'search/getLatestSamples' , async ( ) => {
35- const response = await HttpClient . get ( `${ import . meta . env . VITE_API_URL } latestSamples` , {
35+ const response = await HttpClient . get ( `${ getDataAPIUrl ( ) } latestSamples` , {
3636 withCredentials : false ,
3737 headers : {
3838 'Content-Type' : 'application/json' ,
@@ -44,7 +44,7 @@ export const getLatestSamplesAsync = createAsyncThunk<Sample[]>('search/getLates
4444
4545// async search specific samples
4646export const searchSamplesAsync = createAsyncThunk < Sample [ ] , string > ( 'search/searchSamplesAsync' , async ( query : string ) => {
47- const response = await HttpClient . get ( `${ import . meta . env . VITE_API_URL } findSamples?text=${ query } ` , {
47+ const response = await HttpClient . get ( `${ getDataAPIUrl ( ) } findSamples?text=${ query } ` , {
4848 withCredentials : false ,
4949 headers : {
5050 'Content-Type' : 'application/json' ,
@@ -57,7 +57,7 @@ export const searchSamplesAsync = createAsyncThunk<Sample[], string>('search/sea
5757// delete a sample
5858export const deleteSampleAsync = createAsyncThunk < number , string > ( 'search/deleteSampleAsync' , async ( id : string ) => {
5959 await delay ( 1000 ) . then ( async ( ) => { // for better user experience
60- await HttpClient . delete ( `${ import . meta . env . VITE_API_URL } deleteSample` , {
60+ await HttpClient . delete ( `${ getDataAPIUrl ( ) } deleteSample` , {
6161 data : { id : id , url : null } ,
6262 withCredentials : false ,
6363 headers : {
@@ -72,7 +72,7 @@ export const deleteSampleAsync = createAsyncThunk<number, string>('search/delete
7272
7373// get the details
7474export const getSampleDetailsAsync = createAsyncThunk < Sample , string > ( 'search/getSampleDetailsAsync' , async ( id : string ) => {
75- const response = await HttpClient . post ( `${ import . meta . env . VITE_API_URL } sampleDetails` , { id : id , url : null } , {
75+ const response = await HttpClient . post ( `${ getDataAPIUrl ( ) } sampleDetails` , { id : id , url : null } , {
7676 // withCredentials: false,
7777 headers : {
7878 'Content-Type' : 'application/json' ,
@@ -85,7 +85,7 @@ export const getSampleDetailsAsync = createAsyncThunk<Sample, string>('search/ge
8585
8686// create a sample
8787export const createSampleAsync = createAsyncThunk < number , string > ( 'search/createSampleAsync' , async ( payload : string ) => {
88- const response = await HttpClient . post ( `${ import . meta . env . VITE_API_URL } createSample` , { payload : payload } , {
88+ const response = await HttpClient . post ( `${ getDataAPIUrl ( ) } createSample` , { payload : payload } , {
8989 // withCredentials: false,
9090 headers : {
9191 'Content-Type' : 'application/json' ,
0 commit comments