From 4f4e2d1a3e48722b102d13eab321a98069af3d23 Mon Sep 17 00:00:00 2001 From: khatabwedaa Date: Sun, 23 Aug 2020 08:53:05 +0000 Subject: [PATCH] Prettified Code! --- src/models/Components.js | 105 +++++++++++++++------------------ src/models/ComponentsFilter.js | 11 ++-- 2 files changed, 53 insertions(+), 63 deletions(-) diff --git a/src/models/Components.js b/src/models/Components.js index d6dd8f3..7f8b2f4 100644 --- a/src/models/Components.js +++ b/src/models/Components.js @@ -1,84 +1,75 @@ export default [ { - name: 'Alerts', + name: "Alerts", components: [ - { name: 'SuccessPop' }, - { name: 'InfoPop' }, - { name: 'WarningPop' }, - { name: 'ErrorPop' }, - { name: 'NotificationPop' }, - { name: 'SuccessFullWidth' }, - { name: 'InfoFullWidth' }, - { name: 'WarningFullWidth' }, - { name: 'ErrorFullWidth' }, - + { name: "SuccessPop" }, + { name: "InfoPop" }, + { name: "WarningPop" }, + { name: "ErrorPop" }, + { name: "NotificationPop" }, + { name: "SuccessFullWidth" }, + { name: "InfoFullWidth" }, + { name: "WarningFullWidth" }, + { name: "ErrorFullWidth" }, ], }, { - name: 'Authentication', - components: [ - { name: 'SimpleLogin' }, - { name: 'LoginWithSideImage' }, - ] + name: "Authentication", + components: [{ name: "SimpleLogin" }, { name: "LoginWithSideImage" }], }, { - name: 'Cards', + name: "Cards", components: [ - { name: 'Article' }, - { name: 'ArticleWithSMIcons' }, - { name: 'ArticleWithImage' }, - { name: 'Product' }, - { name: 'ProductWithEvaluation' }, - { name: 'SimpleProduct' }, - { name: 'Testimonial' }, - { name: 'User' }, - { name: 'UserWithDetails' }, + { name: "Article" }, + { name: "ArticleWithSMIcons" }, + { name: "ArticleWithImage" }, + { name: "Product" }, + { name: "ProductWithEvaluation" }, + { name: "SimpleProduct" }, + { name: "Testimonial" }, + { name: "User" }, + { name: "UserWithDetails" }, ], }, { - name: 'Forms', + name: "Forms", + components: [{ name: "Simple" }, { name: "Newsletter" }], + }, + { + name: "Navbars", components: [ - { name: 'Simple' }, - { name: 'Newsletter' }, + { name: "ECommerce" }, + { name: "WithSearch" }, + { name: "WithAvatar" }, ], }, { - name: 'Navbars', + name: "Heros", components: [ - { name: 'ECommerce' }, - { name: 'WithSearch' }, - { name: 'WithAvatar' }, - ] - }, - { - name: 'Heros', - components: [ - { name: 'ECommerce' }, - { name: 'WithImage' }, - { name: 'WithPattern' }, + { name: "ECommerce" }, + { name: "WithImage" }, + { name: "WithPattern" }, ], }, { - name: 'Sections', + name: "Sections", components: [ - { name: 'AboutMe' }, - { name: 'Feature' }, - { name: 'OurTeam' }, - { name: 'ParagraphWithImage' }, - ] + { name: "AboutMe" }, + { name: "Feature" }, + { name: "OurTeam" }, + { name: "ParagraphWithImage" }, + ], }, { - name: 'Paginations', - components: [ - { name: 'Simple' }, - ] + name: "Paginations", + components: [{ name: "Simple" }], }, { - name: 'Footers', + name: "Footers", components: [ - { name: 'Simple' }, - { name: 'WithDetails' }, - { name: 'WithSubscribeForm' }, - ] + { name: "Simple" }, + { name: "WithDetails" }, + { name: "WithSubscribeForm" }, + ], }, -] +]; diff --git a/src/models/ComponentsFilter.js b/src/models/ComponentsFilter.js index 97f6809..abe489c 100644 --- a/src/models/ComponentsFilter.js +++ b/src/models/ComponentsFilter.js @@ -1,7 +1,6 @@ import components from "./Components"; export default class ComponentsFilter { - constructor() { this.components = components; } @@ -11,16 +10,16 @@ export default class ComponentsFilter { } whereCategory(category) { + if (this.isEmpty(category)) return this.components; - if(this.isEmpty(category)) return this.components; + let pattern = new RegExp(`^${category}`, "i"); - let pattern = new RegExp(`^${category}`, 'i'); - - return this.components.filter(category => category.name.match(pattern)); + return this.components.filter((category) => + category.name.match(pattern) + ); } isEmpty(string) { return string.length === 0; } - }