Skip to content
Snippets Groups Projects
Commit 96eb6ff0 authored by MaximeOLIVA's avatar MaximeOLIVA
Browse files

part1 fonctionnelle mais faut opti homepage

parent 872fe527
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -4,6 +4,11 @@ let data_user_home = null;
window.onload = function() {
if(localStorage.getItem("token") != null) {
displayProfilView();
if(localStorage.getItem("browse_success") == "true") {
localStorage.setItem("browsed_email", localStorage.getItem("reloadBrowsed"));
} else {
localStorage.removeItem("browsed_email");
}
openTab(localStorage.getItem("tab"));
} else {
displayWelcomeView();
......@@ -257,8 +262,9 @@ function browse_email(){
let email = document.getElementById("input_email_browse").value;
let form = document.getElementById("email_browsed");
form.reset();
display_wall_info(email, 'BP');
localStorage.setItem("browsed_email", email);
localStorage.setItem("reloadBrowsed", localStorage.getItem("browsed_email"));
display_wall_info(email, 'BP');
}
//------------------------------------TAB MANAGMENT--------------------------------------
......@@ -268,6 +274,10 @@ function openTab(tabName) {
var i, tabcontent, tablinks;
localStorage.setItem("tab", tabName);
if(tabName != "browsePage") {
localStorage.removeItem("browsed_email");
}
// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
......@@ -280,12 +290,14 @@ function openTab(tabName) {
tablinks[i].className = tablinks[i].className.replace("active", "");
}
if(tabName == "homePage") {
if(tabName == "homePage" && localStorage.getItem("email_username") != null) {
display_wall_info(localStorage.getItem("email_username"), "HP");
} else if (tabName == "browsePage" && localStorage.getItem("browsed_email") != null) {
display_wall_info(localStorage.getItem("browsed_email"), "BP");
}
console.log(data_user_home);
document.getElementById("browse_error").style.display = "none";
document.getElementById(tabName).style.display = "block";
document.getElementById("tab_" + tabName).className += " active";
......@@ -298,6 +310,7 @@ function display_wall_info(email, tab) {
let data_user;
get_user_info(email, tab, function(data){
data_user = data;
console.log(data_user);
if(data_user != null) {
if(data_user.success) {
if(tab == "BP") {
......@@ -326,8 +339,7 @@ function display_wall_info(email, tab) {
function get_user_info(email, tab, callback) {
//call the server if data aren't already stored
if((tab == "BP") && (localStorage.getItem("browsed_email") != email || data_user_browse == null)
&& (localStorage.getItem("browsed_email") != null)) {
if(tab == "BP") {
let req = new XMLHttpRequest();
req.open("GET", "/account/get/data/" + email, true);
req.setRequestHeader("token", localStorage.getItem("token"));
......@@ -338,24 +350,27 @@ function get_user_info(email, tab, callback) {
data : JSON.parse(req.responseText),
success : true
};
localStorage.setItem("browse_success", "true");
callback(data_user_browse);
}else if(req.status == 404){
data_user_browse = {
message : "This user doesn't exist",
success : false
};
localStorage.setItem("browse_success", false);
callback(data_user_browse);
}else if(req.status == 401){
data_user_browse = {
message : "Problem with the server",
success : false
};
localStorage.setItem("browse_success", false);
callback(data_user_browse);
}
}
};
req.send();
} else if ((tab == "HP") && (data_user_home == null)) {
} else if (tab == "HP") {
let req = new XMLHttpRequest();
req.open("GET", "/account/get/data/" + email, true);
req.setRequestHeader("token", localStorage.getItem("token"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment