Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
roi1410 committed Jun 1, 2024
2 parents 53ee495 + 0c99a49 commit dd35781
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 122 deletions.
Empty file added .husky/_/.gitignore
Empty file.
36 changes: 36 additions & 0 deletions .husky/_/husky.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env sh
if [ -z "$husky_skip_init" ]; then
debug () {
if [ "$HUSKY_DEBUG" = "1" ]; then
echo "husky (debug) - $1"
fi
}

readonly hook_name="$(basename -- "$0")"
debug "starting $hook_name..."

if [ "$HUSKY" = "0" ]; then
debug "HUSKY env variable is set to 0, skipping hook"
exit 0
fi

if [ -f ~/.huskyrc ]; then
debug "sourcing ~/.huskyrc"
. ~/.huskyrc
fi

readonly husky_skip_init=1
export husky_skip_init
sh -e "$0" "$@"
exitCode="$?"

if [ $exitCode != 0 ]; then
echo "husky - $hook_name hook exited with code $exitCode (error)"
fi

if [ $exitCode = 127 ]; then
echo "husky - command not found in PATH=$PATH"
fi

exit $exitCode
fi
3 changes: 2 additions & 1 deletion .husky/pre-commit → .husky/pre-commit.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run precommit
npm run precommit
11 changes: 5 additions & 6 deletions .husky/pre-push.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@


#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run prepush

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run prepush
37 changes: 30 additions & 7 deletions actions/fetchProjectsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

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

export type ProjectPaginationRequest = {
Expand All @@ -13,25 +13,48 @@ export type ProjectPaginationRequest = {
};

const PROJECT_API_ENDPOINT = 'https://baas-data-provider.onrender.com/projects';
const localy = `http://localhost:8080/projects`;

async function fetchProjectsData({
page = 1,
limit = 100,
filter = ProjectPaginationFilter.ALL,
}: ProjectPaginationRequest): Promise<IProjectsDataResponse> {
const response = await fetch(PROJECT_API_ENDPOINT, {
const response = await fetch(localy, {
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 response.json();
const {
projects,
total,
languages,
pageLanguages,
timestamp,
} =
await response.json() as IProjectsDataResponse;


const parsedProjects = SummaryProjectType.array().safeParse(projects);


if (!parsedProjects.success) {
throw new Error(`Failed to parse projects: ${parsedProjects.error}`);
}


return { projects, total, languages, pageLanguages, timestamp };
const send = {
projects: parsedProjects.data,
total: total,
languages: languages,
pageLanguages: pageLanguages,
timestamp: new Date(timestamp),
};
return send;
}

export default fetchProjectsData;
export default fetchProjectsData;
36 changes: 22 additions & 14 deletions app/[locale]/projects/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ const ProjectsPage = () => {
*/
const projectIncludesActiveTags = useCallback(
(project: Project) => {
return project.item.data.repository.languages.edges.some(edge =>
tags.some(tag => tag.isActive && tag.name === edge.node.name)
return project.item.languages?.some(edge =>
tags.some(tag => tag.isActive && tag.name === edge)
);
},
[tags]
);


/**
*
Expand Down Expand Up @@ -83,32 +84,38 @@ const ProjectsPage = () => {
filter,
});

setProjects(
projects.filter((p: Project) =>
p.item.data.repository.name
.toLocaleLowerCase()
.trim()
.includes(searchByProjectNameValue.toLocaleLowerCase().trim())
)
const projectsFilteredByName = projects.filter((p: Project) =>
p.item?.name?.toLowerCase()
.trim()
.includes(searchByProjectNameValue.toLowerCase().trim())
);

const newTags: ProjectFilter[] = [];
pageLanguages.forEach((lang: string) => {
newTags.push({ name: lang, isActive: true });
});
setTags(newTags);

return {
newTags,
projectsFilteredByName,
}
} catch (error) {
console.error('Failed to fetch projects:', error);
} finally {
setLoading(false);
}
}, [filter, searchByProjectNameValue]);

useEffect(() => {
debouncedFetchProjectsData();
debouncedFetchProjectsData().then((data) => {
if (!data) return;
setProjects(data.projectsFilteredByName);
setTags(data.newTags);
}).finally(() => {
setLoading(false);
});


// eslint-disable-next-line react-hooks/exhaustive-deps
}, [filter, searchByProjectNameValue]);
}, [filter, searchByProjectNameValue, debouncedFetchProjectsData]);

return (
<div className="projects flex flex-col gap-4" dir={direction}>
Expand Down Expand Up @@ -149,4 +156,5 @@ const ProjectsPage = () => {
);
};


export default ProjectsPage;
44 changes: 20 additions & 24 deletions components/Projects/ProjectCard/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,36 @@ import { getChannelUrl } from '../linkToDiscordChannel';
import { Project } from '@/types/project';
import { useTranslations } from 'next-intl';

export interface ProjectCardProps {
project: Project;
type ProjectItem = Project["item"]

export interface ProjectCardProps extends Required<ProjectItem> {
activeLanguagesNames: string[];
}

export default function ProjectCard({
project: {
item: {
data: {
repository: {
openGraphImageUrl,
updatedAt,
createdAt,
name,
url,
description,
languages,
contributors: { edges: contributors },
},
},
},
},
owner,
updatedAt,
createdAt,
name,
url,
description,
languages,
contributors,
activeLanguagesNames,
}: ProjectCardProps) {
const updatedDateString = new Date(updatedAt)

const updatedDateString = new Date(updatedAt ?? "")
.toLocaleDateString('he-IL')
.replaceAll('.', '/');

const createdDateString = new Date(createdAt)
const createdDateString = new Date(createdAt ?? "")
.toLocaleDateString('he-IL')
.replaceAll('.', '/');

const t = useTranslations('Projects');

console.log(owner, name)

return (
<article
className="w-full flex p-4 sm:p-6 gap-7 rounded-lg bg-purple-100 dark:bg-darkAccBg
Expand All @@ -53,7 +49,7 @@ export default function ProjectCard({
<ImageWithFallback
width="108"
height="108"
src={openGraphImageUrl}
src={`https://opengraph.githubassets.com/1/${owner.login}/${name}`}
alt="project name"
fallback={ProjectImagePlaceholder}
></ImageWithFallback>
Expand All @@ -76,8 +72,8 @@ export default function ProjectCard({
</div>
<AvatarList
avatars={contributors.map(c => ({
imageSrc: c.node.avatarUrl,
name: c.node.login,
imageSrc: c.avatarUrl,
name: c.login,
}))}
></AvatarList>
</div>
Expand All @@ -89,7 +85,7 @@ export default function ProjectCard({
<div className="flex flex-wrap justify-between flex-col sm:flex-row gap-y-6 sm:items-end">
<TagList
className="flex-wrap grow basis-[min-content]"
tags={languages.edges.map(l => l.node.name)}
tags={languages}
activeLanguagesNames={activeLanguagesNames}
></TagList>
<div className="flex gap-2">
Expand Down
12 changes: 7 additions & 5 deletions components/Projects/ProjectDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ const ProjectsDisplay = ({
}: ProjectsDisplayProps) => {
return (
<div className="flex flex-col gap-4 h-[75vh] overflow-y-scroll mb-10 w-[90%] md:w-full max-w-[1240px] mx-auto pl-2">
{projects.map((project, i) => (
<ProjectCard
key={project.item.data.repository.url + i}
project={project}
{projects.map((project, i) => {

return <ProjectCard
key={project.item.url + i}
{...project.item}
activeLanguagesNames={activeLanguagesNames}
/>
))}
}
)}
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion tests/newbiesPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test.describe('Test Newbies page', () => {
await page.waitForNavigation();

const pageTitle = await page.title();
expect(pageTitle).toContain('Newbies');
expect(pageTitle).toContain('מצטרפים חדשים - Newbies | מעקף');
});

test('should render NEWBIES', async ({ page }) => {
Expand Down
Loading

0 comments on commit dd35781

Please sign in to comment.