From 2b38e5f43c1da425d3019de9aed9d19da023388c Mon Sep 17 00:00:00 2001 From: Ulyana Lazutina Date: Tue, 10 Sep 2024 18:05:14 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D0=92=D1=8B=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store.js b/src/store.js index 9afab7e81..8f57c7af3 100644 --- a/src/store.js +++ b/src/store.js @@ -67,7 +67,7 @@ class Store { this.setState({ ...this.state, list: this.state.list.map(item => { - if (item.code === code) { + if (item.selected || item.code === code) { item.selected = !item.selected; } return item; From d828e36589171aed5f6867332104a383710f0394 Mon Sep 17 00:00:00 2001 From: Ulyana Lazutina Date: Tue, 10 Sep 2024 19:18:28 +0300 Subject: [PATCH 2/5] =?UTF-8?q?=D0=A3=D0=BD=D0=B8=D0=BA=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/store.js b/src/store.js index 8f57c7af3..20bd4a7db 100644 --- a/src/store.js +++ b/src/store.js @@ -5,6 +5,7 @@ class Store { constructor(initState = {}) { this.state = initState; this.listeners = []; // Слушатели изменений состояния + this.lastCode = this.state.list.at(-1).code; } /** @@ -44,7 +45,7 @@ class Store { addItem() { this.setState({ ...this.state, - list: [...this.state.list, { code: this.state.list.length + 1, title: 'Новая запись' }], + list: [...this.state.list, { code: this.lastCode += 1, title: 'Новая запись' }], }); } From b3f002fb71c2eefbfff9ea73bbf55461e84d2207 Mon Sep 17 00:00:00 2001 From: Ulyana Lazutina Date: Tue, 10 Sep 2024 19:53:23 +0300 Subject: [PATCH 3/5] =?UTF-8?q?=D0=9A=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B2=D0=BE=20=D1=81=D0=BE=D0=B2=D0=B5=D1=80=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B2=D1=8B=D0=B4=D0=B5=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.js | 4 ++-- src/store.js | 8 ++++++++ src/utils.js | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/app.js b/src/app.js index 8ad1c64b4..1b924c2f3 100644 --- a/src/app.js +++ b/src/app.js @@ -1,5 +1,5 @@ import React from 'react'; -import { createElement } from './utils.js'; +import { createElement, formatCount } from './utils.js'; import './styles.css'; /** @@ -27,7 +27,7 @@ function App({ store }) { onClick={() => store.selectItem(item.code)} >
{item.code}
-
{item.title}
+
{item.title} {item.count && `| Выделили ${formatCount(item.count)}`}
diff --git a/src/store.js b/src/store.js index 20bd4a7db..c3d5331c2 100644 --- a/src/store.js +++ b/src/store.js @@ -6,6 +6,7 @@ class Store { this.state = initState; this.listeners = []; // Слушатели изменений состояния this.lastCode = this.state.list.at(-1).code; + this.count = 1; } /** @@ -71,6 +72,13 @@ class Store { if (item.selected || item.code === code) { item.selected = !item.selected; } + if (item.selected) { + if (item.count >= 1) { + item.count++; + } else { + item.count = this.count; + } + } return item; }), }); diff --git a/src/utils.js b/src/utils.js index d1b605243..0617de1a6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -26,3 +26,20 @@ export function createElement(name, props = {}, ...children) { return element; } + +export function formatCount(count) { + const lastNum = count % 10; + + if (lastNum === 2 || lastNum === 3 || lastNum === 4) { + + if (count % 100 >= 12 && count % 100 <= 14) { + return `${count} раз`; + } else { + return `${count} раза`; + } + + } else { + return `${count} раз`; + } + +} From 87dbf201c0f2dd19df7af89a050cb749e5561406 Mon Sep 17 00:00:00 2001 From: Ulyana Lazutina Date: Wed, 11 Sep 2024 01:25:33 +0300 Subject: [PATCH 4/5] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BB=D0=B0=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8E=20=D1=83=D0=BD=D0=B8=D0=BA=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store.js | 4 +++- src/utils.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/store.js b/src/store.js index c3d5331c2..09f1ea115 100644 --- a/src/store.js +++ b/src/store.js @@ -1,3 +1,5 @@ +import { getLengthArray } from "./utils"; + /** * Хранилище состояния приложения */ @@ -5,7 +7,7 @@ class Store { constructor(initState = {}) { this.state = initState; this.listeners = []; // Слушатели изменений состояния - this.lastCode = this.state.list.at(-1).code; + this.lastCode = getLengthArray(this.state.list); this.count = 1; } diff --git a/src/utils.js b/src/utils.js index 0617de1a6..bad780c07 100644 --- a/src/utils.js +++ b/src/utils.js @@ -43,3 +43,13 @@ export function formatCount(count) { } } + +export function getLengthArray(array) { + + if (array.length === 0) { + return 0; + } else { + return array.length; + } + +} \ No newline at end of file From e1a138d63bb9b500b1ca49ba75725e78d4222476 Mon Sep 17 00:00:00 2001 From: Ulyana Lazutina Date: Sat, 14 Sep 2024 15:39:05 +0300 Subject: [PATCH 5/5] =?UTF-8?q?=D0=A3=D0=BD=D0=B8=D0=BA=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index bad780c07..8572a9512 100644 --- a/src/utils.js +++ b/src/utils.js @@ -49,7 +49,10 @@ export function getLengthArray(array) { if (array.length === 0) { return 0; } else { - return array.length; + const arrayCode = array.map((item) => { + return item.code; + }) + return Math.max.apply(null, arrayCode); } } \ No newline at end of file