Skip to content

Commit

Permalink
several minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ipapandinas committed Sep 24, 2024
1 parent 6bcdc99 commit 5a2fd32
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 47 deletions.
25 changes: 24 additions & 1 deletion api/core/_transformers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Issue, IssueDto } from "@/types/issue";
import {
Issue,
IssueDto,
IssueQueryParams,
IssueQueryParamsDto,
} from "@/types/issue";
import { Project, ProjectDto } from "@/types/project";
import { Repository, RepositoryDto } from "@/types/repository";

Expand Down Expand Up @@ -39,3 +44,21 @@ export function dtoToProject(dto: ProjectDto): Project {
technologies: dto.technologies ?? [],
};
}

export function issueQueryParamsToDto(
query: IssueQueryParams,
allLanguages: string[],
): IssueQueryParamsDto {
const technologies = query.technologies ?? [];
const languages = technologies.filter((tech) => allLanguages.includes(tech));
const remainingTechnologies = technologies.filter(
(tech) => !allLanguages.includes(tech),
);

return {
...query,
technologies:
remainingTechnologies.length > 0 ? remainingTechnologies : undefined,
languages: languages.length > 0 ? languages : undefined,
};
}
20 changes: 16 additions & 4 deletions api/core/issues.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
import { DEFAULT_QUERY } from "@/data/fetch";
import { IssueQueryParams, IssueDto, Issue } from "@/types/issue";
import {
IssueQueryParams,
IssueDto,
Issue,
IssueQueryParamsDto,
} from "@/types/issue";
import {
PaginationQueryParams,
PaginatedCustomResponse,
PaginatedCustomResponseDto,
} from "@/types/pagination";
import { prepareUrl } from "@/utils/url";
import { coreApiClient } from "./_client";
import { dtoToIssue } from "./_transformers";
import { dtoToIssue, issueQueryParamsToDto } from "./_transformers";
import { getAllLanguages } from "./languages";

const ISSUES_PATH = "/issues";

export async function getIssues(
query: IssueQueryParams & PaginationQueryParams = DEFAULT_QUERY,
): Promise<PaginatedCustomResponse<Issue>> {
const url = prepareUrl(`${ISSUES_PATH}`, query);
// TODO: Small transformation needed to separate languages from technologies in query params
let queryDto: IssueQueryParamsDto = query;
if (query?.technologies?.length) {
const allLanguages = await getAllLanguages();
queryDto = issueQueryParamsToDto(query, allLanguages);
}

const url = prepareUrl(`${ISSUES_PATH}`, queryDto);
const res =
await coreApiClient.get<PaginatedCustomResponseDto<IssueDto>>(url);

return {
totalCount: res.total_count ?? 0,
hasNextPage: res.has_next_page,
Expand Down
7 changes: 5 additions & 2 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { FiltersProvider } from "@/contexts/filters";
import { SITE_CONFIG } from "@/data/config";
import { getFilterOptions } from "@/lib/filters";
import { initFilters } from "@/utils/filters";
import { DEFAULT_PAGE_SIZE, DEFAULT_PAGINATED_RESPONSE } from "@/data/fetch";
import {
DEFAULT_HOMEPAGE_PAGE_SIZE,
DEFAULT_PAGINATED_RESPONSE,
} from "@/data/fetch";
import { FilterOptions } from "@/types/filters";

const EXPLORE_LABEL = "Explore Open Contributions";
Expand All @@ -27,7 +30,7 @@ export default async function Home() {

const issues = await IssuesApi.getIssues({
offset: 0,
limit: DEFAULT_PAGE_SIZE,
limit: DEFAULT_HOMEPAGE_PAGE_SIZE,
}).catch((error) => {
console.error("Error fetching issues:", error);
return DEFAULT_PAGINATED_RESPONSE;
Expand Down
51 changes: 27 additions & 24 deletions components/table/row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,34 @@ interface IProjectProps {
slug: string;
name: string;
repository: Repository;
withProjectData?: boolean;
}
export const Project = ({
avatarSrc,
slug,
name,
repository,
}: IProjectProps) => (
<NuiLink
className="flex md:gap-4"
href={`/projects/${slug}`}
color="foreground"
title={`${name}'s project page`}
as={Link}
>
<Project.Avatar alt={`${name} logo`} src={avatarSrc} />
<div className="hidden md:flex flex-col justify-start items-start w-36">
<h2 className="w-fit text-small font-semibold truncate">{name}</h2>
<p className="w-fit text-small text-default-500 truncate">
{repository.name}
</p>
</div>
</NuiLink>
);
withProjectData,
}: IProjectProps) => {
if (!withProjectData) return <div />;
return (
<NuiLink
className="flex md:gap-4"
href={`/projects/${slug}`}
color="foreground"
title={`${name}'s project page`}
as={Link}
>
<Project.Avatar alt={`${name} logo`} src={avatarSrc} />
<div className="hidden md:flex flex-col justify-start items-start w-36">
<h2 className="w-fit text-small font-semibold truncate">{name}</h2>
<p className="w-fit text-small text-default-500 truncate">
{repository.name}
</p>
</div>
</NuiLink>
);
};

interface IAvatarProps {
alt: string;
Expand Down Expand Up @@ -83,21 +88,21 @@ interface IContentProps {
title: string;
projectName?: string;
repositoryName: string;
url: string;
isCertified: boolean;
}
export const Content = ({
title,
projectName,
repositoryName,
url,
isCertified,
}: IContentProps) => {
return (
<div
className={`flex flex-col space-y-unit-1 md:space-y-0 ${projectName ? "lg:w-[270px] xl:w-[500px]" : "pl-2"}`}
className={`flex flex-col ${projectName ? "lg:w-[270px] xl:w-[500px]" : "pl-2 gap-1"}`}
>
<span className="text-small text-default-500 max-w-48 truncate md:hidden">
<span
className={`text-small text-default-500 max-w-48 truncate ${projectName ? "md:hidden" : ""}`}
>
<div className="flex items-center gap-2">
{projectName ? (
`${projectName} / ${repositoryName}`
Expand All @@ -109,9 +114,7 @@ export const Content = ({
)}
</div>
</span>
<div
className={`w-fit text-base flex gap-1 flex-grow relative${projectName ? "" : " min-h-10"}`}
>
<div className="w-fit text-base flex gap-1 flex-grow relative">
<h3 className="font-semibold leading-tight line-clamp-2 capitalize">
{title}
</h3>
Expand Down
13 changes: 8 additions & 5 deletions components/table/static-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const StaticTable = ({ data, withProjectData = true }: IStaticTableProps) => {
const isLaptop = useMediaQuery({ minWidth: 1024 }); // tailwind lg default: 1024px

const [columns, setColumns] = useState<IColumn[]>([
...(withProjectData ? [{ name: "PROJECT", uid: "project" }] : []),
{ name: "PROJECT", uid: "project" },
{ name: "CONTENT", uid: "content" },
{ name: "LABELS", uid: "labels" },
{ name: "DATE", uid: "date" },
Expand All @@ -66,6 +66,7 @@ const StaticTable = ({ data, withProjectData = true }: IStaticTableProps) => {
slug={project.slug}
name={project.name}
repository={repository}
withProjectData={withProjectData}
/>
);
}
Expand All @@ -76,7 +77,6 @@ const StaticTable = ({ data, withProjectData = true }: IStaticTableProps) => {
title={title}
projectName={withProjectData ? project.name : undefined}
repositoryName={repository?.name}
url={url}
isCertified={isCertified}
/>
);
Expand Down Expand Up @@ -117,7 +117,7 @@ const StaticTable = ({ data, withProjectData = true }: IStaticTableProps) => {

useEffect(() => {
setColumns([
...(withProjectData ? [{ name: "PROJECT", uid: "project" }] : []),
{ name: "PROJECT", uid: "project" },
{ name: "CONTENT", uid: "content" },
...(isLaptop ? [{ name: "LABELS", uid: "labels" }] : []),
{ name: "DATE", uid: "date" },
Expand Down Expand Up @@ -148,9 +148,12 @@ const StaticTable = ({ data, withProjectData = true }: IStaticTableProps) => {
</TableColumn>
)}
</TableHeader>
<TableBody items={data} emptyContent="No contributions to display.">
<TableBody
items={data}
emptyContent="No contributions to display.. Try another query (:"
>
{(item) => {
const isHighlighted = item.isCertified && !filters[KUDOS_ISSUE_KEY];
const isHighlighted = item.isCertified && !filters?.[KUDOS_ISSUE_KEY];
return (
<TableRow
key={item.id}
Expand Down
5 changes: 3 additions & 2 deletions data/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PaginatedCustomResponse } from "@/types/pagination";

export const DEFAULT_PAGE_SIZE = 25;
export const DEFAULT_PAGE_SIZE = 12;
export const DEFAULT_HOMEPAGE_PAGE_SIZE = 25;
export const DEFAULT_BIG_PAGE_SIZE = 100;

export const DEFAULT_PAGINATED_RESPONSE: PaginatedCustomResponse<never> = {
Expand All @@ -12,7 +13,7 @@ export const DEFAULT_PAGINATED_RESPONSE: PaginatedCustomResponse<never> = {

export const DEFAULT_QUERY = {
offset: 0,
limit: DEFAULT_BIG_PAGE_SIZE,
limit: DEFAULT_PAGE_SIZE,
};

export const UNASSIGNED_CONTRIBUTION_FILTER = {
Expand Down
7 changes: 1 addition & 6 deletions hooks/useFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { useCallback, useState } from "react";
import { useRouter } from "next/navigation";
import {
FilterKeys,
IFilterOption,
FilterOptions,
Filters,
} from "@/types/filters";
import { FilterKeys, FilterOptions, Filters } from "@/types/filters";
import { initFilters } from "@/utils/filters";
import { GOOD_FIRST_ISSUE_KEY, KUDOS_ISSUE_KEY } from "@/data/filters";

Expand Down
10 changes: 7 additions & 3 deletions lib/filters.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import LanguagesApi from "@/api/core/languages";
import ProjectsApi from "@/api/core/projects";
import { DEFAULT_QUERY } from "@/data/fetch";
import { DEFAULT_BIG_PAGE_SIZE } from "@/data/fetch";
import {
FProjectTypes,
FPurposes,
Expand Down Expand Up @@ -42,7 +42,10 @@ export async function getFilterOptions(): Promise<FilterOptions> {

const purposes = createFilterOptions(FPurposes, emojiMapForPurposes);
const technologies = createFilterOptions(
[...languageValues, ...FTechnologies],
[
...languageValues.map((v) => v.toLocaleLowerCase().replaceAll('"', "")),
...FTechnologies,
],
emojiMapForTechnologies,
);
const stackLevels = createFilterOptions(FStackLevels, emojiMapForStackLevels);
Expand All @@ -64,7 +67,8 @@ export function filtersToIssuesQuery(
filters: Filters,
): IssueQueryParams & PaginationQueryParams {
const query: IssueQueryParams & PaginationQueryParams = {
...DEFAULT_QUERY,
offset: 0,
limit: DEFAULT_BIG_PAGE_SIZE,
open: true,
};

Expand Down
5 changes: 5 additions & 0 deletions types/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ export type IssueQueryParams = Partial<{
technologies: string[];
types: string[];
}>;

export type IssueQueryParamsDto = IssueQueryParams &
Partial<{
languages: string[];
}>;

0 comments on commit 5a2fd32

Please sign in to comment.