Skip to content
Snippets Groups Projects
Commit 9c5aac99 authored by VIktorGrev's avatar VIktorGrev
Browse files

style: Adding visual confirmation for sendt reqeust

parent 5e2d0917
No related branches found
No related tags found
1 merge request!75style: Adding visual confirmation for sendt reqeust
Pipeline #282868 passed with warnings
This commit is part of merge request !75. Comments created here will be created in the context of that merge request.
...@@ -99,8 +99,11 @@ ...@@ -99,8 +99,11 @@
</h5> </h5>
</div> </div>
<div class="col-md-3 col-sm-3"> <div class="col-md-3 col-sm-3">
<button class="btn btn-primary pull-right" @click="addFriend(user.id)">Legg <button class="btn btn-primary pull-right" @click="addFriend(user.id)"
til venn</button> :disabled="friendRequestsSent[user.id]"
v-if="!friendRequestsSent[user.id]">Legg til venn</button>
<button class="btn btn-secondary pull-right" disabled
v-if="friendRequestsSent[user.id]">Forespørsel sendt</button>
</div> </div>
</div> </div>
</div> </div>
...@@ -117,7 +120,7 @@ ...@@ -117,7 +120,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from 'vue'; import { type Ref, ref, onMounted } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { FriendService, UserService } from '@/api'; import { FriendService, UserService } from '@/api';
import type { UserDTO } from '@/api'; import type { UserDTO } from '@/api';
...@@ -131,6 +134,8 @@ const friendRequests = ref([] as any); ...@@ -131,6 +134,8 @@ const friendRequests = ref([] as any);
const addFriends = ref([] as any); const addFriends = ref([] as any);
const searchedUsers = ref([] as any); const searchedUsers = ref([] as any);
const friendRequestsSent: Ref<Record<number, boolean>> = ref({});
const searchWord = ref(""); const searchWord = ref("");
const elementsInFriendRequest = ref(false); const elementsInFriendRequest = ref(false);
...@@ -169,7 +174,13 @@ const addNewFriends = async () => { ...@@ -169,7 +174,13 @@ const addNewFriends = async () => {
}; };
async function addFriend(friendID: number) { async function addFriend(friendID: number) {
const response = await FriendService.addFriendRequest({ userId: friendID }); try {
await FriendService.addFriendRequest({ userId: friendID });
// Use a spread to update the state and keep immutability
friendRequestsSent.value = { ...friendRequestsSent.value, [friendID]: true };
} catch (error) {
console.error('Failed to send friend request', error);
}
} }
async function requestFriend() { async function requestFriend() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment