Skip to content

Commit

Permalink
feat: add avatars if assignee present
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ13th committed Jan 31, 2025
1 parent 05a1df7 commit 45ea0d2
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 13 deletions.
18 changes: 14 additions & 4 deletions api/core/_transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,29 @@ import {
Repository,
RepositoryDto,
} from "@/types/repository";
import { User, UserDto } from "@/types/user";

export function dtoToTask(dto: TaskDto): Task {
return {
id: dto.id,
taskId: dto.issue_id,
isCertified: dto.certified,
labels: dto.labels ?? [],
repository: dtoToRepository(dto.repository),
project: dtoToProject(dto.repository.project),
user: dto.user ? dtoToUser(dto.user) : null,
repository: dto.repository ? dtoToRepository(dto.repository) : null,
project: dto.repository ? dtoToProject(dto.repository.project) : null,
title: dto.title,
description: dto.description,
createdAt: dto.issue_created_at,
url: dto.repository.url + `/issues/${dto.issue_id}`,
createdAt: dto.issue_created_at ? dto.issue_created_at : dto.created_at,
url: dto.repository ? dto.repository.url + `/issues/${dto.issue_id}` : null,
};
}

export function dtoToUser(dto: UserDto): User {
return {
id: dto.id,
username: dto.username,
avatar: dto.avatar,
};
}

Expand Down
2 changes: 1 addition & 1 deletion api/core/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { fetchFromApi } from "./_client";
import { dtoToTask, taskQueryParamsToDto } from "./_transformers";
import { getAllLanguages } from "./languages";

const TASKS_PATH = "/issues";
const TASKS_PATH = "/tasks";

export async function getTasks(
query: TaskQueryParams & PaginationQueryParams = DEFAULT_PAGINATION,
Expand Down
24 changes: 23 additions & 1 deletion components/table/row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { formatDate } from "@/utils/date";
import { shuffleArray } from "@/utils/filters";
import { createUrl } from "@/utils/url";
import { CARNIVAL_NEW_LISTED_TASKS, CARNIVAL_WIP_TASKS } from "@/data/carnival";
import NextImage from "next/image";

const MAX_LABEL_WIDTH = 192;

Expand Down Expand Up @@ -67,7 +68,7 @@ interface IAvatarProps {
src: string | null;
}

const Avatar = ({ alt, src }: IAvatarProps) => {
export const Avatar = ({ alt, src }: IAvatarProps) => {
return (
<div className="bg-foreground rounded-md min-w-[40px] min-h-[40px] sm:min-w-[45px] sm:min-h-[45px] shrink-0 flex items-center justify-center">
{src !== null && (
Expand All @@ -86,6 +87,27 @@ const Avatar = ({ alt, src }: IAvatarProps) => {

Project.Avatar = Avatar;

interface IUserAvatarProps {
alt: string;
src: string | null;
}

export const UserAvatar = ({ alt, src }: IAvatarProps) => {
return (
<div className="relative border bg-foreground overflow-hidden rounded-full min-w-[45px] min-h-[45px] shrink-0 flex items-center justify-center">
{src !== null && (
<NextImage
className="pointer-events-none absolute -left-0 -top-0 h-[45px] w-[45px] max-w-[initial] transition-opacity z-10 opacity-100 object-cover object-center"
src={src}
alt={alt}
height={40}
width={40}
/>
)}
</div>
);
};

interface IContentProps {
id: number;
title: string;
Expand Down
22 changes: 21 additions & 1 deletion components/table/static-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ import {
import { Task } from "@/types/task";

import TaskModal from "./task-modal";
import { ExternalLink, Content, Time, Project, ApplyButton } from "./row";
import {
ExternalLink,
Content,
Time,
Project,
ApplyButton,
UserAvatar,
} from "./row";
import { getIconSrc } from "@/utils/icons";

const DEFAULT_EMPTY = "No contributions to display yet";
Expand Down Expand Up @@ -64,6 +71,7 @@ const StaticTable = ({
{ name: "PROJECT", uid: "project" },
{ name: "CONTENT", uid: "content" },
{ name: "LABELS", uid: "labels" },
{ name: "ASSIGNEE", uid: "assignee" },
{ name: "DATE", uid: "date" },
{ name: "ACTIONS", uid: "actions" },
]);
Expand Down Expand Up @@ -115,6 +123,17 @@ const StaticTable = ({
/>
);
}
case "assignee": {
const { user } = item;
return user ? (
<UserAvatar
alt={`${user?.username} avatar`}
src={user.avatar ?? null}
/>
) : (
""
);
}
case "date":
return (
<div className="flex flex-col items-center gap-2">
Expand Down Expand Up @@ -142,6 +161,7 @@ const StaticTable = ({
{ name: "PROJECT", uid: "project" },
{ name: "CONTENT", uid: "content" },
...(isLaptop ? [{ name: "LABELS", uid: "labels" }] : []),
{ name: "ASSIGNEE", uid: "assignee" },
{ name: "DATE", uid: "date" },
...(isMobile ? [] : [{ name: "ACTIONS", uid: "actions" }]),
]);
Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @type {import('next').NextConfig} */
const cspHeader = `
default-src 'self';
connect-src 'self' https://api.morekudos.com/ https://www.google-analytics.com/;
connect-src 'self' http://localhost:8000 https://api.morekudos.com/ https://www.google-analytics.com/;
script-src 'self' 'unsafe-eval' 'unsafe-inline' https://va.vercel-scripts.com/ https://www.google-analytics.com/ https://tagmanager.google.com/ https://www.googletagmanager.com/;
style-src 'self' 'unsafe-inline';
img-src 'self' https://cryptologos.cc/ https://avatars.githubusercontent.com/ blob: data:;
Expand Down
13 changes: 8 additions & 5 deletions types/task.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { PaginationQueryParams } from "./pagination";
import { Project } from "./project";
import { Repository, RepositoryDto } from "./repository";
import { User, UserDto } from "./user";

export type TaskDto = {
id: number;
issue_id: number;
labels: string[] | null;
open: boolean;
assignee_id: string | null;
assignee_username: string | null;
// assignee_username: string | null;
user: UserDto | null;
certified: boolean;
repository: RepositoryDto;
repository: RepositoryDto | null;
title: string | null;
description: string | null;
issue_created_at: string;
Expand All @@ -24,11 +26,12 @@ export type Task = {
taskId: number;
isCertified: boolean;
labels: string[];
repository: Repository;
project: Project;
user: User | null;
repository: Repository | null;
project: Project | null;
title: string | null;
description: string | null;
url: string;
url: string | null;
createdAt: string;
};

Expand Down
14 changes: 14 additions & 0 deletions types/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type UserDto = {
id: number;
username: string;
avatar: string;
created_at: string;
updated_at: string;
github_id: number;
};

export type User = {
id: number;
username: string;
avatar: string;
};

0 comments on commit 45ea0d2

Please sign in to comment.