From 3f7a03d8b5d9347b6bdb3440f696425ab6f0fe25 Mon Sep 17 00:00:00 2001 From: detherminal <76167420+detherminal@users.noreply.github.com> Date: Tue, 18 Apr 2023 14:05:15 +0300 Subject: [PATCH] feat: changed themes.json style --- data/themes.json | 6 +++--- src/getThemeDetails.ts | 10 ++++++---- src/getThemeList.ts | 17 +++++++++-------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/data/themes.json b/data/themes.json index aa1e7ff..c027b47 100644 --- a/data/themes.json +++ b/data/themes.json @@ -1,6 +1,6 @@ { - "themes": [ - { + "themes": { + "dark" : { "name": "Dark", "id": "dark", "description": "Dark", @@ -16,5 +16,5 @@ "accentColorOrange": "0xFFFEA68D", "accentColorDark": "0xFFF3F3F3" } - ] + } } \ No newline at end of file diff --git a/src/getThemeDetails.ts b/src/getThemeDetails.ts index 29db92e..a4435f1 100644 --- a/src/getThemeDetails.ts +++ b/src/getThemeDetails.ts @@ -3,11 +3,13 @@ function getThemeDetails(id : string) { const json_file = fs.readFileSync("data/themes.json"); const json = JSON.parse(json_file); const themes = json.themes; - for (let i = 0; i < themes.length; i++) { - if (themes[i].id == id) { - return themes[i]; + var theme = {}; + Object.entries(themes).map(([key, value]) => { + if (key == id){ + theme = (themes[key]) } - } + }); + return theme } module.exports = getThemeDetails; \ No newline at end of file diff --git a/src/getThemeList.ts b/src/getThemeList.ts index cdd9cbd..b0fcd82 100644 --- a/src/getThemeList.ts +++ b/src/getThemeList.ts @@ -4,17 +4,18 @@ function getThemeList() { const json = JSON.parse(json_file); const themes = json.themes; var themeArray : Array = []; - for (let i = 0; i < themes.length; i++) { + // For loop that will look for all the themes in the themes.json file + Object.entries(themes).map(([key, value]) => { var theme : Object = { - "name": themes[i].name, - "id": themes[i].id, - "description": themes[i].description, - "primary_color": themes[i].primary_color, // Primary color is background color in the theme - "secondary_color": themes[i].secondary_color, // Secondary color is the color of the buttonBackPrimary in the theme - "tertiary_color": themes[i].tertiary_color, // Tertiary color is the color of the buttonTextPrimary in the theme + "name": themes[key].name, + "id": themes[key].id, + "description": themes[key].description, + "primary_color": themes[key].primary_color, // Primary color is background color in the theme + "secondary_color": themes[key].secondary_color, // Secondary color is the color of the buttonBackPrimary in the theme + "tertiary_color": themes[key].tertiary_color, // Tertiary color is the color of the buttonTextPrimary in the theme } themeArray.push(theme); - } + }) return themeArray; }