From a5e0aa60c77d7b9556a1d3f38ac0855a3b1f2efc Mon Sep 17 00:00:00 2001 From: Ivan Dakukin Date: Tue, 10 Sep 2024 16:53:37 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=201:=20=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=BB?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/store.js b/src/store.js index 9afab7e81..d1810c80e 100644 --- a/src/store.js +++ b/src/store.js @@ -69,6 +69,8 @@ class Store { list: this.state.list.map(item => { if (item.code === code) { item.selected = !item.selected; + } else if(item.selected) { + item.selected = false; } return item; }), From f0399a111879f42af453922aa4dcb4377b6b5bfa Mon Sep 17 00:00:00 2001 From: Ivan Dakukin Date: Tue, 10 Sep 2024 17:34:08 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=203:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=B0=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D0=B9=20=D1=8D?= =?UTF-8?q?=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.js | 7 ++++++- src/store.js | 5 ++++- src/utils.js | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/app.js b/src/app.js index 8ad1c64b4..174fd9f34 100644 --- a/src/app.js +++ b/src/app.js @@ -1,6 +1,7 @@ import React from 'react'; import { createElement } from './utils.js'; import './styles.css'; +import { getPlural } from './utils.js'; /** * Приложение @@ -27,7 +28,11 @@ function App({ store }) { onClick={() => store.selectItem(item.code)} >
{item.code}
-
{item.title}
+
+ {item.title} + {item.selectionCount && + ` | Выделяли ${item.selectionCount} ${getPlural(item.selectionCount)}`} +
diff --git a/src/store.js b/src/store.js index d1810c80e..d15df0d7d 100644 --- a/src/store.js +++ b/src/store.js @@ -68,8 +68,11 @@ class Store { ...this.state, list: this.state.list.map(item => { if (item.code === code) { + if (!item.selected) { + item.selectionCount = item.selectionCount ? item.selectionCount + 1 : 1; + } item.selected = !item.selected; - } else if(item.selected) { + } else if (item.selected) { item.selected = false; } return item; diff --git a/src/utils.js b/src/utils.js index d1b605243..d8eb96263 100644 --- a/src/utils.js +++ b/src/utils.js @@ -26,3 +26,18 @@ export function createElement(name, props = {}, ...children) { return element; } + +/** + * Получение слово "раз" в правильной форме в зависимости от числительного + * @param count {Number} Количество выделений + * @returns {String} + */ +export function getPlural(count) { + const lastDigit = count % 10; + const preLastDigit = Math.trunc(count / 10) % 10; + console.log(preLastDigit); + if([2, 3, 4].indexOf(lastDigit) !== -1 && preLastDigit !== 1) { + return "раза"; + } + return "раз"; +} From ca0b30c430d853f96219e10bfcd2eb62dcd0561c Mon Sep 17 00:00:00 2001 From: Ivan Dakukin Date: Tue, 10 Sep 2024 17:50:23 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=202:=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=D1=81=D0=B2=D0=B0=D0=B8=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=B4=D0=BE=D0=B2=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B8=20?= =?UTF-8?q?=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 1 + src/store.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index faa61aa77..b5e7a844f 100644 --- a/src/index.js +++ b/src/index.js @@ -14,6 +14,7 @@ const store = new Store({ { code: 6, title: 'Шестая запись' }, { code: 7, title: 'Седьмая запись' }, ], + nextCode: 8, }); const root = createRoot(document.getElementById('root')); diff --git a/src/store.js b/src/store.js index d15df0d7d..3e5277eef 100644 --- a/src/store.js +++ b/src/store.js @@ -44,7 +44,8 @@ class Store { addItem() { this.setState({ ...this.state, - list: [...this.state.list, { code: this.state.list.length + 1, title: 'Новая запись' }], + list: [...this.state.list, { code: this.state.nextCode, title: 'Новая запись' }], + nextCode: this.state.nextCode + 1, }); } From f57f981edb5fbeb34858e23aa4a99d44bd4e0e36 Mon Sep 17 00:00:00 2001 From: Ivan Dakukin Date: Thu, 12 Sep 2024 15:50:10 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B8=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8E=20nextCode,=20=D1=87=D1=82=D0=BE=D0=B1?= =?UTF-8?q?=D1=8B=20=D0=BD=D0=B5=20=D0=B1=D1=8B=D0=BB=D0=BE=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D1=81=D0=B5=D1=87=D0=B5=D0=BD=D0=B8=D0=B9=20=D1=81?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=B4=D0=B0=D0=BC=D0=B8=20=D0=B2=20=D0=B8=D1=81?= =?UTF-8?q?=D1=85=D0=BE=D0=B4=D0=BD=D0=BE=D0=BC=20=D0=BC=D0=B0=D1=81=D1=81?= =?UTF-8?q?=D0=B8=D0=B2=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 1 - src/store.js | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index b5e7a844f..faa61aa77 100644 --- a/src/index.js +++ b/src/index.js @@ -14,7 +14,6 @@ const store = new Store({ { code: 6, title: 'Шестая запись' }, { code: 7, title: 'Седьмая запись' }, ], - nextCode: 8, }); const root = createRoot(document.getElementById('root')); diff --git a/src/store.js b/src/store.js index 3e5277eef..871d91240 100644 --- a/src/store.js +++ b/src/store.js @@ -4,6 +4,7 @@ class Store { constructor(initState = {}) { this.state = initState; + this.state.nextCode = Math.max(...this.state.list.map(el => el.code)) + 1; this.listeners = []; // Слушатели изменений состояния }