-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from frontend-park-mail-ru/NM-93
NM-93: fix csat error
- Loading branch information
Showing
13 changed files
with
274 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,32 @@ | ||
import { Router } from '../shared/lib/router.js'; | ||
import { LAYOUT, PAGES } from './routes.js'; | ||
import { userStore } from '../entities/user/index.js'; | ||
import { Router } from "../shared/lib/router.js"; | ||
import { LAYOUT, PAGES } from "./routes.js"; | ||
|
||
export class App { | ||
constructor() { | ||
this.router = new Router(); | ||
this.registerRoutes(); | ||
this.registerLayout(); | ||
} | ||
constructor() { | ||
this.router = new Router(); | ||
this.registerRoutes(); | ||
this.registerLayout(); | ||
} | ||
|
||
/** | ||
* Starts the application by making the router listen for path changes. | ||
*/ | ||
async run() { | ||
if (userStore.isAuth() && !userStore.csrfToken) { | ||
await userStore.getCSRFToken(); | ||
} | ||
this.router.listen(); | ||
} | ||
/** | ||
* Starts the application by making the router listen for path changes. | ||
*/ | ||
async run() { | ||
this.router.listen(); | ||
} | ||
|
||
/** | ||
* Registers all the defined pages in the application with the router. | ||
*/ | ||
registerRoutes() { | ||
PAGES.forEach(({ path, view, updateLayout }) => { | ||
this.router.registerPath(path, view, updateLayout); | ||
}); | ||
} | ||
/** | ||
* Registers the application's layout views with the router. | ||
*/ | ||
registerLayout() { | ||
LAYOUT.forEach((view) => this.router.registerLayout(view)); | ||
} | ||
/** | ||
* Registers all the defined pages in the application with the router. | ||
*/ | ||
registerRoutes() { | ||
PAGES.forEach(({ path, view, updateLayout }) => { | ||
this.router.registerPath(path, view, updateLayout); | ||
}); | ||
} | ||
/** | ||
* Registers the application's layout views with the router. | ||
*/ | ||
registerLayout() { | ||
LAYOUT.forEach((view) => this.router.registerLayout(view)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { csatStore } from './model/store.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Storage } from '../../../shared/lib/storage.js'; | ||
|
||
class CSATStore { | ||
constructor() { | ||
this.storage = { | ||
csat: Storage.load('csat') || {}, | ||
}; | ||
} | ||
|
||
submitted = () => { | ||
return this.storage.csat?.submitted; | ||
}; | ||
|
||
submit = () => { | ||
this.storage.csat = { | ||
submitted: true, | ||
}; | ||
Storage.save('csat', this.storage.csat); | ||
}; | ||
} | ||
|
||
export const csatStore = new CSATStore(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
import { UploadAvatarView } from '../../../widgets/uploadAvatar/index.js'; | ||
import { EditUserView } from '../../../widgets/editUser/index.js'; | ||
import { userStore } from '../../../entities/user/index.js'; | ||
import { PUBLIC_ERRORS } from '../../../shared/lib/index.js'; | ||
import { eventBus } from '../../../shared/lib/index.js'; | ||
import { UploadAvatarView } from "../../../widgets/uploadAvatar/index.js"; | ||
import { EditUserView } from "../../../widgets/editUser/index.js"; | ||
import { userStore } from "../../../entities/user/index.js"; | ||
import { PUBLIC_ERRORS } from "../../../shared/lib/index.js"; | ||
import { eventBus } from "../../../shared/lib/index.js"; | ||
|
||
export class EditProfilePage { | ||
parent; | ||
username; | ||
|
||
constructor(params) { | ||
this.parent = document.querySelector('#root'); | ||
this.username = params['username']; | ||
this.parent = document.querySelector("#root"); | ||
this.username = params["username"]; | ||
} | ||
|
||
async render() { | ||
this.parent.innerHTML = ''; | ||
this.parent.innerHTML = ""; | ||
|
||
await userStore.checkAuth(); | ||
if (!userStore.isAuth()) { | ||
console.error(PUBLIC_ERRORS.UNAUTHORIZED); | ||
eventBus.emit('navigate', '/'); | ||
return; | ||
} | ||
|
||
const user = userStore.storage.user; | ||
const user = userStore.storage.user; | ||
|
||
if (user.username != this.username) { | ||
console.error(PUBLIC_ERRORS.FORBIDDEN); | ||
eventBus.emit('navigate', '/'); | ||
eventBus.emit("navigate", "/"); | ||
return; | ||
} | ||
|
||
this.pageContent = document.createElement('div'); | ||
this.pageContent.classList.add('page_content'); | ||
this.parent.appendChild(this.pageContent); | ||
this.pageContent = document.createElement("div"); | ||
this.pageContent.classList.add("page_content"); | ||
this.parent.appendChild(this.pageContent); | ||
|
||
const uploadAvatarView = new UploadAvatarView(this.pageContent, user.id); | ||
await uploadAvatarView.render(); | ||
|
||
const editUserView = new EditUserView(this.pageContent, user.id); | ||
await editUserView.render(); | ||
|
||
eventBus.emit('hidePlayer'); | ||
eventBus.emit("hidePlayer"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.