Skip to content

Commit

Permalink
chore: fix file handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lajbel committed Oct 15, 2024
1 parent 8713d95 commit 010b8a1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/components/Editor/MonacoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import { configMonaco } from "./monacoConfig";

type Props = {
onMount?: () => void;
defaultTheme?: string;
};

const defaultTheme = localStorage.getItem("theme") as string;

export const MonacoEditor: FC<Props> = (props) => {
const { updateFile, getFile } = useProject();
const {
Expand Down Expand Up @@ -101,7 +100,7 @@ export const MonacoEditor: FC<Props> = (props) => {
defaultValue={getFile(getRuntime().currentFile)?.value}
beforeMount={handleEditorBeforeMount}
onMount={handleEditorMount}
theme={defaultTheme}
theme={props.defaultTheme}
language="javascript"
options={{
fontSize: 20,
Expand Down
8 changes: 7 additions & 1 deletion src/components/FileTree/FileEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { cn } from "../../util/cn";
import { removeExtension } from "../../util/removeExtensions";
import "./FileEntry.css";
import { useEditor } from "../../hooks/useEditor";
import { debug } from "../../util/logs";

type Props = {
file: File;
Expand All @@ -23,11 +22,13 @@ const FileButton: FC<{
onClick: MouseEventHandler;
icon: keyof typeof assets;
rotate?: 0 | 90 | 180 | 270;
hidden?: boolean;
}> = (props) => {
return (
<button
className="btn btn-ghost btn-xs rounded-sm px-1"
onClick={props.onClick}
hidden={props.hidden}
>
<img
src={assets[props.icon].outlined}
Expand Down Expand Up @@ -135,6 +136,11 @@ export const FileEntry: FC<Props> = ({ file }) => {
icon="arrow"
rotate={270}
/>
<FileButton
onClick={handleMoveDown}
icon="arrow"
rotate={90}
/>
</div>
<img
src={logoByKind[file.kind]}
Expand Down
14 changes: 11 additions & 3 deletions src/components/FileTree/FileFold.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { assets } from "@kaplayjs/crew";
import { type FC, type PropsWithChildren, useMemo, useState } from "react";
import {
type FC,
type PropsWithChildren,
useEffect,
useMemo,
useState,
} from "react";
import { cn } from "../../util/cn";
import { FileToolbar } from "./FileToolbar";
import "./FileFolder.css";
Expand All @@ -25,8 +31,10 @@ const paddingLevels = {

export const FileFold: FC<Props> = (props) => {
const [folded, setFolded] = useState(false);
const { getFilesByFolder } = useProject();
const files = useMemo(() => getFilesByFolder(props.folder), [props.folder]);
const { getFilesByFolder, project } = useProject();
const files = useMemo(() => getFilesByFolder(props.folder), [
project.files.values(),
]);

return (
<div className="mb-2">
Expand Down
11 changes: 10 additions & 1 deletion src/components/Playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const Playground = () => {
} = useProject();
const [loadingProject, setLoadingProject] = useState<boolean>(true);
const [loadingEditor, setLoadingEditor] = useState<boolean>(true);
const [defaultTheme, setDefaultTheme] = useState<string | null>(null);
const isPortrait = useMediaQuery({ query: "(orientation: portrait)" });

const handleMount = () => {
Expand All @@ -29,9 +30,17 @@ const Playground = () => {
// First useEffect
useEffect(() => {
const defaultTheme = localStorage.getItem("theme") as string;
const browserPrefersDark = window.matchMedia(
"(prefers-color-scheme: dark)",
).matches;

document.documentElement.setAttribute(
"data-theme",
defaultTheme || "Ghostiny",
defaultTheme || (browserPrefersDark ? "Spiker" : "Ghostiny"),
);

setDefaultTheme(
defaultTheme || (browserPrefersDark ? "Spiker" : "Ghostiny"),
);
}, []);

Expand Down

0 comments on commit 010b8a1

Please sign in to comment.