Skip to content

Commit

Permalink
Update patterns page
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottkember committed Mar 9, 2021
1 parent b947b75 commit a382bba
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 18 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
"dependencies": {
"@sentry/electron": "^2.0.1",
"@serialport/bindings": "9.0.2",
"account-realm-client": "^1.2.2",
"bonjour": "^3.5.0",
"electron-auth0-login": "^1.3.1",
"electron-context-menu": "^2.0.1",
"electron-is-dev": "^1.2.0",
"electron-log": "^4.3.0",
"electron-root-path": "^1.0.16",
"electron-updater": "^4.3.8",
"react-use": "^17.1.1",
"react-user": "^0.1.4",
"serialport": "9.0.2"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions src/index.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ body .monaco-editor .view-lines {
.button {
@apply cursor-pointer inline-flex items-center px-6 py-2 border border-transparent text-base leading-6 font-medium rounded-md text-white bg-purple-600 focus:outline-none focus:border-purple-700 focus:shadow-outline-purple active:bg-purple-700 transition ease-in-out duration-150 justify-center;
}

.button-small {
@apply cursor-pointer inline-flex items-center px-2.5 py-1.5 border border-transparent text-xs font-medium rounded shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500;
}
}

.app-border {
Expand Down
12 changes: 12 additions & 0 deletions src/main/components/Menu/SoulmateSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ const SoulmatesSection = () => {
</NavLink>
)}

{!needsSetup && (
<NavLink
activeClassName={activeLinkClass}
className={linkClass}
location={location}
to="/soulmate"
>
<HiOutlineLightningBolt className={iconClass} />
Edit Patterns
</NavLink>
)}

{isElectron() && (
<>
{!needsSetup && usbConnected && (
Expand Down
8 changes: 3 additions & 5 deletions src/main/hooks/useSwr.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ export const fetcher = async (url) => {
return fetch(url, { ...headers }).then((d) => d.json());
};

const useRequest = (path) => {
if (!path) throw new Error("Path is required");

const useRequest = (path, fetchFunction = fetcher) => {
const { appServer } = NetworkContainer.useContainer();
const url = normalizeUrl(appServer + "/" + path);
return useSwr(url, fetcher);
const url = path ? normalizeUrl(appServer + "/" + path) : path;
return useSwr(url, fetchFunction);
};

export default useRequest;
5 changes: 5 additions & 0 deletions src/main/ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import NewPlaylist from "./newPlaylist";
import Playlist from "./playlist";
import Playlists from "./playlists";
import Settings from "./Settings";
import SoulmateEditor from "./soulmateEditor";
import Tutorial from "./tutorial";
import User from "./user";

Expand Down Expand Up @@ -145,6 +146,10 @@ const IDE = () => {
{isElectron() ? <Flash /> : <Download />}
</Route>

<Route exact path="/soulmate">
<SoulmateEditor />
</Route>

<Route exact path="/config">
<Config />
</Route>
Expand Down
5 changes: 2 additions & 3 deletions src/main/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ const Playlist = (props) => {
const sketch = sketches ? sketches[index] : {};
const { config } = playlist || {};

let build;
const code = playlist?.sketches[index]?.code || emptyCode;
build = useBuild(code, config);
const build = useBuild(code, config);

const save = () => {
savePlaylist(playlist.id, { sketches });
Expand Down Expand Up @@ -254,7 +253,7 @@ const Playlist = (props) => {
<Simulator
build={build}
className="flex flex-col flex-grow"
config={config}
config={config || {}}
hideResolutionMenu
minWidth={400}
/>
Expand Down
114 changes: 105 additions & 9 deletions src/main/soulmateEditor.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,113 @@
import { useSWR } from "~/hooks/useSWR";
import { useStateList } from "react-use";

const SoulmateEditor = ({ selectedSoulmate }) => {
const buildId = selectedSoulmate.build;
const data = useSWR(`https://editor.soulmatelights.com/build/${buildId}`);
import CodeEditor from "~/components/codeEditor";
import Header from "~/components/Header";
import Simulator from "~/components/Simulator";
import SoulmatesContainer from "~/containers/soulmates";
import useBuild from "~/hooks/useBuild";
import useSWR from "~/hooks/useSwr";
import Logo from "~/images/logo.svg";
import { emptyCode } from "~/utils/code";

const { sketches = [], config = {} } = data;
import soulmateName from "./utils/soulmateName";

const SoulmateEditor = () => {
const { selectedSoulmate } = SoulmatesContainer.useContainer();

const buildId = selectedSoulmate?.config?.build;

const { data } = useSWR(buildId ? `builds/${buildId}` : null, (url) =>
fetch(url).then((d) => d.json())
);

const [sketches, setSketches] = useState([]);

useEffect(() => {
setSketches(data?.sketches || []);
}, [data?.sketches, selectedSoulmate]);

const {
state: sketch,
setState: setSelectedSketch,
currentIndex: selectedSketchIndex,
} = useStateList(data?.sketches);

const code = sketch?.code;
const { config = {} } = selectedSoulmate || {};
const build = useBuild(code, config);

if (!selectedSoulmate) return null;

return (
<div>
<div>{sketches.map((s) => s.name)}</div>
{JSON.stringify(config)}
<div className="flex flex-col flex-grow flex-shrink h-full min-w-0">
<Header
actions={[{ title: "Save changes" }]}
title={<>{soulmateName(selectedSoulmate)}</>}
/>
<div className="flex flex-row flex-shrink-0 w-full pl-4 overflow-auto text-gray-800 bg-gray-700 border-r border-gray-200 w-72 dark-mode:border-gray-700">
<div className="flex flex-row pt-4">
{sketches.map((s, index) => (
<a
className={classnames(
"px-4 py-2 ml-1 rounded-tl rounded-tr cursor-pointer",
{
"bg-white": index === selectedSketchIndex,
"text-white": index !== selectedSketchIndex,
}
)}
key={s.name}
onClick={() => setSelectedSketch(s)}
>
{s.name}
</a>
))}
</div>

<div className="flex flex-col justify-center ml-auto mr-8">
<div className=" text-white button-small">Add from gallery</div>
</div>
</div>
<div className="flex flex-row flex-grow flex-shrink h-full">
<div className="flex flex-row flex-grow flex-shrink min-w-0 min-h-0">
{sketch && (
<>
<CodeEditor
build={build}
className="relative flex-grow flex-shrink w-6/12 min-w-0 min-h-0 bg-white"
code={sketch?.code || emptyCode}
key={selectedSketchIndex}
onChange={(_code) => {
// sketches[index].code = code;
// setSketches(sketches);
// setDirty(true);
}}
onSave={(_code) => {
// setDirty(false);
// sketches[index].code = code;
// setSketches(sketches);
// savePlaylist(playlist.id, { sketches });
}}
/>

<Simulator
build={build}
className="flex flex-col flex-grow"
config={config}
hideResolutionMenu
minWidth={400}
/>
</>
)}
</div>
</div>
</div>
);
};

export default SoulmateEditor;
const SoulmateEditorWrapper = () => {
const { selectedSoulmate } = SoulmatesContainer.useContainer();
if (!selectedSoulmate?.config) return <Logo className="loading-spinner" />;
return <SoulmateEditor />;
};

export default SoulmateEditorWrapper;
Loading

0 comments on commit a382bba

Please sign in to comment.