Skip to content

Commit

Permalink
chore: format ts(x) code
Browse files Browse the repository at this point in the history
  • Loading branch information
bchmnn committed Jul 17, 2024
1 parent f1bc43c commit 6057b2f
Show file tree
Hide file tree
Showing 46 changed files with 848 additions and 690 deletions.
1 change: 0 additions & 1 deletion checker/src/checker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import string
import random
import secrets
import re
from logging import LoggerAdapter

Expand Down
6 changes: 3 additions & 3 deletions service/frontend/src/actions/navigate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use server'
"use server";

import { redirect } from 'next/navigation'
import { redirect } from "next/navigation";

export async function navigate(path: string) {
redirect(path)
redirect(path);
}
56 changes: 38 additions & 18 deletions service/frontend/src/app/devenv/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,71 @@

import dynamic from "next/dynamic";
import FileTree from "@/components/file-tree";
import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/components/ui/resizable";
import {
ResizableHandle,
ResizablePanel,
ResizablePanelGroup,
} from "@/components/ui/resizable";
import { useEffect, useState } from "react";
import ExecTerm from "@/components/exec-term";
import { useDevenvGeneration } from "@/hooks/use-devenv-generation";
import { useDevenvGenerationMutation } from "@/hooks/use-devenv-generation-mutation";

const Editor = dynamic(() => import('@/components/editor'), {
ssr: false
})
const Editor = dynamic(() => import("@/components/editor"), {
ssr: false,
});

export default function Page({ params }: { params: { slug: string } }) {
const [currentFile, setCurrentFile] = useState<string>();

const devenvGenerationMutation = useDevenvGenerationMutation({ uuid: params.slug })
const generation = useDevenvGeneration({ uuid: params.slug })
const devenvGenerationMutation = useDevenvGenerationMutation({
uuid: params.slug,
});
const generation = useDevenvGeneration({ uuid: params.slug });

useEffect(() => {
return () => {
devenvGenerationMutation.mutate(null)
}
}, [])
devenvGenerationMutation.mutate(null);
};
}, []);

return (
<main className="h-screen w-screen pt-16">
<ResizablePanelGroup direction="horizontal">
<ResizablePanel id="file-tree-panel" defaultSize={15}>
<div className="flex flex-col w-full h-full p-4 space-y-5">
<FileTree className="flex flex-col w-full h-full space-y-5" devenvUuid={params.slug} selectedFile={currentFile} setSelectedFile={setCurrentFile} />
<FileTree
className="flex flex-col w-full h-full space-y-5"
devenvUuid={params.slug}
selectedFile={currentFile}
setSelectedFile={setCurrentFile}
/>
</div>
</ResizablePanel>
<ResizableHandle />
<ResizablePanel defaultSize={85}>
<ResizablePanelGroup direction="vertical">
<ResizablePanel id="editor-panel">
<Editor className="w-full h-full" devenvUuid={params.slug} filename={currentFile} />
<Editor
className="w-full h-full"
devenvUuid={params.slug}
filename={currentFile}
/>
</ResizablePanel>
{Boolean(generation) && <>
<ResizableHandle />
<ResizablePanel id="terminal-panel">
<ExecTerm className="w-full h-full" id={String(generation)} path={"/api/devenv/" + params.slug + "/exec"} />
</ResizablePanel>
</>}
{Boolean(generation) && (
<>
<ResizableHandle />
<ResizablePanel id="terminal-panel">
<ExecTerm
className="w-full h-full"
id={String(generation)}
path={"/api/devenv/" + params.slug + "/exec"}
/>
</ResizablePanel>
</>
)}
</ResizablePanelGroup>
</ResizablePanel>

</ResizablePanelGroup>
</main>
);
Expand Down
6 changes: 3 additions & 3 deletions service/frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import "./globals.css";
import "@xterm/xterm/css/xterm.css";

import type { Metadata } from "next";
import { ThemeProvider } from "@/components/theme-provider"
import { ThemeProvider } from "@/components/theme-provider";
import Navbar from "@/components/navigation-bar";
import localFont from 'next/font/local';
import localFont from "next/font/local";
import ReactQueryProvider from "@/components/react-query-provider";

const dejaVuFont = localFont({ src: './DejaVuSansMNerdFontMono-Regular.ttf' })
const dejaVuFont = localFont({ src: "./DejaVuSansMNerdFontMono-Regular.ttf" });

export const metadata: Metadata = {
title: "replme",
Expand Down
26 changes: 16 additions & 10 deletions service/frontend/src/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { Button } from "@/components/ui/button";
import { z } from "zod";
import { Form, FormControl, FormField, FormItem, FormMessage } from "@/components/ui/form";
import {
Form,
FormControl,
FormField,
FormItem,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { useLoginMutation } from "@/hooks/use-login-mutation";

const LoginFormSchema = z.object({
username: z.string().min(1, { message: "Username can't be empty" }),
password: z.string().min(1, { message: "Password can't be empty" })
})
password: z.string().min(1, { message: "Password can't be empty" }),
});

type LoginForm = z.infer<typeof LoginFormSchema>;

Expand All @@ -21,20 +27,20 @@ export default function Page() {
defaultValues: {
username: "",
password: "",
}
})
},
});

const loginMutation = useLoginMutation({
onError: () => {
form.setError("password", {
message: "Password is wrong"
})
}
})
message: "Password is wrong",
});
},
});

const onSubmit = (credentials: LoginForm) => {
loginMutation.mutate(credentials);
}
};

return (
<main className="flex h-screen w-screen flex-col items-center p-24 justify-center space-y-5">
Expand Down
18 changes: 10 additions & 8 deletions service/frontend/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@ import CreateDevenvButton from "@/components/create-devenv-button";
import CreateReplButton from "@/components/create-repl-button";
import { Button } from "@/components/ui/button";
import { useUserQuery } from "@/hooks/use-user-query";
import { RocketIcon } from "@radix-ui/react-icons"
import { RocketIcon } from "@radix-ui/react-icons";

export default function Page() {
const userQuery = useUserQuery()
const isAuthenticatedMode = !userQuery.isStale && userQuery.isSuccess
const userQuery = useUserQuery();
const isAuthenticatedMode = !userQuery.isStale && userQuery.isSuccess;

return (
<main className="flex h-screen w-screen flex-col items-center p-24 justify-center space-y-5">
<div className="text-2xl italic">Want a clean /home?</div>
<div className="text-5xl font-bold">Use replme!</div>
<div>
Hack together your ideas in development environments,
use a throwaway shell - all in one place.
Hack together your ideas in development environments, use a throwaway
shell - all in one place.
</div>
<div className="flex flex-row space-x-3 items-center">
{isAuthenticatedMode ?
<CreateDevenvButton /> :
{isAuthenticatedMode ? (
<CreateDevenvButton />
) : (
<a href="/register">
<Button>
<RocketIcon className="mr-2 h-4 w-4" /> REGISTER!
</Button>
</a>}
</a>
)}
<CreateReplButton />
</div>
</main>
Expand Down
36 changes: 24 additions & 12 deletions service/frontend/src/app/register/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,50 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { Button } from "@/components/ui/button";
import { z } from "zod";
import { Form, FormControl, FormField, FormItem, FormMessage } from "@/components/ui/form";
import {
Form,
FormControl,
FormField,
FormItem,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { useRegisterMutation } from "@/hooks/use-register-mutation";

const RegisterFormSchema = z.object({
username: z.string().min(4, { message: "Minimum length 4" }).max(64, { message: "Maximum length 4" }).regex(/^[a-zA-Z0-9]*$/, { message: "Only alphanumeric" }),
password: z.string().min(4, { message: "Minimum length 4" }).max(64, { message: "Maximum length 4" })
})
username: z
.string()
.min(4, { message: "Minimum length 4" })
.max(64, { message: "Maximum length 4" })
.regex(/^[a-zA-Z0-9]*$/, { message: "Only alphanumeric" }),
password: z
.string()
.min(4, { message: "Minimum length 4" })
.max(64, { message: "Maximum length 4" }),
});

type RegisterForm = z.infer<typeof RegisterFormSchema>;

export default function Page() {

const form = useForm<RegisterForm>({
resolver: zodResolver(RegisterFormSchema),
defaultValues: {
username: "",
password: "",
}
})
},
});

const mutation = useRegisterMutation({
onError: () => {
form.setError("username", {
message: "That did not work, user exists?"
})
}
})
message: "That did not work, user exists?",
});
},
});

const onSubmit = (credentials: RegisterForm) => {
mutation.mutate(credentials);
}
};

return (
<main className="flex h-screen w-screen flex-col items-center p-24 justify-center space-y-5">
Expand Down
19 changes: 12 additions & 7 deletions service/frontend/src/app/repl/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
"use client";

import dynamic from 'next/dynamic'
import dynamic from "next/dynamic";

const Terminal = dynamic(() => import('@/components/terminal'), {
ssr: false
})
const Terminal = dynamic(() => import("@/components/terminal"), {
ssr: false,
});

export default function Page({ params }: { params: { slug: string } }) {
return (
<main className="w-screen h-screen pt-16 px-2 pb-2" >
<Terminal id="terminal" path={"/api/repl/" + params.slug} catchClose={true} className="w-full h-full" />
<main className="w-screen h-screen pt-16 px-2 pb-2">
<Terminal
id="terminal"
path={"/api/repl/" + params.slug}
catchClose={true}
className="w-full h-full"
/>
</main>
)
);
}
32 changes: 21 additions & 11 deletions service/frontend/src/components/create-devenv-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,36 @@ const CreateDevenvButton = React.forwardRef<HTMLButtonElement, ButtonProps>(
(props, ref) => {
const createDevenvMutation = useCreateDevenvMutation();

const handleCreateDevenv = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
const handleCreateDevenv = (
event: React.MouseEvent<HTMLButtonElement, MouseEvent>,
) => {
const name = randomString(10);
createDevenvMutation.mutate({
name,
buildCmd: "gcc -o main main.c",
runCmd: "./main"
runCmd: "./main",
});
if (props.onClick) props.onClick(event)
}
if (props.onClick) props.onClick(event);
};

return (
<Button ref={ref} {...props} disabled={createDevenvMutation.isPending} onClick={handleCreateDevenv}>
{createDevenvMutation.isPending ? <ReloadIcon className="mr-2 h-4 w-4 animate-spin" /> :
<CodeIcon className="mr-2 h-4 w-4" />} DEVENVME!
<Button
ref={ref}
{...props}
disabled={createDevenvMutation.isPending}
onClick={handleCreateDevenv}
>
{createDevenvMutation.isPending ? (
<ReloadIcon className="mr-2 h-4 w-4 animate-spin" />
) : (
<CodeIcon className="mr-2 h-4 w-4" />
)}{" "}
DEVENVME!
</Button>
)
}
)
);
},
);

CreateDevenvButton.displayName = "CreateDevenvButton";

export default CreateDevenvButton;

Loading

0 comments on commit 6057b2f

Please sign in to comment.