From 0065217f081dab87f120f71303c2808b27516e1a Mon Sep 17 00:00:00 2001 From: TatsianaSauko Date: Tue, 10 Sep 2024 11:48:08 +0300 Subject: [PATCH 1/5] fix: reset selection of other items when one is selected --- src/store.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/store.js b/src/store.js index 9afab7e81..5a2e09f49 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 { + item.selected = false; } return item; }), From 8ea83ed32f66a4696181158375f8e43c46f63776 Mon Sep 17 00:00:00 2001 From: TatsianaSauko Date: Tue, 10 Sep 2024 11:55:44 +0300 Subject: [PATCH 2/5] feat: implement unique code generation for new items --- src/store.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/store.js b/src/store.js index 5a2e09f49..b64ed0000 100644 --- a/src/store.js +++ b/src/store.js @@ -3,7 +3,10 @@ */ class Store { constructor(initState = {}) { - this.state = initState; + this.state = { + ...initState, + nextCode: 1, // Начальное значение для уникальных кодов + }; this.listeners = []; // Слушатели изменений состояния } @@ -42,9 +45,11 @@ class Store { * Добавление новой записи */ addItem() { + const newCode = this.state.nextCode; this.setState({ ...this.state, - list: [...this.state.list, { code: this.state.list.length + 1, title: 'Новая запись' }], + list: [...this.state.list, { code: newCode, title: 'Новая запись' }], + nextCode: newCode + 1, // Увеличиваем счетчик }); } From 820ca95e087d3e27b904e05d1f5349ee7ebd6fc7 Mon Sep 17 00:00:00 2001 From: TatsianaSauko Date: Tue, 10 Sep 2024 12:25:50 +0300 Subject: [PATCH 3/5] feat: display selection count for each item --- src/app.js | 8 +++++++- src/store.js | 5 ++++- src/styles.css | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/app.js b/src/app.js index 8ad1c64b4..c09d5baa5 100644 --- a/src/app.js +++ b/src/app.js @@ -28,8 +28,14 @@ function App({ store }) { >
{item.code}
{item.title}
+ {item.selectionCount > 0 && ( +
Выделяли {item.selectionCount} раз
+ )}
- +
diff --git a/src/store.js b/src/store.js index b64ed0000..aa68ddc4f 100644 --- a/src/store.js +++ b/src/store.js @@ -5,7 +5,7 @@ class Store { constructor(initState = {}) { this.state = { ...initState, - nextCode: 1, // Начальное значение для уникальных кодов + nextCode: 8, // Начальное значение для уникальных кодов }; this.listeners = []; // Слушатели изменений состояния } @@ -74,6 +74,9 @@ class Store { list: this.state.list.map(item => { if (item.code === code) { item.selected = !item.selected; + if (item.selected) { + item.selectionCount = (item.selectionCount || 0) + 1; + } } else { item.selected = false; } diff --git a/src/styles.css b/src/styles.css index 67e37a9b3..f6631aa9c 100644 --- a/src/styles.css +++ b/src/styles.css @@ -59,3 +59,8 @@ body { justify-content: flex-end; padding: 20px 20px 20px 10px; } + +.Item-selectionCount { + font-size: 12px; + padding: 20px 20px 20px 10px; +} From 090844883b144d49e68f78ce8eb9bae01307ed06 Mon Sep 17 00:00:00 2001 From: TatsianaSauko Date: Wed, 11 Sep 2024 09:32:46 +0300 Subject: [PATCH 4/5] fix: unique code generation and selection count display --- src/app.js | 7 +++++-- src/store.js | 28 ++++++++++++++++++++++++++-- src/styles.css | 3 +-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/app.js b/src/app.js index c09d5baa5..e901342fc 100644 --- a/src/app.js +++ b/src/app.js @@ -27,10 +27,13 @@ function App({ store }) { onClick={() => store.selectItem(item.code)} >
{item.code}
-
{item.title}
+
{item.title} {item.selectionCount > 0 && ( -
Выделяли {item.selectionCount} раз
+
+  (Выделяли {store.getSelectionCountText(item.selectionCount)}) +
)} +