-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
189 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// TODO: implent the transformData function that takes in an array of RawDataEntry objects and from manf and returns structured json for backend endpoint. | ||
// Define the structure of a color entry | ||
interface ColorEntry { | ||
color: string; | ||
hexColor: string; | ||
colorTag: string; | ||
} | ||
|
||
// Define the raw data structure | ||
interface RawDataEntry { | ||
filament: string; | ||
hexColor: string; | ||
colorTag: string; | ||
} | ||
|
||
// Define the structure of the transformed output | ||
interface TransformedData { | ||
[key: string]: ColorEntry[]; | ||
} | ||
|
||
export const rawData: RawDataEntry[] = [ | ||
{ filament: "PETG WHITE", hexColor: "f6efef", colorTag: "petgWhite" }, | ||
{ filament: "PETG BLACK", hexColor: "000000", colorTag: "petgBlack" }, | ||
{ filament: "PLA BLACK", hexColor: "000000", colorTag: "black" }, | ||
{ filament: "PLA GRAY", hexColor: "666666", colorTag: "gray" }, | ||
{ filament: "PLA WHITE", hexColor: "ffffff", colorTag: "white" }, | ||
{ filament: "PLA YELLOW", hexColor: "f5c211", colorTag: "yellow" }, | ||
{ filament: "PLA RED", hexColor: "f91010", colorTag: "red" }, | ||
{ filament: "PLA GOLD", hexColor: "d5b510", colorTag: "gold" }, | ||
{ filament: "PLA LUNAR REGOLITH", hexColor: "7d7e7e", colorTag: "lunarRegolith" }, | ||
{ filament: "PLA MATTE BLACK", hexColor: "000000", colorTag: "matteBlack" } | ||
]; | ||
|
||
export const transformData = (data: RawDataEntry[]): TransformedData[] => { | ||
const filamentMap: TransformedData = {}; | ||
|
||
data.forEach((item) => { | ||
const [type, color] = item.filament.split(' '); // Split filament into type and color | ||
|
||
const colorEntry: ColorEntry = { | ||
color: color.toUpperCase(), // Capitalize color name | ||
hexColor: item.hexColor, | ||
colorTag: item.colorTag, | ||
}; | ||
|
||
// If the filament type doesn't exist, initialize it | ||
if (!filamentMap[type]) { | ||
filamentMap[type] = []; | ||
} | ||
|
||
console.log(filamentMap); | ||
// Push the color entry to the corresponding filament type | ||
filamentMap[type].push(colorEntry); | ||
}); | ||
|
||
// Convert the map into an array of objects, sorted by PLA first, PETG second | ||
return Object.entries(filamentMap) | ||
.sort(([keyA], [keyB]) => { | ||
if (keyA === 'PLA') return -1; | ||
if (keyB === 'PLA') return 1; | ||
return keyA.localeCompare(keyB); // Sort alphabetically otherwise | ||
}) | ||
.map(([filamentType, colors]) => ({ | ||
[filamentType]: colors, | ||
})); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { create } from 'zustand'; | ||
import { ColorsResponse } from '../interfaces'; | ||
|
||
interface ColorState { | ||
// State | ||
colorOptions: ColorsResponse[]; | ||
color: string; | ||
isLoading: boolean; | ||
|
||
// Actions | ||
setColorOptions: (colorOptions: ColorsResponse[]) => void; | ||
setColor: (color: string) => void; | ||
setIsLoading: (isLoading: boolean) => void; | ||
|
||
} | ||
|
||
export const useColorStore = create<ColorState>((set) => ({ | ||
// State | ||
colorOptions: [], | ||
color: '000000', | ||
isLoading: false, | ||
|
||
// Actions | ||
setColorOptions: (colorOptions: ColorsResponse[]) => set({ colorOptions }), | ||
setColor: (color: string) => set({ color }), | ||
setIsLoading: (isLoading: boolean) => set({ isLoading }), | ||
})); |