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

Replace then with await #223

Merged
merged 12 commits into from
Mar 28, 2024
28 changes: 13 additions & 15 deletions actions/fetchProjectsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import {
IProjectsDataResponse,
Project,
ProjectPaginationFilter,
} from '@/types/project';

Expand All @@ -17,23 +18,20 @@ async function fetchProjectsData({
page = 1,
limit = 100,
filter = ProjectPaginationFilter.ALL,
}: ProjectPaginationRequest) {
}: ProjectPaginationRequest): Promise<IProjectsDataResponse> {
const response = await fetch(PROJECT_API_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ page, limit, filter }),
});

// fetch from endpoint POST with page, limit, filter as IProjectsDataResponse
const { projects, total, languages, pageLanguages, timestamp } = await fetch(
PROJECT_API_ENDPOINT,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ page, limit, filter }),
}
).then(res => res.json() as Promise<IProjectsDataResponse>);
const { projects, total, languages, pageLanguages, timestamp } =
await response.json();

return {
projects: projects,
pageLanguages,
};
return { projects, total, languages, pageLanguages, timestamp };
}

export default fetchProjectsData;
6 changes: 3 additions & 3 deletions app/[locale]/members/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MembersList } from '@/components/Members/MembersLIst/MembersList';
import { Member } from '@/types';
import { fetchFilteredMemebers } from '@/actions/fetchFilteredMemebers';
import { useTranslations } from 'next-intl';
import useTypedLocale from '@/hooks/useTypedLocale';
import useTextDirection from '@/hooks/useTextDirection';

const Magnifier: React.FC<SVGProps<SVGSVGElement>> = props => {
return (
Expand Down Expand Up @@ -34,10 +34,10 @@ const Magnifier: React.FC<SVGProps<SVGSVGElement>> = props => {

const WelcomeMessage = () => {
const t = useTranslations('Members');
const localLang = useTypedLocale();
const direction = useTextDirection();
return (
<div
dir={localLang === 'he' ? 'rtl' : 'ltr'}
dir={direction}
className="flex flex-col justify-center bg-purple-100 dark:bg-gray-800 mb-6 mt-2 md:mb-12 py-8 px-4 md:p-4"
>
<div className="flex flex-col md:flex-row md:justify-center md:items-center gap-2 md:gap-8 mx-auto">
Expand Down
5 changes: 2 additions & 3 deletions app/[locale]/projects/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const ProjectsPage = () => {
};

const debouncedFetchProjectsData = useCallback(async () => {
console.log('first', Date.now());
setLoading(true);
try {
const { projects, pageLanguages } = await fetchProjectsData({
Expand All @@ -84,7 +83,7 @@ const ProjectsPage = () => {
});

setProjects(
projects.filter(p =>
projects.filter((p: Project) =>
p.item.data.repository.name
.toLocaleLowerCase()
.trim()
Expand All @@ -93,7 +92,7 @@ const ProjectsPage = () => {
);

const newTags: ProjectFilter[] = [];
pageLanguages.forEach(lang => {
pageLanguages.forEach((lang: string) => {
newTags.push({ name: lang, isActive: true });
});
setTags(newTags);
Expand Down
2 changes: 1 addition & 1 deletion components/BeOurFriends/BeOurFriends.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const variants = {
};

const BeOurFriends = () => {
const t = useTranslations('components.home.beOurFriends');
const t = useTranslations('Components.home.beOurFriends');
const localLang = useLocale();
const direction = localLang == 'he' ? 'rtl' : 'ltr';

Expand Down
Loading