Skip to content

Commit

Permalink
refactor: move libraries and fonts to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
seasick committed Jan 30, 2024
1 parent 3e1b432 commit e1a709d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 44 deletions.
33 changes: 12 additions & 21 deletions src/components/Workspace/Fonts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,10 @@ import ListItemText from '@mui/material/ListItemText';
import { BlobReader, Uint8ArrayWriter, ZipReader } from '@zip.js/zip.js';
import React from 'react';

import commonFonts from '../../etc/fonts.json';
import FileWithPath from '../../lib/FileWithPath';
import { useFileSystemProvider } from '../FileSystemProvider';

const commonLibraries = [
{
name: 'Liberation Fonts',
description:
'The Liberation Fonts is font collection which aims to provide document layout compatibility as usage of Times New Roman, Arial, Courier New.',
url: 'https://github.com/shantigilbert/liberation-fonts-ttf/archive/refs/heads/master.zip',
startPath: 'liberation-fonts-ttf-master/',
},
];

export default function Fonts() {
const { writeFiles } = useFileSystemProvider();
const [isLoading, setLoading] = React.useState({});
Expand All @@ -39,7 +30,7 @@ export default function Fonts() {
const zip = await response.blob();
const files = await new ZipReader(new BlobReader(zip)).getEntries();

// Libraries should go into the library folder
// Fonts should go into the font folder
const movedFiles = await Promise.all(
files
.filter((f) => f.directory === false)
Expand All @@ -62,31 +53,31 @@ export default function Fonts() {
setLoading({ ...isLoading, [url]: false });
};

const libraryIsAlreadyDownloaded = (lib) => {
const fontIsAlreadyDownloaded = (lib) => {
return isAvailable[lib.url];
};

return (
<>
<Alert severity="info">
<AlertTitle>Libraries</AlertTitle>
Select which common libraries to include in your project.
Select which common font to include in your project.
</Alert>
<List>
{commonLibraries.map((lib) => (
{commonFonts.map((font) => (
<ListItem
key={lib.name}
key={font.name}
secondaryAction={
isAvailable && (
<IconButton
edge="end"
aria-label="download library"
aria-label="download font"
onClick={handleDownload}
disabled={libraryIsAlreadyDownloaded(lib)}
data-url={lib.url}
data-start-path={lib.startPath}
disabled={fontIsAlreadyDownloaded(font)}
data-url={font.url}
data-start-path={font.startPath}
>
{isLoading[lib.url] ? (
{isLoading[font.url] ? (
<LoopIcon sx={{ animation: 'spin 2s linear infinite' }} />
) : (
<DownloadIcon />
Expand All @@ -95,7 +86,7 @@ export default function Fonts() {
)
}
>
<ListItemText primary={lib.name} secondary={lib.description} />
<ListItemText primary={font.name} secondary={font.description} />
</ListItem>
))}
</List>
Expand Down
23 changes: 1 addition & 22 deletions src/components/Workspace/Libraries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,10 @@ import ListItemText from '@mui/material/ListItemText';
import { BlobReader, Uint8ArrayWriter, ZipReader } from '@zip.js/zip.js';
import React from 'react';

import commonLibraries from '../../etc/libraries.json';
import FileWithPath from '../../lib/FileWithPath';
import { useFileSystemProvider } from '../FileSystemProvider';

const commonLibraries = [
{
name: 'BOSL2',
description: 'A library for OpenSCAD that includes a number of utilities.',
url: 'https://github.com/BelfrySCAD/BOSL2/archive/refs/heads/master.zip',
startPath: 'BOSL2-master',
},
{
name: 'BOSL',
description: 'A library for OpenSCAD that includes a number of utilities.',
url: 'https://github.com/revarbat/BOSL/archive/refs/tags/v1.0.3.zip',
startPath: 'BOSL-1.0.3',
},
{
name: 'Round-Anything',
description:
'A set of OpenSCAD utilities for adding radii and fillets, that embodies a robust approach to developing OpenSCAD parts.',
url: 'https://github.com/Irev-Dev/Round-Anything/archive/refs/tags/1.0.4.zip',
startPath: 'Round-Anything-1.0.4',
},
];

export default function Libraries() {
const { writeFiles } = useFileSystemProvider();
const [isLoading, setLoading] = React.useState({});
Expand Down
8 changes: 8 additions & 0 deletions src/etc/fonts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"name": "Liberation Fonts",
"description": "The Liberation Fonts is font collection which aims to provide document layout compatibility as usage of Times New Roman, Arial, Courier New.",
"url": "https://github.com/shantigilbert/liberation-fonts-ttf/archive/refs/heads/master.zip",
"startPath": "liberation-fonts-ttf-master/"
}
]
20 changes: 20 additions & 0 deletions src/etc/libraries.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"name": "BOSL2",
"description": "A library for OpenSCAD that includes a number of utilities.",
"url": "https://github.com/BelfrySCAD/BOSL2/archive/refs/heads/master.zip",
"startPath": "BOSL2-master"
},
{
"name": "BOSL",
"description": "A library for OpenSCAD that includes a number of utilities.",
"url": "https://github.com/revarbat/BOSL/archive/refs/tags/v1.0.3.zip",
"startPath": "BOSL-1.0.3"
},
{
"name": "Round-Anything",
"description": "A set of OpenSCAD utilities for adding radii and fillets, that embodies a robust approach to developing OpenSCAD parts.",
"url": "https://github.com/Irev-Dev/Round-Anything/archive/refs/tags/1.0.4.zip",
"startPath": "Round-Anything-1.0.4"
}
]
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"jsx": "react",
"esModuleInterop": true
"esModuleInterop": true,
"resolveJsonModule": true,
},
"exclude": [
"**/*.spec.ts",
Expand Down

0 comments on commit e1a709d

Please sign in to comment.