diff --git a/src/App.tsx b/src/App.tsx
index 76738b6..18604de 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -6,17 +6,19 @@ import './App.css';
import BenchmarkDetail from './components/Benchmarks/BenchmarkDetail';
import Benchmarks from './components/Benchmarks/Benchmarks';
import CreateBenchmark from './components/Benchmarks/CreateBenchmark';
+import UserBenchmarks from './components/Benchmarks/UserBenchmarks';
import Landing from './components/Landing';
import Login from './components/Login';
import Register from './components/Register';
import PrivateRoute from './components/Routing/PrivateRoute';
import Rules from './components/rules/Rules';
+import User from './components/User';
function App() {
const queryClient = new QueryClient();
return (
-
+
@@ -29,8 +31,13 @@ function App() {
+
+
) => {
+ let benchmarks: benchmarkModel[] = [];
+ const {
+ isLoading: isBenchmarksLoading,
+ isError: isBenchmarksError,
+ data: benchmarksData,
+ error,
+ } = useBenchmarksForUser(match.params.id);
+
+ if (isBenchmarksLoading) {
+ return Loading.... ;
+ }
+
+ if (isBenchmarksError) {
+ if (error) {
+ return Error: {error.message} ;
+ }
+ }
+
+ if (benchmarksData) {
+ benchmarks = benchmarksData;
+ }
+
+ return (
+
+
+
+
+
+
+
+
+
+
+
+ Title
+
+
+ Subject
+
+
+ Difficulty
+
+
+ Creator
+
+
+ View
+
+
+
+
+ {benchmarks.map((benchmark: benchmarkModel) => (
+
+ ))}
+
+
+
+
+
+
+
+
+ );
+};
+
+export default UserBenchmarks;
diff --git a/src/components/Page/Navbar.tsx b/src/components/Page/Navbar.tsx
index 911491a..e9eac3b 100644
--- a/src/components/Page/Navbar.tsx
+++ b/src/components/Page/Navbar.tsx
@@ -5,7 +5,7 @@ import Gravatar from 'react-gravatar';
import { Link, useHistory } from 'react-router-dom';
import useDarkMode from 'use-dark-mode';
import { useToken } from '../../hooks/token';
-import useProfile from '../../hooks/users';
+import { useProfile } from '../../hooks/users';
const navigation = ['Benchmarks', 'Rules'];
const profile = ['Your Profile', 'Settings', 'Sign out'];
@@ -71,29 +71,27 @@ export default function Navbar() {
- {navigation.map(
- (item, itemIdx) => (
- // itemIdx === 0 ? (
- //
- // {/* Current: "bg-gray-900 text-white", Default: "text-gray-300 hover:bg-gray-700 hover:text-white" */}
- //
- // {item}
- //
- //
- // ) : (
-
- {item}
-
- ),
- // )
- )}
+
+ {'All benchmarks'}
+
+
+ {'My benchmarks'}
+
+
+ {'My profile'}
+
@@ -184,6 +182,16 @@ export default function Navbar() {
)}
))} */}
+
+
+ Profile
+
+
) => {
+ const {
+ isLoading: isProfileLoading,
+ isError: isProfileError,
+ data: profileData,
+ error,
+ } = useUser(match.params.id);
+
+ let benchmarks: benchmarkModel[] = [];
+ const { data: benchmarksData } = useBenchmarksForUser(match.params.id);
+
+ if (isProfileLoading) {
+ return Loading.... ;
+ }
+
+ if (isProfileError) {
+ if (error) {
+ return Error: {error.message} ;
+ }
+ }
+
+ if (benchmarksData) {
+ benchmarks = benchmarksData;
+ }
+
+ return (
+
+
+
+
+
+
+ {/* */}
+
+ {/* */}
+
+
+
+
+
+ {profileData?.name}
+
+
+ Developer
+
+ {/*
+ Lorem ipsum dolor sit amet consectetur adipisicing elit.
+ Reprehenderit, eligendi dolorum sequi illum qui unde
+ aspernatur non deserunt
+
*/}
+
+
+ Status
+
+
+ Active
+
+
+
+
+ Member since
+
+ {profileData?.createdAt
+ ? DateTime.fromISO(profileData?.createdAt).toISODate()
+ : ''}
+
+
+
+
+ {/* */}
+
+
+ {/* */}
+
+ {/* */}
+
+ {/* */}
+
+
+
+
+
+
+
+
+
+
+ Published benchmarks
+
+
+
+
+
+
+
+
+
+ Title
+
+
+ Subject
+
+
+ Difficulty
+
+
+ Creator
+
+
+ View
+
+
+
+
+ {benchmarks.map((benchmark: benchmarkModel) => (
+
+ ))}
+
+
+
+
+
+
+
+ {/* */}
+
+ {/* */}
+
+
+
+
+
+ );
+};
+
+export default User;
diff --git a/src/hooks/benchmark.ts b/src/hooks/benchmark.ts
index 0aaa428..374159c 100644
--- a/src/hooks/benchmark.ts
+++ b/src/hooks/benchmark.ts
@@ -22,6 +22,15 @@ export function useBenchmarkSList() {
});
}
+export function useBenchmarksForUser(username: string) {
+ return useQuery(`benchmark`, async () => {
+ const { data } = await authenticatedRequest({
+ url: `users/${username}/benchmarks`,
+ });
+ return data;
+ });
+}
+
export async function createBenchmark(bench: {
title: string;
subject: string;
diff --git a/src/hooks/users.ts b/src/hooks/users.ts
index b82946b..dc86925 100644
--- a/src/hooks/users.ts
+++ b/src/hooks/users.ts
@@ -15,9 +15,28 @@ function useProfile() {
return JSON.parse(window.atob(base64));
}
- return useQuery<{ email: string }, Error>('profile', async () => {
+ return useQuery<{ email: string; name: string; username: string }, Error>(
+ 'profile',
+ async () => {
+ if (token) {
+ const username = parseJwt(token).username;
+ const { data } = await authenticatedRequest({
+ url: `users/${username}`,
+ });
+ return data;
+ }
+ },
+ );
+}
+
+function useUser(username: string) {
+ const { token } = useToken();
+
+ return useQuery<
+ { email: string; name: string; username: string; createdAt: string },
+ Error
+ >('profile', async () => {
if (token) {
- const username = parseJwt(token).username;
const { data } = await authenticatedRequest({
url: `users/${username}`,
});
@@ -26,4 +45,4 @@ function useProfile() {
});
}
-export default useProfile;
+export { useProfile, useUser };