Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server action cookieConsent & lang prefix routing #282

Merged
merged 3 commits into from
Aug 27, 2024
Merged

server action cookieConsent & lang prefix routing #282

merged 3 commits into from
Aug 27, 2024

Conversation

0x74h51N
Copy link
Owner

No description provided.

import dynamic from 'next/dynamic';
import 'swiper/css';
import 'swiper/css/free-mode';
import 'swiper/css/pagination';
import 'swiper/css/navigation';
import { sectionsData } from '@/constants/sections';
import { SectionsSchema, SectionsTypes } from '@/schemas';
import useSupabaseFetch from '@/hooks/useSupabaseFetch';
import { memo, useEffect } from 'react';
import filterByLanguage from '@/lib/utils/filterByLanguage';
import { getLocale } from '@/i18n/client';
import { useDispatch, useSelector } from 'react-redux';
import { setSectionItems } from '@/store/redux/sectionItems';
import { RootState } from '@/store';
import FsLoading from '@/components/Loading/FsLoading';

const Section = dynamic(() => import('@/components/Sections/Section'), {
  ssr: false,
  loading: () => <FsLoading />,
});

const Home = () => {
  const dispatch = useDispatch();
  const filteredData = useSelector((state: RootState) => state.section.items);
  const { data, loading, error } = useSupabaseFetch<SectionsTypes>(
    'home_schema',
    'sections',
    `*, translations(*, cards(*))`,
    SectionsSchema,
  );

  useEffect(() => {
    const fetchLocaleAndFilterData = async () => {
      const language = await getLocale();

      if (data && !loading) {
        const filteredItems = filterByLanguage({
          items: data,
          language,
          localPath: 'translations',
        });
        dispatch(setSectionItems(filteredItems));
      }
    };

    fetchLocaleAndFilterData();
  }, [data, dispatch, loading]);

  if (error) {
    console.error(error);
  }

  return !filteredData || filteredData.length <= 1 || error || loading ? (
    <FsLoading />
  ) : (
    <Section sectionsData={sectionsData} />
  );
};

export default memo(Home);
@0x74h51N 0x74h51N changed the title server action cookieConsent server action cookieConsent & lang prefix routing Aug 26, 2024
@0x74h51N 0x74h51N merged commit e1c4286 into master Aug 27, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant