-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8bc7751
commit 0f689aa
Showing
6 changed files
with
180 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Axios } from './axios'; | ||
import { CACHING_STATUS_URL } from './constants'; | ||
|
||
export const getCachingStatus = (streamName: string) => { | ||
return Axios().get(CACHING_STATUS_URL(streamName)); | ||
}; | ||
|
||
export const updateCaching = (streamName: string, type: boolean) => { | ||
return Axios().put(CACHING_STATUS_URL(streamName), type, { headers: { 'Content-Type': 'application/json' } }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import useMountedState from './useMountedState'; | ||
import { StatusCodes } from 'http-status-codes'; | ||
import { getCachingStatus } from '@/api/caching'; | ||
|
||
export const useGetCacheStatus = () => { | ||
const [data, setData] = useMountedState<boolean | null>(null); | ||
const [error, setError] = useMountedState<string | null>(null); | ||
const [loading, setLoading] = useMountedState<boolean>(false); | ||
|
||
const getCacheStatus = async (streamName: string) => { | ||
setLoading(true); | ||
try { | ||
const res = await getCachingStatus(streamName); | ||
|
||
switch (res.status) { | ||
case StatusCodes.OK: { | ||
setData(res.data); | ||
break; | ||
} | ||
default: { | ||
setError('Failed to get cache status'); | ||
console.error(res); | ||
} | ||
} | ||
} catch (error) { | ||
setError('Failed to get cache status'); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
const resetData = () => { | ||
setData(null); | ||
}; | ||
|
||
return { data, error, loading, getCacheStatus, resetData }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import useMountedState from './useMountedState'; | ||
import { StatusCodes } from 'http-status-codes'; | ||
import { updateCaching } from '@/api/caching'; | ||
|
||
export const usePutCache = () => { | ||
const [data, setData] = useMountedState<boolean | null>(null); | ||
const [error, setError] = useMountedState<string | null>(null); | ||
const [loading, setLoading] = useMountedState<boolean>(false); | ||
|
||
const updateCache = async (streamName: string, type: boolean) => { | ||
setLoading(true); | ||
try { | ||
const res = await updateCaching(streamName, type); | ||
|
||
switch (res.status) { | ||
case StatusCodes.OK: { | ||
setData(res.data); | ||
break; | ||
} | ||
default: { | ||
setError('Failed to change cache setting'); | ||
console.error(res); | ||
} | ||
} | ||
} catch (error) { | ||
setError('Failed to change cache setting'); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
const resetData = () => { | ||
setData(null); | ||
}; | ||
|
||
return { data, error, loading, updateCache, resetData }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters