|
| 1 | +import { RouteComponentProps } from 'react-router-dom'; |
| 2 | +import { useBenchmarksForUser } from '../../hooks/benchmark'; |
| 3 | +import Header from '../Page/Header'; |
| 4 | +import Page from '../Page/Page'; |
| 5 | +import benchmarkModel from './BenchmarkModel'; |
| 6 | +import BenchmarkRow from './BenchmarkRow'; |
| 7 | + |
| 8 | +type UserParams = { |
| 9 | + id: string; |
| 10 | +}; |
| 11 | + |
| 12 | +const UserBenchmarks = ({ match }: RouteComponentProps<UserParams>) => { |
| 13 | + let benchmarks: benchmarkModel[] = []; |
| 14 | + const { |
| 15 | + isLoading: isBenchmarksLoading, |
| 16 | + isError: isBenchmarksError, |
| 17 | + data: benchmarksData, |
| 18 | + error, |
| 19 | + } = useBenchmarksForUser(match.params.id); |
| 20 | + |
| 21 | + if (isBenchmarksLoading) { |
| 22 | + return <span>Loading....</span>; |
| 23 | + } |
| 24 | + |
| 25 | + if (isBenchmarksError) { |
| 26 | + if (error) { |
| 27 | + return <span>Error: {error.message}</span>; |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + if (benchmarksData) { |
| 32 | + benchmarks = benchmarksData; |
| 33 | + } |
| 34 | + |
| 35 | + return ( |
| 36 | + <Page> |
| 37 | + <Header |
| 38 | + title="My Benchmarks" |
| 39 | + button="Create" |
| 40 | + navTo="/benchmarks/create" |
| 41 | + /> |
| 42 | + <div className="max-w-7xl mx-auto py-6 sm:px-6 lg:px-8"> |
| 43 | + <div className="flex flex-col"> |
| 44 | + <div className="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8"> |
| 45 | + <div className="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8"> |
| 46 | + <div className="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg"> |
| 47 | + <table className="min-w-full divide-y divide-gray-200"> |
| 48 | + <thead className="bg-gray-50 dark:bg-gray-800"> |
| 49 | + <tr> |
| 50 | + <th |
| 51 | + scope="col" |
| 52 | + className="dark:text-gray-100 px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider" |
| 53 | + > |
| 54 | + Title |
| 55 | + </th> |
| 56 | + <th |
| 57 | + scope="col" |
| 58 | + className="dark:text-gray-100 px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider" |
| 59 | + > |
| 60 | + Subject |
| 61 | + </th> |
| 62 | + <th |
| 63 | + scope="col" |
| 64 | + className="dark:text-gray-100 px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider" |
| 65 | + > |
| 66 | + Difficulty |
| 67 | + </th> |
| 68 | + <th |
| 69 | + scope="col" |
| 70 | + className="dark:text-gray-100 px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider" |
| 71 | + > |
| 72 | + Creator |
| 73 | + </th> |
| 74 | + <th scope="col" className="relative px-6 py-3"> |
| 75 | + <span className="sr-only">View</span> |
| 76 | + </th> |
| 77 | + </tr> |
| 78 | + </thead> |
| 79 | + <tbody className="bg-white dark:bg-gray-300 divide-y divide-gray-200"> |
| 80 | + {benchmarks.map((benchmark: benchmarkModel) => ( |
| 81 | + <BenchmarkRow |
| 82 | + key={benchmark.id?.toString()} |
| 83 | + benchmark={benchmark} |
| 84 | + /> |
| 85 | + ))} |
| 86 | + </tbody> |
| 87 | + </table> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + </div> |
| 91 | + </div> |
| 92 | + </div> |
| 93 | + </Page> |
| 94 | + ); |
| 95 | +}; |
| 96 | + |
| 97 | +export default UserBenchmarks; |
0 commit comments