From f6387d493c49fa0bbde5200dbac3f3f76a34cdbc Mon Sep 17 00:00:00 2001
From: Martin Wighus Holtmon <martinwh@stud.ntnu.no>
Date: Fri, 12 Nov 2021 12:59:46 +0100
Subject: [PATCH] projectPart2/Problem1: Made updateHeader a bit safer

---
 .../src/photo-share/components/top-bar/TopBar.jsx  | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/projectSecondPart/src/photo-share/components/top-bar/TopBar.jsx b/projectSecondPart/src/photo-share/components/top-bar/TopBar.jsx
index d058ca4..1eae740 100644
--- a/projectSecondPart/src/photo-share/components/top-bar/TopBar.jsx
+++ b/projectSecondPart/src/photo-share/components/top-bar/TopBar.jsx
@@ -27,13 +27,15 @@ class TopBar extends React.Component {
 
 	updateHeader = (pathname) => {
 		const path = pathname.split('/');
-		const user = PROG2053Models.userModel(path[3]);
-		let newContext = '';
-		if (path[2] === 'photos') {
-			newContext += 'Photos of ';
+		if (path[2] && path[3]) {
+			const user = PROG2053Models.userModel(path[3]);
+			let newContext = '';
+			if (path[2] === 'photos') {
+				newContext += 'Photos of ';
+			}
+			newContext += `${user.first_name} ${user.last_name}`;
+			this.setState({headerContext: newContext});
 		}
-		newContext += `${user.first_name} ${user.last_name}`;
-		this.setState({headerContext: newContext});
 	};
 
 	render() {
-- 
GitLab