Skip to content
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

added default profile picture and logout button #20

Merged
merged 1 commit into from
Mar 30, 2024
Merged
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
Binary file added public/default_pfp.svg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion src/components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
<li><RouterLink to="/faq" class="link">FAQ</RouterLink></li>
<li class="profile-pic" v-if="isLoggedIn">
<RouterLink :to="isLoggedIn ? '/user' : '/login'">
<img :src="profilePicture" class="profile-picture" alt="Profile" />
<img
:src="profilePicture ? profilePicture : defaultProfilePicture"
class="profile-picture"
alt="Profile"
/>
</RouterLink>
</li>
<li v-if="isLoggedIn">
<button @click="logout" class="blackButton button">Logout</button>
</li>
<li>
<RouterLink to="/signup" class="purpleButton button" v-if="!isLoggedIn">Sign up</RouterLink>
</li>
Expand All @@ -22,9 +29,11 @@
<script setup>
import { ref, onMounted } from 'vue'
import { getUserByUsername } from '@/api/userHooks'
import router from '@/router'

const isLoggedIn = ref(sessionStorage.getItem('isLoggedIn') === 'true')
const profilePicture = ref('')
const defaultProfilePicture = '/default_pfp.svg.png'

const fetchUserProfilePicture = async () => {
if (isLoggedIn.value) {
Expand All @@ -34,6 +43,12 @@ const fetchUserProfilePicture = async () => {
}
}

const logout = () => {
sessionStorage.clear()
isLoggedIn.value = false
router.push('/login')
}

onMounted(() => {
fetchUserProfilePicture()
})
Expand Down
7 changes: 6 additions & 1 deletion src/components/UserPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
<Card class="profile-section">
<h2 id="header">Your profile</h2>
<div class="profile-info">
<img :src="user.profilePicture ?? ''" alt="Profile Picture" class="profile-picture" />
<img
:src="user.profilePicture ? user.profilePicture : defaultProfilePicture"
alt="Profile Picture"
class="profile-picture"
/>
<div>
<p class="email">{{ user.email }}</p>
<div class="file-input-container">
Expand Down Expand Up @@ -137,6 +141,7 @@ const currentQuizId = ref<string | null>(null) // Define currentQuizId type
const quizComments = ref<{ [key: number]: Comment[] }>({}) // Define quizComments type
const fetchedQuizzes = ref<Quiz[]>([]) // Define fetchedQuizzes type
const currentQuiz = ref<Quiz | null>(null) // Define currentQuiz type
const defaultProfilePicture = '/default_pfp.svg.png'

interface Comment {
id: number
Expand Down
Loading