summaryrefslogtreecommitdiff
path: root/src-migrate/modules/page-content
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2024-11-15 14:55:57 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2024-11-15 14:55:57 +0700
commit36c6e0361762cb0faff10996e30737a58cf14284 (patch)
tree4cb225b8f106c5ea2ce1d929fc8af0b9757ea0e4 /src-migrate/modules/page-content
parentc69b71c16ff7cc7a347394710d069ef711db08bb (diff)
parent7ca8fce4ac97ffc31042dd4d016460a5e61284a5 (diff)
Merge branch 'new-release' of https://bitbucket.org/altafixco/next-indoteknik into new-release
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 '';