+
diff --git a/src/components/home_components/navigationbar.vue b/src/components/home_components/navigationbar.vue
index 5e785a2..cc5cfdd 100644
--- a/src/components/home_components/navigationbar.vue
+++ b/src/components/home_components/navigationbar.vue
@@ -5,7 +5,7 @@
import router from "../../router";
import { ref, onMounted, onUnmounted } from 'vue';
-let self = localStorage.getItem("self_id");
+let self;
const isMobile = ref(false);
const show = ref(false);
@@ -45,6 +45,8 @@ onMounted(() => {
if(localStorage.getItem("mobile") === null){
show.value = false;
}
+ self = localStorage.getItem("self_id");
+ console.log("SELF NB: " + self);
});
onUnmounted(() => {
diff --git a/src/components/login_components/login_comp.vue b/src/components/login_components/login_comp.vue
index d539706..c0ea542 100644
--- a/src/components/login_components/login_comp.vue
+++ b/src/components/login_components/login_comp.vue
@@ -20,6 +20,11 @@ async function login(event: Event) {
const username = input_username_mail;
const password = input_user_password;
+ if (username.value === "" || password.value === "") {
+ alert("Please fill all fields");
+ return;
+ }
+
try {
const response = await fetch('http://localhost:8000/api/account/login', {
method: 'POST',
@@ -34,6 +39,7 @@ async function login(event: Event) {
localStorage.setItem('isLoggedIn', 'true');
localStorage.setItem('username', username.value);
localStorage.setItem('self_id', data["userId"]);
+ console.log("SELF LOG: " + data["userId"]);
alert("You will be now redirected");
router.push('/');
} else {
diff --git a/src/components/messages.vue b/src/components/messages.vue
index 0bf1c48..ab9b149 100644
--- a/src/components/messages.vue
+++ b/src/components/messages.vue
@@ -8,14 +8,14 @@ import Msg_main from "./messages_components/msg_main.vue";
-
-
+
+
-
+
diff --git a/src/components/messages_components/msg_main.vue b/src/components/messages_components/msg_main.vue
index 9e383a2..2454bfc 100644
--- a/src/components/messages_components/msg_main.vue
+++ b/src/components/messages_components/msg_main.vue
@@ -40,10 +40,10 @@ function openChat(contact) {
-
-
-
-
+
+
+
+
{{nachricht.content}}
diff --git a/src/components/notifications.vue b/src/components/notifications.vue
index 3777071..b548aa1 100644
--- a/src/components/notifications.vue
+++ b/src/components/notifications.vue
@@ -7,14 +7,14 @@ import Contacts from "./home_components/contacts.vue";
-
-
+
+
-
+
diff --git a/src/components/posts.vue b/src/components/posts.vue
index a9fa5f8..706ab06 100644
--- a/src/components/posts.vue
+++ b/src/components/posts.vue
@@ -72,6 +72,7 @@ async function getPost(post_id: any) {
if(post_response.status === 404) {
console.error("No comments found.");
+ alert("Post not found")
await router.push('/');
return;
}
@@ -102,6 +103,13 @@ async function getComment(post_id: any) {
const user_response = await fetch(`http://localhost:8000/api/users`, { method: 'GET' });
const usersDATA: User[] = await user_response.json();
+ if(comments_response.status === 404 || user_response.status === 404) {
+ console.error("ERRROR");
+ alert("Error try it again later.");
+ await router.push('/');
+ return;
+ }
+
comments.value = fetchedComments.map(comment => {
const author = usersDATA.find(u => u.user_id === comment.author_user_id) || {
username: 'Unknown',
@@ -115,6 +123,8 @@ async function getComment(post_id: any) {
};
});
+ comments.value.sort((a, b) => b.post_id - a.post_id);
+
console.log(comments.value);
} catch (e) {
console.error(e);
@@ -136,11 +146,10 @@ async function addLike() { // Post liken
body: `{"userId":${self_id}}`,
});
- if (!response_like.ok) {
- const errorText = await response_like.text();
- console.error('Server-Fehlertext:', errorText);
- //post.value.likes--;
- throw new Error(`HTTP error! status: ${response_like.status}, text: ${errorText}`);
+ if(response_like.status === 404) {
+ console.error("ERROR");
+ await router.push('/');
+ return;
}
const data = await response_like.json();
@@ -154,6 +163,10 @@ async function addLike() { // Post liken
}
async function comment_create_text(comment_text: string) {
+ if (comment_text === null) {
+ alert("Please write something before commenting.");
+ return;
+ }
try {
const response = await fetch(`http://localhost:8000/api/post/${post_uuid.value}/comment`, {
method: 'POST',
@@ -162,11 +175,13 @@ async function comment_create_text(comment_text: string) {
const data = await response.json();
- if(response.ok) {
- await getComment(parseInt(post_uuid.value));
- } else {
- alert("Error while posting comment.");
+ if(response.status === 404) {
+ console.error("ERROR");
+ await router.push('/');
+ return;
}
+
+ await getComment(parseInt(post_uuid.value));
return data;
} catch (error) {
console.error(error);
@@ -183,11 +198,10 @@ async function addLike_comment(comment_id: number | string) {
body: `{"userId":${self_id}}`,
});
- if (!response_like.ok) {
- const errorText = await response_like.text();
- console.error('Server-Fehlertext:', errorText);
- post.value.likes--;
- throw new Error(`HTTP error! status: ${response_like.status}, text: ${errorText}`);
+ if(response_like.status === 404) {
+ console.error("ERROR");
+ await router.push('/');
+ return;
}
const data = await response_like.json();
@@ -201,11 +215,15 @@ async function addLike_comment(comment_id: number | string) {
throw error;
}
}
+
+function gotoProfile(user_id: string | number) {
+ router.push(`/profile/${user_id}`);
+}
-
+
diff --git a/src/components/profile.vue b/src/components/profile.vue
index 9f785a4..7cd8802 100644
--- a/src/components/profile.vue
+++ b/src/components/profile.vue
@@ -7,7 +7,7 @@ import Profile_main from "./profile_components/profile_main.vue";
-
+
diff --git a/src/components/profile_components/profile_main.vue b/src/components/profile_components/profile_main.vue
index 072e47f..a0d47bf 100644
--- a/src/components/profile_components/profile_main.vue
+++ b/src/components/profile_components/profile_main.vue
@@ -6,90 +6,64 @@ const route = useRoute();
const router = useRouter();
const upc = ref([]);
-let self_id ;
-let profile_id = ref();
+const profile_id = ref
(null);
+const userData = ref(null);
onMounted(async () => {
- console.log("PARAMS: "+ route.path);
const pathArray = route.path.split('/');
- console.log(pathArray);
if (pathArray.length > 2) {
- profile_id.value = pathArray[2];
- console.log("profile_id 0: ", profile_id.value);
-
+ profile_id.value = parseInt(pathArray[2], 10);
+ } else {
+ console.warn("No profile ID found in the route.");
}
- if (!profile_id) {
+ if (!profile_id.value) {
alert('No profile selected. Redirecting to feed.');
await router.push('/');
return;
}
await create_own_posts();
+ await getUser();
});
async function create_own_posts() {
try {
- // posts und user holen und schauen ob sie richtig sidn
- const post_response = await fetch('http://localhost:8000/api/posts', { method: 'GET' });
+ const post_response = await fetch('http://localhost:8000/api/posts', {
+ method: 'GET',
+ });
if (!post_response.ok) {
throw new Error(`HTTP error! status: ${post_response.status}`);
}
const postsDATA = await post_response.json();
- const user_response = await fetch('http://localhost:8000/api/users', { method: 'GET' });
- if (!user_response.ok) {
- throw new Error(`HTTP error! status: ${user_response.status}`);
+ upc.value = postsDATA.filter((post) => post.user_id === profile_id.value);
+
+ if (upc.value.length === 0) {
+ console.warn('No posts found for this user.');
+ return;
}
- const usersDATA = await user_response.json();
+ //console.log("upc: "+ JSON.stringify(upc.value, null, 2));
- // posts und user kombinieren
- const combinedPosts = postsDATA.filter(post => post.user_id === profile_id).map(post => {
- const user = usersDATA.find(user => user.user_id === post.user_id);
-
- return {
- post_id: post.posts_uuid,
- post_text: post.post_text,
- likes: post.likes,
- comments: post.comments,
- displayname: user ? user.displayname : 'Unknown',
- username: user ? user.username : 'unknown_user',
- user_id: post.user_id,
- };
- });
- console.log("upc: " + upc.value);
- console.log("combinedPosts: " + combinedPosts);
-
- //upc.value = combinedPosts;
-
- upc.value = combinedPosts.sort((a, b) => b.post_id - a.post_id);;
-
- console.log("upc 2: " + upc.value);
- console.log("combinedPosts 2: " + combinedPosts);
- } catch (e) {
- console.error("An error has occurred. Please try again later.");
- console.error(e);
+ return upc.value;
+ } catch (error) {
+ console.error('Error fetching posts:', error);
+ upc.value = [];
}
- console.log(upc.value);
}
async function addLike(post_id: string | number, user_id: number, index: number) {
try {
- console.log("UPC: ", upc.value);
- console.log("post_id: ", post_id);
upc.value[index].likes++;
const response = await fetch(`http://localhost:8000/api/post/${post_id}/like`, {
method: 'POST',
- headers: {'content-type': 'application/json'},
+ headers: { 'content-type': 'application/json' },
body: `{"userId":${user_id}}`,
});
- console.log('Antwort-Status:', response.status);
-
if (!response.ok) {
const errorText = await response.text();
console.error('Server-Fehlertext:', errorText);
- //upc.value[index].likes--;
throw new Error(`HTTP error! status: ${response.status}, text: ${errorText}`);
}
@@ -102,68 +76,124 @@ async function addLike(post_id: string | number, user_id: number, index: number)
}
}
+function consoleLog() {
+ console.log("upc: ", upc.value);
+ console.log("profile_id: ", profile_id.value);
+}
+
+function gotoPost(post_id: string | number) {
+ localStorage.setItem("viewedpost", post_id.toString());
+ router.push(`/post/${post_id}`);
+}
+
+function copyLink(post_id: string | number) {
+ const tocopy = `http://localhost:5173/post/${post_id}`;
+ navigator.clipboard.writeText(tocopy);
+ alert("Copied to clipboard with");
+}
+
+async function getUser() {
+ try {
+ const response = await fetch('http://localhost:8000/api/users/');
+ if (!response.ok) {
+ throw new Error(`HTTP error! status: ${response.status}`);
+ }
+ const users = await response.json();
+ const user = users.find((u) => u.user_id === profile_id.value);
+
+ if (user) {
+ const followerCount = JSON.parse(user.followers).length;
+ const followingCount = JSON.parse(user.following).length;
+
+ userData.value = {
+ ...user,
+ followerCount,
+ followingCount,
+ };
+ console.log("userData: ", userData.value);
+ return userData;
+ } else {
+ console.error('Benutzer nicht gefunden.');
+ userData.value = null;
+ }
+ } catch (error) {
+ console.error('Fehler beim Abrufen der Benutzerdaten:', error);
+ userData.value = null;
+ }
+}
+
+function copyUser(){
+ const tocopy = `http://localhost:5173/profile/${profile_id.value}`;
+ navigator.clipboard.writeText(tocopy);
+ alert("Copied to clipboard");
+}
-
-
-
Profile
-
-
-
-

+
Profile
+
+
+
-
-
+
+
+
+
-
-
-
-
-
Posts (x)
+
+
USER NOT FOUND
+
Go to Feed
-
- -
-
-
-
-
-
-
-
-
-
{{ postitem.content }}
-
-
-
-

-
-
+
+
Posts
+
+
-
+
\ No newline at end of file
diff --git a/src/components/register_components/register_main.vue b/src/components/register_components/register_main.vue
index 14c5057..bf98f3b 100644
--- a/src/components/register_components/register_main.vue
+++ b/src/components/register_components/register_main.vue
@@ -16,6 +16,11 @@ async function register() {
const password = register_input_password;
const std_text = "default";
+ if (username.value === "" || password.value === "" || displayname.value === "" || email.value === "") {
+ alert("Please fill all fields");
+ return;
+ }
+
console.log("Username: " + username.value + ", Password: " + password.value);
@@ -34,17 +39,17 @@ async function register() {
localStorage.setItem('isLoggedIn', 'true');
localStorage.setItem('username', username.value);
localStorage.setItem('self_id', data["userId"]);
+ console.log("SELF REG: " + data["userId"]);
alert("Account created! You will be now redirected");
router.push('/');
router.go(1);
- } else {
- alert("Something went wrong. Please try again later.");
}
const data = await response.json();
console.log(response);
} catch (e) {
console.log("An error has occurred. Please try again later.");
+ console.error(e);
}
}
diff --git a/src/components/search.vue b/src/components/search.vue
index f6c983a..b492e0b 100644
--- a/src/components/search.vue
+++ b/src/components/search.vue
@@ -8,8 +8,8 @@ import Contacts from "./home_components/contacts.vue";
-
-
+
+
@@ -18,7 +18,7 @@ import Contacts from "./home_components/contacts.vue";
-
+
diff --git a/src/components/search_components/search_main.vue b/src/components/search_components/search_main.vue
index 277b4c9..8c70820 100644
--- a/src/components/search_components/search_main.vue
+++ b/src/components/search_components/search_main.vue
@@ -119,30 +119,18 @@ function go_fs(){
-
-
Trending
-
- -
-
-
{{ i+1 }} - {{ bing.category}}
-
#{{ bing.name }}
-
{{ bing.nr_posts }} posts
-
-
-
-
@@ -150,7 +138,7 @@ function go_fs(){
-
+
diff --git a/src/components/settings.vue b/src/components/settings.vue
index 43cdfb0..4267060 100644
--- a/src/components/settings.vue
+++ b/src/components/settings.vue
@@ -16,15 +16,15 @@ function handleUpdateSetting(setting: string) {
-
-
+
+
-
+
-
+
diff --git a/src/components/settings_components/settings_main.vue b/src/components/settings_components/settings_main.vue
index 49ada99..9bd30f5 100644
--- a/src/components/settings_components/settings_main.vue
+++ b/src/components/settings_components/settings_main.vue
@@ -46,7 +46,7 @@ console.log(`Setting got (SM): ${props.selectedSetting}`);
-
+
diff --git a/src/components/settings_components/so_main.vue b/src/components/settings_components/so_main.vue
index 71e7ad9..815da91 100644
--- a/src/components/settings_components/so_main.vue
+++ b/src/components/settings_components/so_main.vue
@@ -13,7 +13,7 @@ function logout() {
-
+
diff --git a/src/router/index.ts b/src/router/index.ts
index 51ecae8..16e9394 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -80,10 +80,9 @@ const router = createRouter({
router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth && localStorage.getItem("isLoggedIn") !== "true") {
- console.log("User not logged in: redirecting to login.");
+ alert("not logged in ");
next({ name: "login" });
} else {
- console.log("User logged in or no auth required.");
next();
}
});