From c68c8f1ef9c1038f4d50612fb56b564d1ca8524c Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 28 Jun 2020 11:24:20 -0500 Subject: [PATCH] refactor: icons --- src/client/index.scss | 2 +- src/client/resource-from-uri.js | 5 ++ src/client/resource.jsx | 6 +-- src/client/resources.jsx | 40 ++++++++-------- src/client/resources.raw.scss | 4 ++ src/client/sidebar.jsx | 46 ++++++++----------- .../resources/entity/entity.resource.js | 2 + src/common/resources/entity/icon.jsx | 13 ++++++ 8 files changed, 69 insertions(+), 49 deletions(-) create mode 100644 src/client/resource-from-uri.js create mode 100644 src/common/resources/entity/icon.jsx diff --git a/src/client/index.scss b/src/client/index.scss index e3e9715..14a0371 100644 --- a/src/client/index.scss +++ b/src/client/index.scss @@ -197,7 +197,7 @@ select { } } .icon { - padding: 0.75em; + padding: 0 0.25em 0 0.5em; } .close { background-color: transparent; diff --git a/src/client/resource-from-uri.js b/src/client/resource-from-uri.js new file mode 100644 index 0000000..2751ab4 --- /dev/null +++ b/src/client/resource-from-uri.js @@ -0,0 +1,5 @@ +import {all} from './resources.scwp'; + +const resources = Object.values(all()).map((M) => M.default); + +export default (uri) => resources.find((resource) => uri.match(resource.matcher)); diff --git a/src/client/resource.jsx b/src/client/resource.jsx index 20c1131..5cd5da0 100644 --- a/src/client/resource.jsx +++ b/src/client/resource.jsx @@ -4,19 +4,17 @@ import PropTypes from 'prop-types'; import React from 'react'; import {registerHooks} from 'scwp'; -import {all} from './resources.scwp'; +import resourceFromUri from './resource-from-uri'; const decorate = compose( contempo(require('./resource.raw.scss')), ); -const resources = Object.values(all()).map((M) => M.default); - const Resource = (props) => { const { uri, } = props; - const resource = resources.find((r) => uri.match(r.matcher)); + const resource = resourceFromUri(uri); const { Component = () => (
diff --git a/src/client/resources.jsx b/src/client/resources.jsx index fd63831..25601f2 100644 --- a/src/client/resources.jsx +++ b/src/client/resources.jsx @@ -11,6 +11,7 @@ import { } from 'react-tabs'; import Resource from './resource'; +import resourceFromUri from './resource-from-uri'; import { closeResource, setActiveResourceUri, @@ -30,24 +31,27 @@ const Resources = (props) => { onSelect={(index) => dispatch(setActiveResourceUri(uris[index]))} > - {uris.map((uri) => ( - - - - {uri} - - - - ))} + {uris.map((uri) => { + const resource = resourceFromUri(uri); + return ( + + + + {uri} + + + + ); + })} {uris.map((uri) => ( diff --git a/src/client/resources.raw.scss b/src/client/resources.raw.scss index 72ee5eb..655942b 100644 --- a/src/client/resources.raw.scss +++ b/src/client/resources.raw.scss @@ -2,3 +2,7 @@ height: 100%; width: 100%; } + +.wrapper .icon svg { + fill: #999999; +} diff --git a/src/client/sidebar.jsx b/src/client/sidebar.jsx index 017920f..ac9bf95 100644 --- a/src/client/sidebar.jsx +++ b/src/client/sidebar.jsx @@ -9,6 +9,7 @@ import ResourcesPacket from '~/common/packets/resources.packet'; import useSocket from './hooks/useSocket'; import FileExplorerTheme from './react-sortable-tree-theme-file-explorer'; +import resourceFromUri from './resource-from-uri'; import { setActiveResourceUri, } from './state'; @@ -29,32 +30,25 @@ const sortTree = (tree) => tree return node; }); -const mapComponents = (tree) => tree.map((node) => ({ - ...node, - children: node.children ? mapComponents(node.children) : [], - rawTitle: node.title, - title: ( - - {node.uri && ( - - - - )} - {node.title} - - ), -})); +const mapComponents = (tree) => tree.map((node) => { + const resource = node.uri && resourceFromUri(node.uri); + return ({ + ...node, + children: node.children ? mapComponents(node.children) : [], + rawTitle: node.title, + title: ( + + {node.uri && } + {node.title} + + ), + }); +}); const unmapComponents = (tree) => tree.map((node) => ({ ...node, diff --git a/src/common/resources/entity/entity.resource.js b/src/common/resources/entity/entity.resource.js index 43b1df6..1a8ba59 100644 --- a/src/common/resources/entity/entity.resource.js +++ b/src/common/resources/entity/entity.resource.js @@ -1,7 +1,9 @@ import EntityComponent from './entity'; +import Icon from './icon'; export default { keys: ['entity', 'entities'], + Icon, matcher: /\.entity\.json$/, Component: EntityComponent, // eslint-disable-next-line global-require diff --git a/src/common/resources/entity/icon.jsx b/src/common/resources/entity/icon.jsx new file mode 100644 index 0000000..28f5f8f --- /dev/null +++ b/src/common/resources/entity/icon.jsx @@ -0,0 +1,13 @@ +import React from 'react'; + +export default () => ( + + + +);