Skip to content

Commit

Permalink
❇: Added progress system
Browse files Browse the repository at this point in the history
  • Loading branch information
TeaByte committed Jan 12, 2024
1 parent 80b4eb3 commit c03bb50
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
5 changes: 2 additions & 3 deletions components/CourseCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Course } from "../utils/types.ts";

import IconCircle from "https://deno.land/x/tabler_icons_tsx@0.0.5/tsx/circle.tsx";
// import IconcircleCheck from "https://deno.land/x/tabler_icons_tsx@0.0.5/tsx/circle-check.tsx";
import ProgressCheck from "../islands/ProgressCheck.tsx";

export default function CourseCard(props: { course: Course }) {
const { course } = props;
Expand All @@ -13,7 +12,7 @@ export default function CourseCard(props: { course: Course }) {
style={{ order: course.order }}
>
<h3 class="text-gray-500 font-bold flex gap-1 items-center">
<IconCircle aria-hidden="true" class="h-4 w-4" />
<ProgressCheck slug={course.slug} />
{course.title}
</h3>
</a>
Expand Down
4 changes: 4 additions & 0 deletions fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import * as $group_slug_ from "./routes/group/[slug].tsx";
import * as $index from "./routes/index.tsx";
import * as $DoTest from "./islands/DoTest.ts";
import * as $Editor from "./islands/Editor.tsx";
import * as $ProgressCheck from "./islands/ProgressCheck.tsx";
import * as $ProgressTrack from "./islands/ProgressTrack.tsx";
import * as $ThemeToggle from "./islands/ThemeToggle.tsx";
import * as $Toast from "./islands/Toast.tsx";
import * as $signals_store from "./islands/signals/store.ts";
Expand All @@ -30,6 +32,8 @@ const manifest = {
islands: {
"./islands/DoTest.ts": $DoTest,
"./islands/Editor.tsx": $Editor,
"./islands/ProgressCheck.tsx": $ProgressCheck,
"./islands/ProgressTrack.tsx": $ProgressTrack,
"./islands/ThemeToggle.tsx": $ThemeToggle,
"./islands/Toast.tsx": $Toast,
"./islands/signals/store.ts": $signals_store,
Expand Down
17 changes: 17 additions & 0 deletions islands/ProgressCheck.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useState } from "preact/hooks";

import IconCircle from "https://deno.land/x/tabler_icons_tsx@0.0.5/tsx/circle.tsx";
import IconCircleCheckFilled from "https://deno.land/x/tabler_icons_tsx@0.0.5/tsx/circle-check-filled.tsx";

interface ProgressTrackProps {
slug: string;
}

export default function ProgressCheck(props: ProgressTrackProps) {
const [isDone, setIsDone] = useState(
localStorage.getItem(props.slug.replace(/\\/g, "/")) === "done",
);
return isDone
? <IconCircleCheckFilled aria-hidden="true" class="h-4 w-4" />
: <IconCircle aria-hidden="true" class="h-4 w-4" />;
}
19 changes: 19 additions & 0 deletions islands/ProgressTrack.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useEffect } from "preact/hooks";

interface ProgressTrackProps {
slug: string;
}

export default function ProgressTrack(props: ProgressTrackProps) {
useEffect(() => {
const initializeEditor = () => {
localStorage.setItem(props.slug, "done");
};
window.onload = initializeEditor;
return () => {
window.onload = null;
};
}, []);

return <></>;
}
2 changes: 2 additions & 0 deletions routes/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import EditorSplit from "../components/EditorSplit.tsx";
import MarkdownSplit from "../components/MarkdownSplit.tsx";
import { getTestCase } from "../utils/testcase.ts";

import ProgressTrack from "../islands/ProgressTrack.tsx";
import IconAppWindow from "https://deno.land/x/tabler_icons_tsx@0.0.5/tsx/app-window.tsx";

export const handler: Handlers<
Expand Down Expand Up @@ -89,6 +90,7 @@ export default function CoursePage(
</div>
</div>
</main>
<ProgressTrack slug={course.slug} />
</>
);
}
2 changes: 1 addition & 1 deletion static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ body, .markdown-body {

/* Monaco Editor */
.monaco-editor, .overflow-guard {
border-radius: 0.2rem;
border-radius: 0.3rem;
}

.iPadShowKeyboard{
Expand Down

0 comments on commit c03bb50

Please sign in to comment.