From 5872afafabb928580760fe61ed093ea29429cb4d Mon Sep 17 00:00:00 2001
From: Eugene Serb <46799701+eugene-serb@users.noreply.github.com>
Date: Fri, 2 Feb 2024 18:54:40 +0300
Subject: [PATCH 01/16] #100 replace links from MHeader into parent component
---
src/components/molecules/MHeader.vue | 37 ++++++----------------------
src/layouts/LDefault.vue | 36 ++++++++++++++++++++++++++-
2 files changed, 42 insertions(+), 31 deletions(-)
diff --git a/src/components/molecules/MHeader.vue b/src/components/molecules/MHeader.vue
index 96fea50..46968e5 100644
--- a/src/components/molecules/MHeader.vue
+++ b/src/components/molecules/MHeader.vue
@@ -2,44 +2,21 @@
import { defineComponent } from 'vue';
import { ATextLogo } from '@/components/atoms';
import MHeaderMenu from '@/components/molecules/MHeaderMenu.vue';
-import { URL_TO_HOME, URL_TO_FAQ, URL_TO_ABOUT, URL_TO_DONATE, URL_TO_MOBILE } from '@/constants';
+import { URL_TO_HOME } from '@/constants';
+import type { PropType } from 'vue';
import type { Link } from '@/models';
defineComponent({
name: 'MHeader',
});
-/**
- * Ссылки.
- */
-const links: Link[] = [
- {
- text: 'Gamepad',
- to: URL_TO_HOME,
- target: '_self',
+defineProps({
+ links: {
+ type: Array as PropType,
+ default: () => [],
},
- {
- text: 'Mobile',
- to: URL_TO_MOBILE,
- target: '_self',
- },
- {
- text: 'FAQ',
- to: URL_TO_FAQ,
- target: '_self',
- },
- {
- text: 'About',
- to: URL_TO_ABOUT,
- target: '_self',
- },
- {
- text: 'Donate',
- to: URL_TO_DONATE,
- target: '_self',
- },
-];
+});
diff --git a/src/layouts/LDefault.vue b/src/layouts/LDefault.vue
index 128cac8..cbe172c 100644
--- a/src/layouts/LDefault.vue
+++ b/src/layouts/LDefault.vue
@@ -1,15 +1,49 @@
-
+
From be2fd7cfcf91ed6b885b233a7d93eed62c66d4e7 Mon Sep 17 00:00:00 2001
From: Eugene Serb <46799701+eugene-serb@users.noreply.github.com>
Date: Fri, 2 Feb 2024 19:06:05 +0300
Subject: [PATCH 02/16] #102 add storage types
---
src/storage/core/types.ts | 11 +++++++++++
1 file changed, 11 insertions(+)
create mode 100644 src/storage/core/types.ts
diff --git a/src/storage/core/types.ts b/src/storage/core/types.ts
new file mode 100644
index 0000000..2654ad1
--- /dev/null
+++ b/src/storage/core/types.ts
@@ -0,0 +1,11 @@
+export interface CommonStorageModel {
+ id: string;
+ serializer: (object: T) => string;
+ deserializer: (raw: string | null) => T;
+}
+
+export interface CommonStorageController {
+ get: () => T;
+ set: (data: T) => void;
+ remove: () => void;
+};
From f39bb29a96577df9970dfb2ed548bd5f9406f334 Mon Sep 17 00:00:00 2001
From: Eugene Serb <46799701+eugene-serb@users.noreply.github.com>
Date: Fri, 2 Feb 2024 19:06:33 +0300
Subject: [PATCH 03/16] #102 add storage fetcher
---
src/storage/core/fetcher.ts | 27 +++++++++++++++++++++++++++
src/storage/core/index.ts | 2 ++
2 files changed, 29 insertions(+)
create mode 100644 src/storage/core/fetcher.ts
create mode 100644 src/storage/core/index.ts
diff --git a/src/storage/core/fetcher.ts b/src/storage/core/fetcher.ts
new file mode 100644
index 0000000..f8722d8
--- /dev/null
+++ b/src/storage/core/fetcher.ts
@@ -0,0 +1,27 @@
+import type { CommonStorageModel } from './types';
+
+function get(store: CommonStorageModel): T {
+ const dto = localStorage.getItem(store.id);
+ return store.deserializer(dto);
+}
+
+function set(data: T, store: CommonStorageModel): void {
+ localStorage.setItem(store.id, store.serializer(data));
+}
+
+function remove(store: CommonStorageModel): void {
+ localStorage.removeItem(store.id);
+}
+
+function clear(): void {
+ localStorage.clear();
+}
+
+const fetcher = {
+ get,
+ set,
+ remove,
+ clear,
+};
+
+export default fetcher;
diff --git a/src/storage/core/index.ts b/src/storage/core/index.ts
new file mode 100644
index 0000000..989a42c
--- /dev/null
+++ b/src/storage/core/index.ts
@@ -0,0 +1,2 @@
+export * from './fetcher';
+export * from './types';
From 330c5adf4cb62ae86c310b66481d37bcb121d584 Mon Sep 17 00:00:00 2001
From: Eugene Serb <46799701+eugene-serb@users.noreply.github.com>
Date: Fri, 2 Feb 2024 19:07:19 +0300
Subject: [PATCH 04/16] #102 add model for storage announcements
---
src/storage/models/announcements.ts | 43 +++++++++++++++++++++++++++++
src/storage/models/index.ts | 1 +
2 files changed, 44 insertions(+)
create mode 100644 src/storage/models/announcements.ts
create mode 100644 src/storage/models/index.ts
diff --git a/src/storage/models/announcements.ts b/src/storage/models/announcements.ts
new file mode 100644
index 0000000..a056bfa
--- /dev/null
+++ b/src/storage/models/announcements.ts
@@ -0,0 +1,43 @@
+import type { CommonStorageModel } from '../core/types';
+import type { AnnouncementSavedData } from '@/models';
+
+export function announcementStorage(): CommonStorageModel {
+ return {
+ id: 'announcements',
+ serializer: (object: AnnouncementSavedData[]) => {
+ return JSON.stringify(object);
+ },
+ deserializer: (dto: string | null) => {
+ if (!dto || typeof dto !== 'string') {
+ return [];
+ }
+
+ const raw = JSON.parse(dto);
+
+ if (!Array.isArray(raw)) {
+ return [];
+ }
+
+ const filtered = raw.filter((entity) => {
+ const { id, enabled } = entity;
+
+ if (!(id && typeof id === 'string')) {
+ return false;
+ }
+
+ if (!(typeof enabled === 'boolean')) {
+ return false;
+ }
+
+ return true;
+ });
+
+ const result = filtered.map((entity) => ({
+ id: entity.id,
+ enabled: entity.enabled,
+ }));
+
+ return result;
+ },
+ };
+}
diff --git a/src/storage/models/index.ts b/src/storage/models/index.ts
new file mode 100644
index 0000000..2d6aa7f
--- /dev/null
+++ b/src/storage/models/index.ts
@@ -0,0 +1 @@
+export * from './announcements';
From e84e7faaf0d641d4df932a4fdbdf41619dba0cfe Mon Sep 17 00:00:00 2001
From: Eugene Serb <46799701+eugene-serb@users.noreply.github.com>
Date: Fri, 2 Feb 2024 19:07:42 +0300
Subject: [PATCH 05/16] #102 add controller for storage announcements
---
src/storage/controllers/announcements.ts | 25 ++++++++++++++++++++++++
src/storage/controllers/index.ts | 1 +
2 files changed, 26 insertions(+)
create mode 100644 src/storage/controllers/announcements.ts
create mode 100644 src/storage/controllers/index.ts
diff --git a/src/storage/controllers/announcements.ts b/src/storage/controllers/announcements.ts
new file mode 100644
index 0000000..86f9730
--- /dev/null
+++ b/src/storage/controllers/announcements.ts
@@ -0,0 +1,25 @@
+import fetcher from '../core/fetcher';
+import { announcementStorage } from '../models';
+
+import type { CommonStorageController } from '../core';
+import type { AnnouncementSavedData } from '@/models';
+
+function get(): AnnouncementSavedData[] {
+ return fetcher.get(announcementStorage());
+}
+
+function set(data: AnnouncementSavedData[]): void {
+ fetcher.set(data, announcementStorage());
+}
+
+function remove(): void {
+ fetcher.remove(announcementStorage());
+}
+
+const announcements: CommonStorageController = {
+ get,
+ set,
+ remove,
+};
+
+export default announcements;
diff --git a/src/storage/controllers/index.ts b/src/storage/controllers/index.ts
new file mode 100644
index 0000000..2146bbc
--- /dev/null
+++ b/src/storage/controllers/index.ts
@@ -0,0 +1 @@
+export { default as announcements } from './announcements';
From fdc76653106cf6be59bd61c36c91889dd81b989b Mon Sep 17 00:00:00 2001
From: Eugene Serb <46799701+eugene-serb@users.noreply.github.com>
Date: Fri, 2 Feb 2024 19:07:55 +0300
Subject: [PATCH 06/16] #102 export storage
---
src/storage/index.ts | 1 +
1 file changed, 1 insertion(+)
create mode 100644 src/storage/index.ts
diff --git a/src/storage/index.ts b/src/storage/index.ts
new file mode 100644
index 0000000..a6c3cbc
--- /dev/null
+++ b/src/storage/index.ts
@@ -0,0 +1 @@
+export * as storage from './controllers';
From 63fb7e3088b166db4db9a46c012e39e71df3a0f0 Mon Sep 17 00:00:00 2001
From: Eugene Serb <46799701+eugene-serb@users.noreply.github.com>
Date: Fri, 2 Feb 2024 19:08:54 +0300
Subject: [PATCH 07/16] #102 connect announcements composable into storage
layer
---
src/composables/useAnnouncements.ts | 57 ++++-------------------------
1 file changed, 8 insertions(+), 49 deletions(-)
diff --git a/src/composables/useAnnouncements.ts b/src/composables/useAnnouncements.ts
index c5efe97..feaaa89 100644
--- a/src/composables/useAnnouncements.ts
+++ b/src/composables/useAnnouncements.ts
@@ -1,4 +1,5 @@
import { ref, watch } from 'vue';
+import { storage } from '@/storage';
import type { Ref } from 'vue';
import type { Announcement, AnnouncementSavedData } from '@/models';
@@ -27,7 +28,7 @@ export function useAnnouncements(
*
* @private
*/
- const _announcementSavedData = ref(_getDataFromStorage());
+ const _announcementSavedData = ref(_getSavedData());
/**
* Анонсы.
@@ -39,7 +40,7 @@ export function useAnnouncements(
watch(
announcements,
() => {
- _setDataIntoStorage(announcements.value);
+ _setSavedData(announcements.value);
},
{ deep: true },
);
@@ -87,51 +88,15 @@ export function useAnnouncements(
}));
}
- /**
- * Десериализовать DTO AnnouncementSavedData.
- *
- * @private
- * @param dto DTO сохранённой конфигурации анонсов.
- * @returns Сохранённая конфигурация анонсов.
- */
- function _deserialize(dto: string): AnnouncementSavedData[] {
- const raw = JSON.parse(dto);
-
- if (!Array.isArray(raw)) {
- return [];
- }
-
- const filtered = raw.filter((entity) => {
- const { id, enabled } = entity;
-
- if (!(id && typeof id === 'string')) {
- return false;
- }
-
- if (!(typeof enabled === 'boolean')) {
- return false;
- }
-
- return true;
- });
-
- return filtered.map((entity) => ({
- id: entity.id,
- enabled: entity.enabled,
- }));
- }
-
/**
* Сохранить данные в localStorage
*
* @private
* @param announcements Данные, которые надо поместить в localStorage.
*/
- function _setDataIntoStorage(announcements: Announcement[]): void {
- const save = _createAnnouncementSavedData(announcements);
- const dto = JSON.stringify(save);
-
- window.localStorage.setItem(storageKey.value, dto);
+ function _setSavedData(announcements: Announcement[]): void {
+ const savedData = _createAnnouncementSavedData(announcements);
+ storage.announcements.set(savedData);
}
/**
@@ -140,14 +105,8 @@ export function useAnnouncements(
* @private
* @returns Сохранённое состояние анонсов.
*/
- function _getDataFromStorage(): AnnouncementSavedData[] {
- const dto = window.localStorage.getItem(storageKey.value);
-
- if (!dto) {
- return [];
- }
-
- return _deserialize(dto);
+ function _getSavedData(): AnnouncementSavedData[] {
+ return storage.announcements.get();
}
return {
From f2b2716091573fbcd0c5b34e6f71d19d301f0487 Mon Sep 17 00:00:00 2001
From: Eugene Serb <46799701+eugene-serb@users.noreply.github.com>
Date: Fri, 2 Feb 2024 19:11:51 +0300
Subject: [PATCH 08/16] #102 format
---
src/storage/core/types.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/storage/core/types.ts b/src/storage/core/types.ts
index 2654ad1..64a9eae 100644
--- a/src/storage/core/types.ts
+++ b/src/storage/core/types.ts
@@ -8,4 +8,4 @@ export interface CommonStorageController {
get: () => T;
set: (data: T) => void;
remove: () => void;
-};
+}
From bb494d5d982685e3119e2a7b10e10a2693f0425c Mon Sep 17 00:00:00 2001
From: Eugene Serb <46799701+eugene-serb@users.noreply.github.com>
Date: Fri, 2 Feb 2024 19:29:07 +0300
Subject: [PATCH 09/16] #102 add new interface for fetcher and add jsdoc
---
src/storage/core/types.ts | 68 +++++++++++++++++++++++++++++++++++++--
1 file changed, 66 insertions(+), 2 deletions(-)
diff --git a/src/storage/core/types.ts b/src/storage/core/types.ts
index 64a9eae..4266b9d 100644
--- a/src/storage/core/types.ts
+++ b/src/storage/core/types.ts
@@ -1,11 +1,75 @@
+/**
+ * Общий интерфейс модели данных хранилища.
+ */
export interface CommonStorageModel {
+ /**
+ * Идентификатор хранилища. Служит ключом при записи данных.
+ */
id: string;
- serializer: (object: T) => string;
- deserializer: (raw: string | null) => T;
+ /**
+ * Сериализатор данных.
+ *
+ * @param data Данные.
+ * @returns DTO
+ */
+ serializer: (data: T) => string;
+ /**
+ * Десериализатор данных.
+ *
+ * @param dto Транспортный объект данных.
+ * @returns Данные.
+ */
+ deserializer: (dto: string | null) => T;
}
+/**
+ * Общий интерфейс контроллера хранилища данных.
+ */
export interface CommonStorageController {
+ /**
+ * Извлечь данные.
+ *
+ * @returns Данные.
+ */
get: () => T;
+ /**
+ * Записать данные.
+ *
+ * @param data Данные.
+ */
set: (data: T) => void;
+ /**
+ * Удалить данные.
+ */
remove: () => void;
}
+
+/**
+ * Fetcher слоя storage, с которым работают контроллеры.
+ */
+export interface Fetcher {
+ /**
+ * Извлечь данные.
+ *
+ * @param store Модель данных хранилища.
+ * @returns Данные.
+ */
+ get: (store: CommonStorageModel) => T,
+ /**
+ * Записать данные.
+ *
+ * @param data Данные.
+ * @param store Модель данных хранилища.
+ */
+ set: (data: T, store: CommonStorageModel) => void,
+ /**
+ * Удалить данные.
+ *
+ * @param store Модель данных хранилища.
+ */
+ remove: (store: CommonStorageModel) => void,
+ /**
+ * Очистить всё хранилище.
+ */
+ clear: () => void,
+}
From bc99dea3651563b6d76626f0de89a98222ec2ea5 Mon Sep 17 00:00:00 2001
From: Eugene Serb <46799701+eugene-serb@users.noreply.github.com>
Date: Fri, 2 Feb 2024 19:31:49 +0300
Subject: [PATCH 10/16] #102 type fetcher and add jsdoc
---
src/storage/core/fetcher.ts | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/src/storage/core/fetcher.ts b/src/storage/core/fetcher.ts
index f8722d8..d7bcee1 100644
--- a/src/storage/core/fetcher.ts
+++ b/src/storage/core/fetcher.ts
@@ -1,23 +1,46 @@
-import type { CommonStorageModel } from './types';
+import type { CommonStorageModel, Fetcher } from './types';
+/**
+ * Извлечь данные.
+ *
+ * @param store Модель данных хранилища.
+ * @returns Данные.
+ */
function get(store: CommonStorageModel): T {
const dto = localStorage.getItem(store.id);
return store.deserializer(dto);
}
+/**
+ * Записать данные.
+ *
+ * @param data Данные.
+ * @param store Модель данных хранилища.
+ */
function set(data: T, store: CommonStorageModel): void {
localStorage.setItem(store.id, store.serializer(data));
}
+/**
+ * Удалить данные.
+ *
+ * @param store Модель данных хранилища.
+ */
function remove(store: CommonStorageModel): void {
localStorage.removeItem(store.id);
}
+/**
+ * Очистить всё хранилище.
+ */
function clear(): void {
localStorage.clear();
}
-const fetcher = {
+/**
+ * Fetcher слоя storage.
+ */
+const fetcher: Fetcher = {
get,
set,
remove,
From b77243ecc6e0b12e7991a95de76f50210e1ef5d2 Mon Sep 17 00:00:00 2001
From: Eugene Serb <46799701+eugene-serb@users.noreply.github.com>
Date: Fri, 2 Feb 2024 19:36:07 +0300
Subject: [PATCH 11/16] #102 update model and add jsdoc
---
src/storage/models/announcements.ts | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/src/storage/models/announcements.ts b/src/storage/models/announcements.ts
index a056bfa..f912558 100644
--- a/src/storage/models/announcements.ts
+++ b/src/storage/models/announcements.ts
@@ -1,12 +1,32 @@
import type { CommonStorageModel } from '../core/types';
import type { AnnouncementSavedData } from '@/models';
+/**
+ * Модель данных хранилища Announcements.
+ *
+ * @returns
+ */
export function announcementStorage(): CommonStorageModel {
return {
+ /**
+ * Идентификатор хранилища. Служит ключом при записи данных.
+ */
id: 'announcements',
- serializer: (object: AnnouncementSavedData[]) => {
- return JSON.stringify(object);
+ /**
+ * Сериализатор данных.
+ *
+ * @param data Данные.
+ * @returns DTO
+ */
+ serializer: (data: AnnouncementSavedData[]) => {
+ return JSON.stringify(data);
},
+ /**
+ * Десериализатор данных.
+ *
+ * @param dto Транспортный объект данных.
+ * @returns Данные.
+ */
deserializer: (dto: string | null) => {
if (!dto || typeof dto !== 'string') {
return [];
From 8ba102e50b1702e501b9672a56e0bfe04a60aef7 Mon Sep 17 00:00:00 2001
From: Eugene Serb <46799701+eugene-serb@users.noreply.github.com>
Date: Fri, 2 Feb 2024 19:37:53 +0300
Subject: [PATCH 12/16] #102 add jsdoc
---
src/storage/controllers/announcements.ts | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/storage/controllers/announcements.ts b/src/storage/controllers/announcements.ts
index 86f9730..4804b5c 100644
--- a/src/storage/controllers/announcements.ts
+++ b/src/storage/controllers/announcements.ts
@@ -4,18 +4,34 @@ import { announcementStorage } from '../models';
import type { CommonStorageController } from '../core';
import type { AnnouncementSavedData } from '@/models';
+/**
+ * Извлечь данные.
+ *
+ * @returns Данные.
+ */
function get(): AnnouncementSavedData[] {
return fetcher.get(announcementStorage());
}
+/**
+ * Записать данные.
+ *
+ * @param data Данные.
+ */
function set(data: AnnouncementSavedData[]): void {
fetcher.set(data, announcementStorage());
}
+/**
+ * Удалить данные.
+ */
function remove(): void {
fetcher.remove(announcementStorage());
}
+/**
+ * Контроллер хранилища данных Announcements.
+ */
const announcements: CommonStorageController = {
get,
set,
From 7a887eb798234391e7f9a6657da1ff93fb38750c Mon Sep 17 00:00:00 2001
From: Eugene Serb <46799701+eugene-serb@users.noreply.github.com>
Date: Fri, 2 Feb 2024 19:45:12 +0300
Subject: [PATCH 13/16] #102 delete storage key from composable and
MAnnouncement
---
src/components/molecules/MAnnouncement.vue | 9 ++-------
src/composables/useAnnouncements.ts | 8 ++------
2 files changed, 4 insertions(+), 13 deletions(-)
diff --git a/src/components/molecules/MAnnouncement.vue b/src/components/molecules/MAnnouncement.vue
index f5504fb..2c28577 100644
--- a/src/components/molecules/MAnnouncement.vue
+++ b/src/components/molecules/MAnnouncement.vue
@@ -1,5 +1,5 @@