ql
62 строки · 1.9 Кб
1import React from 'react';
2import { useParams } from 'react-router-dom';
3import { useQuery } from '@apollo/client';
4import { GET_REPO_DETAILS } from '../../resurce/get_repo_details.tsx';
5import { Link } from 'react-router-dom';
6import styles from './Reposiyory.module.scss'
7
8interface ILanguage {
9name: string;
10}
11
12interface IRepository {
13name: string;
14stargazers: {
15totalCount: number;
16};
17updatedAt: string;
18owner: {
19login: string;
20avatarUrl: string;
21url: string;
22};
23description: string;
24languages: {
25nodes: ILanguage[];
26};
27}
28
29const Repository: React.FC = () => {
30const { owner, name } = useParams<{ owner: string; name: string }>();
31
32const { data, loading, error } = useQuery(GET_REPO_DETAILS, {
33variables: { owner, name },
34});
35
36if (loading) return <p>Loading...</p>;
37if (error || !data || !data.repository) return <p>Error: {error ? error.message : 'Repository not found'}</p>;
38
39const repository: IRepository = data.repository;
40
41return (
42<div className={styles.container}>
43<Link to="/" className={styles.btn}>Назад</Link>
44<h1>{repository.name} - {repository.stargazers.totalCount} stars - {new Date(repository.updatedAt).toLocaleDateString()}</h1>
45<div>
46<img src={repository.owner.avatarUrl} alt={repository.owner.login} width={50} />
47<a href={repository.owner.url} target="_blank" rel="noopener noreferrer">{repository.owner.login}</a>
48</div>
49<div>
50<h3>Languages</h3>
51<ul>
52{repository.languages.nodes.map(language => (
53<li key={language.name}>{language.name}</li>
54))}
55</ul>
56</div>
57<p>{repository.description}</p>
58</div>
59);
60};
61
62export default Repository;
63