Skip to content

Commit

Permalink
😒: Some Features added
Browse files Browse the repository at this point in the history
  • Loading branch information
m7medVision committed Jan 11, 2024
1 parent def59d4 commit 384c294
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 18 deletions.
6 changes: 4 additions & 2 deletions components/EditorSplit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Editor from "../islands/Editor.tsx";
import { getTestCase } from "../utils/testcase.ts";

export default function EditorSplit() {
// const
export default function EditorSplit(props: { slug: string }) {
const testcases = getTestCase(props.slug);
return (
<>
<div class="mt-2">
Expand All @@ -22,6 +23,7 @@ export default function EditorSplit() {
</div>
<Editor
preCode={'console.log("Hello World!")'}
testcases={testcases}
/>
</>
);
Expand Down
29 changes: 18 additions & 11 deletions islands/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { useToast } from "./useToast.ts";

interface CounterProps {
preCode: string;
testcases?:
| { regex?: string | undefined; output?: string | undefined }[]
| undefined;
}

declare var window: Window & typeof globalThis;
Expand Down Expand Up @@ -30,8 +33,10 @@ export default function Editor(props: CounterProps) {
setOutput("");
}
function handleCodeTest() {
handleCodeRun();
const code: string | undefined = window.editor.getValue();
showToast({
msg: "هذه الخاصية غير متوفرة حالياً",
type: "warning",
});
}

function handleCodeRun() {
Expand All @@ -40,18 +45,20 @@ export default function Editor(props: CounterProps) {
const capturedOutput: string[] = [];
const originalConsoleLog = console.log;
console.log = (...args: any[]) => {
capturedOutput.push(args.map((arg) => {
if (typeof arg === 'object' && arg !== null) {
return JSON.stringify(arg);
}
return arg.toString();
}).join(" "));
capturedOutput.push(
args.map((arg) => {
if (typeof arg === "object" && arg !== null) {
return JSON.stringify(arg);
}
return arg.toString();
}).join(" "),
);
originalConsoleLog(...args);
};
if (code) {
eval(code);
}
setOutput(capturedOutput.join('\n'));
setOutput(capturedOutput.join("\n"));

console.log = originalConsoleLog;
} catch (error) {
Expand All @@ -75,12 +82,12 @@ export default function Editor(props: CounterProps) {
>
مسح
</button>
{/* <button
<button
class="btn btn-error grow"
onClick={handleCodeTest}
>
اختبار
</button> */}
</button>
</div>
<div class="bg-base-300 h-full grow mt-2 mx-2 overflow-y-scroll rounded-lg pb-36">
<pre className=" bg-base-300 overflow-y-hidden p-4">
Expand Down
24 changes: 21 additions & 3 deletions islands/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,27 @@ export default function Toast() {
<span>{ToastSignal.value.message}</span>
</div>
) : (
<div class="alert alert-error">
<span>{ToastSignal.value.message}</span>\
</div>
ToastSignal.value.type === "error" ? (
<div class="alert alert-error">
<span>{ToastSignal.value.message}</span>
</div>
) : (
ToastSignal.value.type === "warning" ? (
<div class="alert alert-warning">
<span>{ToastSignal.value.message}</span>
</div>
) : (
ToastSignal.value.type === "info" ? (
<div class="alert alert-info">
<span>{ToastSignal.value.message}</span>
</div>
) : (
<div class="alert">
<span>{ToastSignal.value.message}</span>
</div>
)
)
)
)
}
</div>
Expand Down
2 changes: 1 addition & 1 deletion islands/useToast.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ToastSignal } from "./signals/store.ts";
export function useToast() {
function showToast(msg: string, type: "success" | "error" = "success") {
function showToast({ msg, type = "success" }: { msg: string; type?: "success" | "error" | "warning" | "info" }) {
ToastSignal.value = { show: true, message: msg, type: type };
setTimeout(() => {
ToastSignal.value = { show: false, message: "", type: "success" };
Expand Down
2 changes: 1 addition & 1 deletion routes/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default function CoursePage(
<main>
<div dir="ltr" class="split flex-grow h-full-minus-bar">
<div id="split-0" class="flex flex-col">
<EditorSplit />
<EditorSplit slug={course.slug} />
</div>
<div id="split-1" class="overflow-y-scroll">
<MarkdownSplit course={course} lable={lable} />
Expand Down
4 changes: 4 additions & 0 deletions utils/testcase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export function getTestCase(slug: string): { regex?: string | undefined; output?
return [
{
regex: '.*',

},
{
output: '200',
}
]
}

0 comments on commit 384c294

Please sign in to comment.