Skip to content

merge #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 16, 2024
Merged

merge #198

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/pages/_app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import { Context } from '../context';
import { useEffect, useState } from 'react';
import request from '@/utils/request';
import { Analytics } from "@vercel/analytics/react"
import { usePathname, useRouter } from 'next/navigation';


export default function App({ Component, pageProps }) {
const [username, setUsername] = useState('');
const [role, setRole] = useState('');
const [accountType, setAccountType] = useState('');
const [profilePic, setProfilePic] = useState('');
const [points, setPoints] = useState(0);
const path = usePathname();
const router = useRouter();

const appState = {
role, setRole,
Expand All @@ -26,7 +30,14 @@ export default function App({ Component, pageProps }) {
const fetchUser = async () => {
const url = process.env.NEXT_PUBLIC_API_URL + "/account";
const user = await request(url, "GET", null);
console.log(user);

if(user && user.error && user.error === "Not authorized") {
const pathNames = ["/", "/login", "/careers", "/register",
"/onboarding", "/forgot-password", "/education", "/userrs",
"/privacy-policy","/404", "/terms-of-service", "/learn"];
if(!pathNames.includes(path)) router.push("/login");
}

if (user && user.username) {
setRole(user.role);
setUsername(user.username);
Expand Down
42 changes: 26 additions & 16 deletions src/pages/users/[user].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -944,20 +944,26 @@ export default function Create() {
</span>
)}
{!ownUser && followedUser && (
<span className="ml-2 text-lg text-white">
<i
className="fas fa-user-slash text-lg hover:text-gray-400"
onClick={handleUnfollowUser}
<button
className="border rounded-sm border-neutral-500 ml-2 px-1 text-sm text-white hover:bg-neutral-600"
onClick={handleUnfollowUser}>
<i
className="fas fa-user-slash text-xs"
></i>
</span>
{' '}
Unfollow
</button>
)}
{!ownUser && !followedUser && (
<span className="ml-2 text-lg text-white">
<i
className="fas fa-user-plus text-lg hover:text-gray-400"
onClick={handleFollowUser}
<button
className="border rounded-sm border-neutral-500 ml-2 px-1 text-sm text-white hover:bg-neutral-600"
onClick={handleFollowUser}>
<i
className="fas fa-user-plus text-xs"
></i>
</span>
{' '}
Follow
</button>
)}
</h1>
<p className="text-white">
Expand All @@ -976,21 +982,25 @@ export default function Create() {
{user && (
<>
<span
className="cursor-pointer font-bold hover:text-gray-400"
className={`border border-neutral-500 rounded-sm px-2 py-1 cursor-pointer font-bold hover:bg-neutral-600 ${
displayMode === 'followers' ? 'bg-neutral-500' : ''
}`}
onClick={() => setDisplayMode('followers')}
>
{' '}
Followers
</span>{' '}
{' '}
{followerNum || '0'}
</span>
<span
className="ml-4 cursor-pointer font-bold hover:text-gray-400"
className={`border border-neutral-500 rounded-sm px-2 py-1 ml-4 cursor-pointer font-bold hover:bg-neutral-600 ${
displayMode === 'following' ? 'bg-neutral-500' : ''
}`}
onClick={() => setDisplayMode('following')}
>
{' '}
Following
</span>{' '}
{' '}
{followingNum || '0'}
</span>
</>
)}
</p>
Expand Down