Skip to content

Commit 893e47e

Browse files
committed
feat(graphql): modity task-item component
https://github.com/martis-git/learn-frontend/issues/279
1 parent fd6a82e commit 893e47e

File tree

6 files changed

+53
-11
lines changed

6 files changed

+53
-11
lines changed

examples/graphql/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@ant-design/icons": "^4.2.2",
67
"@testing-library/jest-dom": "^4.2.4",
78
"@testing-library/react": "^9.3.2",
89
"@testing-library/user-event": "^7.1.2",

examples/graphql/src/models.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,27 @@ declare type Task = {
44
title: string,
55
completed: boolean;
66
}
7+
8+
declare type User = {
9+
id: number,
10+
name: string,
11+
username: string,
12+
email: string,
13+
address: {
14+
street: string,
15+
suite: string,
16+
city: string,
17+
zipcode: string,
18+
geo: {
19+
lat: string,
20+
lng: string,
21+
},
22+
},
23+
phone: string,
24+
website: string,
25+
company: {
26+
name: string,
27+
catchPhrase: string,
28+
bs: string,
29+
},
30+
}

examples/graphql/src/pages/tasks-list/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const TasksListTitle = () => (
1313
);
1414

1515
const TasksList = () => {
16-
const { data, error, loading } = useFetch<Task[]>("");
16+
const { data, error, loading } = useFetch<Task[]>("todos");
1717

1818
return (
1919
<div className="page page-tasks-list">
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
.task-item {
2-
transition: 0.25s;
2+
& > div {
3+
display: flex;
4+
}
35

46
&.completed {
5-
text-decoration: line-through;
7+
color: lightgrey;
68
}
79

8-
&:hover {
9-
background-color: var(--clr-foreground--hover);
10-
}
11-
&:active {
12-
background-color: var(--clr-foreground--selected);
10+
&__title {
11+
flex-grow: 1;
12+
transition: 0.25s;
13+
color: unset;
14+
15+
&:hover {
16+
text-decoration: underline;
17+
color: unset;
18+
}
19+
&:active {
20+
color: rgba(cornflowerblue, 0.8);
21+
}
1322
}
1423
}

examples/graphql/src/shared/components/task-item/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import React from 'react'
22
import cn from "classnames";
33
import { Card } from "antd";
4+
import { UserOutlined } from "@ant-design/icons";
5+
import { useFetch } from "shared/hooks";
46
import "./index.scss";
57

68
type Props = Task;
79

810
const TaskItem = (props: Props) => {
9-
const { completed, id, title, userId } = props;
11+
const { completed, title, userId, id } = props;
12+
const { data: author } = useFetch<User>(`users/${userId}`);
13+
1014
return (
1115
<Card className={cn("task-item", { completed })}>
12-
[{id}] {title}
16+
<a className="task-item__title" href={`/${id}`}>{title}</a>
17+
<span className="task-item__author" >
18+
<UserOutlined />
19+
{author?.username}
20+
</span>
1321
</Card>
1422
)
1523
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// FIXME: move to env
2-
export const API_DOMAIN = "https://jsonplaceholder.typicode.com/todos";
2+
export const API_DOMAIN = "https://jsonplaceholder.typicode.com";

0 commit comments

Comments
 (0)