Skip to content

Commit

Permalink
Merge pull request #683 from 3DStreet/cards-img
Browse files Browse the repository at this point in the history
use catalog.json for additional asset metadata
  • Loading branch information
kfarr authored Jul 3, 2024
2 parents 5bb78de + 176ee09 commit 0bac4fe
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/catalog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"id": "Bicycle_1",
"name": "Bicycle Model 1",
"img": "ui_assets/cards/models/bicycle_1.jpg"
},
{
"id": "bus",
"name": "Bus New Flyer XD40",
"description": "The New Flyer XD40 is a modern, stylish, and comfortable bus that is perfect for people in urban settings."
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import CardPlaceholder from '../../../../../ui_assets/card-placeholder.svg';
import LockedCard from '../../../../../ui_assets/locked-card.svg';

import { LayersOptions } from './LayersOptions.js';
import mixinCatalog from '../../../../catalog.json';
import posthog from 'posthog-js';

import {
Expand Down Expand Up @@ -41,23 +42,43 @@ const AddLayerPanel = ({ onClose, isAddLayerPanelOpen }) => {
const groupedArray = [];
let categoryName, mixinId;

// convert the mixins array into an object with mixins for faster access by index
const mixinCatalogObj = mixinCatalog.reduce((obj, item) => {
obj[item.id] = item;
return obj;
}, {});

const groupedObject = {};
let index = 0;
for (const mixinEl of mixinElements) {
categoryName = mixinEl.getAttribute('category');
if (!categoryName) continue;
mixinId = mixinEl.id;

if (!groupedObject[categoryName]) {
groupedObject[categoryName] = [];
}
groupedObject[categoryName].push({
// get mixin data from mixin catalog and push it to object with grouped mixins
mixinId = mixinEl.id;
const mixinDataFromCatalog = mixinCatalogObj[mixinId];
let mixinImg = '';
let mixinName = '';
let mixinDescr = '';

if (mixinDataFromCatalog) {
mixinImg = mixinDataFromCatalog.img;
mixinName = mixinDataFromCatalog.name;
mixinDescr = mixinDataFromCatalog.description;
}
const mixinData = {
// here could be data from dataCards JSON file
img: '',
img: mixinImg,
icon: '',
mixinId: mixinId,
name: mixinId,
name: mixinName || mixinId,
description: mixinDescr,
id: index
});
};
groupedObject[categoryName].push(mixinData);
index += 1;
}

Expand Down
6 changes: 3 additions & 3 deletions src/editor/components/components/AddLayerPanel/cardsData.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const mixinsData = {
mixinId1: {
img: '',
bicycle_1: {
img: 'ui_assets/cards/models/bicycle_1.jpg',
icon: '',
description: 'Description',
description: "Bicycle, it's a bike!",
id: 1
},
mixinId2: {
Expand Down
Binary file added ui_assets/cards/models/bicycle_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0bac4fe

Please sign in to comment.