Conversation
src/components/tool-bar.js
Outdated
src/components/tool-bar.js
Outdated
|
|
||
| constructor() { | ||
| super(); | ||
| this.editorKey = ''; |
There was a problem hiding this comment.
Зачем прописывать конструктор для начальных значений, если можно их при объявлении полей класса сразу писать?
There was a problem hiding this comment.
Потому что для реактивности переменной это необходимо. Если я определю реактивный атрибут через поле класса, то реактивность потеряется. Другой вопрос, правда, в том, нужна ли мне эта реактивность здесь - скорее всего нет, поэтому можно действительно в поле класса просто определить.
src/components/tool-bar.js
Outdated
|
|
||
| render() { | ||
| return html` | ||
| <ul class="Lsst-n P0 M0 H100p D-f Ai-c Jc-fs Flg1"> |
There was a problem hiding this comment.
Список здесь не подходит, тут ведь элементы разного типа
src/components/tool-bar.js
Outdated
| return html` | ||
| <ul class="Lsst-n P0 M0 H100p D-f Ai-c Jc-fs Flg1"> | ||
| <li class="M0 P0 Pr4u D-f Ai-str Ps -Ctx"> | ||
| <label for="editor-key" hidden> Editor's key</label> |
There was a problem hiding this comment.
Нужно доступное скрытие, а не полное. И связывать с инпутом лучше вкладыванием, а не по id
src/components/tool-bar.js
Outdated
| <li class="M0 P0 Pr4u D-f Ai-str Ps -Ctx"> | ||
| <label for="editor-key" hidden> Editor's key</label> | ||
| <input name="editor-key" type="text" value="${this.editorKey}" @keyup="${this.typeKey}" placeholder="Editor's key" autocomplete="off" | ||
| class="M0 P1u;3u Bdtlr1u Bdblr1u Fns4u Bd1;s;$accent800 Ol-n_f Bgc-$core800 C-$accent900_ph C-$accent800_f:ph -Ts_ph C-$accent900"> |
There was a problem hiding this comment.
Если Ol-n_f делаем, то надо альтернативный фокус делать обязательно. Либо не надо убирать дефолтный
src/components/tool-bar.js
Outdated
|
|
||
| </li> | ||
| <li class="M0 Mr4u"> | ||
| <button class="btn D P1.5u;4u Lnh1.2 Bgc-$brand Bgc-$brand500_h C#fff Bdrd1u Txd-n C-$accent800 -Ts"> Share </button> |
| <body class="P0 M0 H100vh"> | ||
| <header class="W100p H-$headerH Mxh18u D-g Gtc1fr;1fr P2u;5u Bgc-$core700"> | ||
| <header class="W100p H-$headerH Mxh18u D-g Gtc1fr;1fr;1fr P2u;5u Bgc-$core700"> | ||
|
|
index.html
Outdated
| <a href="https://mlut.style/" class="Txd-n C-$accent800 C-$brand_h -Ts Fnw600"> Main</a> | ||
| </li> | ||
| <li class="M0"> | ||
| <a href="https://mlutcss.github.io/mlut/" class="Txd-n C-$accent800 C-$brand_h -Ts Fnw600"> Docs</a> |
There was a problem hiding this comment.
Неверная ссылка на доку. Подлей апдейты из мастера
src/components/tool-bar.js
Outdated
| </li> | ||
| </ul> | ||
|
|
||
| <div class="Ps-a Txa-l W20vw T-$headerH R0 Zi20 P2u Fns5u Tsd300ms" |
There was a problem hiding this comment.
Tsd300ms - зачем, если есть дефолтный?
There was a problem hiding this comment.
И вот это как раз отдельный компонент должен быть, который мы по событию показываем. При этом, тексты ошибок в отдельным глобальном словаре лежат
| @@ -0,0 +1,48 @@ | |||
| class Client { | |||
| static apiUrl = ''; | |||
There was a problem hiding this comment.
Зачем static? Это же синглтон
| @@ -0,0 +1,48 @@ | |||
| class Client { | |||
There was a problem hiding this comment.
По дефолту сам класс тоже экспортируем. И название надо более подходящее, а не просто client
| static editorsKey = ''; | ||
| static sketchId = ''; | ||
|
|
||
| async makeRequest(path, method = 'GET', data = {}) { |
There was a problem hiding this comment.
make в названии метода здесь не подходит
| return fetch( | ||
| `${this.apiUrl}` + path, | ||
| options | ||
| ).then((resp) => { |
There was a problem hiding this comment.
Обработку запроса тут лучше вот такую сделать:
const result = r.headers.get('content-type').includes('application/json') ?
r.json() : r.text();
if (r.ok && r.status >= 200 && r.status < 400) {
return result;
}
throw (await result);| } | ||
|
|
||
| async getInitialCode(path) { | ||
| return await this.makeRequest(path); |
There was a problem hiding this comment.
| return await this.makeRequest(path); | |
| return this.makeRequest(path); |
В любом случае промис возвращается
|
|
||
| export class ErrorMessage extends LitElement { | ||
| static properties = { | ||
| errorText: { type: String }, |
There was a problem hiding this comment.
| errorText: { type: String }, | |
| text: { type: String }, |
| export class ErrorMessage extends LitElement { | ||
| static properties = { | ||
| errorText: { type: String }, | ||
| status: { type: String } |
| this.isToolbarAware = false; | ||
|
|
||
| if (urlParams.has('art')) { | ||
| client.apiUrl = 'https://00017615-8bbc-455f-8757-eb63ba8c7d31.mock.pstmn.io/arts/'; |
There was a problem hiding this comment.
Это все внутри клиента должно быть. В этом и смысл абстракции, что все детали там скрыты
| async firstUpdated() { | ||
| this.isToolbarAware = false; | ||
|
|
||
| if (urlParams.has('art')) { |
There was a problem hiding this comment.
И зачем тут вообще арты? Это совершенно другая задача
|
|
||
| try { | ||
| const res = await client.getInitialCode(client.sketchId); | ||
| [this.checkpointLayout, this.checkpointConfig] = [res.html, res.sass || '@use \'@mlut/core\';']; |
There was a problem hiding this comment.
Не надо делать такое присваивание. В большинстве случаев плохо читается
| client.sketchId = urlParams.get('sketch'); | ||
| } | ||
|
|
||
| try { |
There was a problem hiding this comment.
Асинхронную обработку ошибок лучше через чепочку промисов делать - так лучше читается
| } | ||
|
|
||
| [this.currentLayout, this.currentConfig] = [this.checkpointLayout, this.checkpointConfig]; | ||
| eventBus.emit('first-update', { |
There was a problem hiding this comment.
Лучше более подходящее название события, типа editor-init. И все эти названия должны быть в словаре (enum), а не строчками в коде
| } | ||
| }); | ||
|
|
||
| this.dispatchEvent(new CustomEvent('first-loaded', { bubbles: true })); |
There was a problem hiding this comment.
То же самое - не подходящее название
| checkpointConfig = ''; | ||
| currentLayout = ''; | ||
| currentConfig = ''; | ||
| isToolbarAware = false; |
There was a problem hiding this comment.
Непонятно по названию, для чего это
| controlToolbar(layout, config) { | ||
| if ((layout != this.checkpointLayout || config != this.checkpointConfig)) { | ||
| if (!this.isToolbarAware) { | ||
| eventBus.emit('enable-submit', { |
There was a problem hiding this comment.
Лучше событие toggle-* и в payload отправляется true/false
| console.log(client.editorsKey); | ||
| history.pushState(null, null, `/?sketch=${client.sketchId}`); | ||
|
|
||
| eventBus.emit('sketch-is-shared', { |
There was a problem hiding this comment.
Это не через события делается. Методы с отправкой запросов передаются в компонент тулбара и назначаются на клики по нужным кнопкам
|
|
||
| try { | ||
| console.log('Share requested'); | ||
| const res = await this.makePostRequest(event); |
| return await this.makeRequest(path); | ||
| } | ||
|
|
||
| async createNewSketch(path, method = 'POST', data) { |
There was a problem hiding this comment.
Тут нужен 1 метод putSketch и запрос всегда put. Он как создает, так и изменяет скетч
|
|
||
| render() { | ||
| return html` | ||
| <div id="error-wrapper" class="Ps-a Txa-l W20vw T-$headerH R0 Zi20 P2u Fns5u Tsd300ms" |
| import { client } from '../assets/scripts/client.js'; | ||
| import { errorTexts } from '../assets/data/error-texts'; | ||
|
|
||
| export class SandboxToolbar extends LitElement { |
There was a problem hiding this comment.
У нас же вроде 1 toolbar, зачем еще префикс sandbox?
|
|
||
| </ul> | ||
|
|
||
| <error-message status="${this.errorStatus}"> |
There was a problem hiding this comment.
Я писал, что он должен в main-comp лежать и по событию вызываться
| }; | ||
|
|
||
| typeKey(e) { | ||
| client.editorsKey = e.target.value; |
There was a problem hiding this comment.
Надо сделать метод у клиента setEditorsKey и через него устанавливать. Сам editorsKey - приватное свойство, как и все остальные
No description provided.