summaryrefslogtreecommitdiff
path: root/src-migrate/modules/page-content
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2024-11-15 07:39:14 +0000
committerIT Fixcomart <it@fixcomart.co.id>2024-11-15 07:39:14 +0000
commit7ca8fce4ac97ffc31042dd4d016460a5e61284a5 (patch)
treed0f1bb7711e2d93859e1d534551328b14a3ae78e /src-migrate/modules/page-content
parent49f2e6a5612d000c3a740513c1a54b73bb656d77 (diff)
parente5544ace96dd9a200ca5876b8e9ba837ad0a26ac (diff)
Merged in CR/redis (pull request #379)
CR/redis
Diffstat (limited to 'src-migrate/modules/page-content')
-rw-r--r--src-migrate/modules/page-content/index.tsx33
1 files changed, 13 insertions, 20 deletions
diff --git a/src-migrate/modules/page-content/index.tsx b/src-migrate/modules/page-content/index.tsx
index 3423ca8b..54ee0a04 100644
--- a/src-migrate/modules/page-content/index.tsx
+++ b/src-migrate/modules/page-content/index.tsx
@@ -10,28 +10,21 @@ type Props = {
const PageContent = ({ path }: Props) => {
const [localData, setData] = useState<PageContentProps>();
const [shouldFetch, setShouldFetch] = useState(false);
+ const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
- const localData = localStorage.getItem(`page-content:${path}`);
- if (localData) {
- setData(JSON.parse(localData));
- }else{
- setShouldFetch(true);
- }
- },[])
-
- const { data, isLoading } = useQuery<PageContentProps>(
- `page-content:${path}`,
- async () => await getPageContent({ path }), {
- enabled: shouldFetch,
- onSuccess: (data) => {
- if (data) {
- localStorage.setItem(`page-content:${path}`, JSON.stringify(data));
- setData(data);
- }
- },
- }
- );
+ const fetchData = async () => {
+ setIsLoading(true);
+ const res = await fetch(`/api/page-content?path=${path}`);
+ const { data } = await res.json();
+ if (data) {
+ setData(data);
+ }
+ setIsLoading(false);
+ };
+
+ fetchData();
+ }, []);
const parsedContent = useMemo<string>(() => {
if (!localData) return '';