Compare commits
2 Commits
5ba432e9fd
...
8e0514514b
Author | SHA1 | Date | |
---|---|---|---|
8e0514514b | |||
0626faae7f |
@ -19,6 +19,10 @@ class Profile
|
|||||||
async init(user_id)
|
async init(user_id)
|
||||||
{
|
{
|
||||||
let response = await this.client._get(`/api/profiles/${user_id}`);
|
let response = await this.client._get(`/api/profiles/${user_id}`);
|
||||||
|
|
||||||
|
if (response.status === 404)
|
||||||
|
return 1;
|
||||||
|
|
||||||
let response_data = await response.json();
|
let response_data = await response.json();
|
||||||
|
|
||||||
this.user_id = response_data.user_id;
|
this.user_id = response_data.user_id;
|
||||||
|
@ -28,7 +28,8 @@ class Profiles
|
|||||||
async getProfile(user_id)
|
async getProfile(user_id)
|
||||||
{
|
{
|
||||||
let profile = new Profile(this.client);
|
let profile = new Profile(this.client);
|
||||||
await profile.init(user_id);
|
if (await profile.init(user_id))
|
||||||
|
return null;
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,19 @@ const navigateTo = async (uri) => {
|
|||||||
history.pushState(null, null, uri);
|
history.pushState(null, null, uri);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function renderView(view)
|
||||||
|
{
|
||||||
|
let content = await view.getHtml();
|
||||||
|
if (content == null)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
view.setTitle();
|
||||||
|
document.querySelector("#app").innerHTML = content
|
||||||
|
|
||||||
|
if (await view.postInit())
|
||||||
|
renderView(new PageNotFoundView());
|
||||||
|
}
|
||||||
|
|
||||||
const router = async (uri) => {
|
const router = async (uri) => {
|
||||||
const routes = [
|
const routes = [
|
||||||
{ path: "/", view: Dashboard },
|
{ path: "/", view: Dashboard },
|
||||||
@ -80,14 +93,7 @@ const router = async (uri) => {
|
|||||||
lastView = view;
|
lastView = view;
|
||||||
|
|
||||||
await client.isAuthentificate();
|
await client.isAuthentificate();
|
||||||
let content = await view.getHtml();
|
renderView(view);
|
||||||
if (content == null)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
view.setTitle();
|
|
||||||
document.querySelector("#app").innerHTML = content
|
|
||||||
|
|
||||||
await view.postInit();
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,6 +10,10 @@ export default class extends AbstractView {
|
|||||||
async postInit()
|
async postInit()
|
||||||
{
|
{
|
||||||
let profile = await client.profiles.getProfile(this.user_id);
|
let profile = await client.profiles.getProfile(this.user_id);
|
||||||
|
|
||||||
|
if (profile === null)
|
||||||
|
return 1;
|
||||||
|
|
||||||
let info = document.getElementById("info");
|
let info = document.getElementById("info");
|
||||||
|
|
||||||
// Username
|
// Username
|
||||||
@ -18,7 +22,7 @@ export default class extends AbstractView {
|
|||||||
username.appendChild(document.createTextNode(profile.username));
|
username.appendChild(document.createTextNode(profile.username));
|
||||||
info.appendChild(username);
|
info.appendChild(username);
|
||||||
|
|
||||||
info.appendChild(document.createElement("br"));
|
info.appendChild(document.createElement("br"));
|
||||||
|
|
||||||
// Avatar
|
// Avatar
|
||||||
let avatar = document.createElement("img");
|
let avatar = document.createElement("img");
|
||||||
|
Loading…
Reference in New Issue
Block a user