Skip to content

Commit 951d3e0

Browse files
Merge pull request #3 from PhantomKnight287/dev
Add autocomplete for imports
2 parents 4cd199a + baa86c1 commit 951d3e0

File tree

14 files changed

+298
-270
lines changed

14 files changed

+298
-270
lines changed

apps/docs/content/faq.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ You can resize the preview window to check responsiveness of site. You can also
4040

4141
## Where can I see console logs that I add in my code?
4242

43-
You can open dev tools in the site itself but we won't recommend it. You can open the preview in new tab by clicking on button in top right corner of preview window and then open dev tools in that tab.
43+
You can open dev tools in the site itself but we won't recommend it(you really don't want to see errors due to my skill issue, do you?). You can open the preview in new tab by clicking on button in top right corner of preview window and then open dev tools in that tab.
4444

4545
## I want to report a bug or suggest a feature
4646

apps/docs/content/index.mdx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ description: How to create Challenges for FrameGround
55

66
Thank you for your interest in creating a Challenge for FrameGround! We are excited to see what you come up with. This guide will walk you through the process of creating a Challenge.
77

8+
<Callout title="Note" type="warn">
9+
Please do not add any empty file in challenge. Add atleast 2-3 new lines.
10+
</Callout>
11+
812
## Using CLI
913

1014
### Creating a new project
@@ -34,19 +38,19 @@ describe("It Should Work", () => {
3438
Cli will only parse first test file in the project so make sure to add all tests in only 1 file.
3539
</Callout>
3640

37-
3841
### Using Cli to parse the project
3942

4043
Now, you can use the cli in `parser` folder to generate the json file.
4144

42-
```bash
45+
```bash
4346
cargo run generate --test-runner vitest --folder ../project --name test-challenge --slug react
4447
```
4548

4649
<TypeTable
4750
type={{
4851
"test-runner": {
49-
description: "The test runner to use for the challenge. It can be jest or vitest.",
52+
description:
53+
"The test runner to use for the challenge. It can be jest or vitest.",
5054
type: "string",
5155
typeDescription: "jest, vitest",
5256
},
@@ -65,15 +69,13 @@ cargo run generate --test-runner vitest --folder ../project --name test-challeng
6569
}}
6670
/>
6771

68-
6972
Running the above command will create a `challenges/react/test-challenge` folder in `parser` folder. You can copy the `test-challenge` or `react/test-challenge`(if track doesn't exist) folder to `challenges` folder.
7073

71-
72-
<Callout
73-
title="Note"
74-
type="info"
75-
>
76-
If you are creating a challenge using `jest`, you are adviced to create `jest.config.ts/jest.config.js` file in root of the challenge. Cli will parse the jest config file and use it for the challenge, if it doesn't exist, it will create an empty jest config file.
74+
<Callout title="Note" type="info">
75+
If you are creating a challenge using `jest`, you are adviced to create
76+
`jest.config.ts/jest.config.js` file in root of the challenge. Cli will parse
77+
the jest config file and use it for the challenge, if it doesn't exist, it
78+
will create an empty jest config file.
7779
</Callout>
7880

7981
### Marking Files as Editable
@@ -96,10 +98,6 @@ export default {
9698
} satisfies FrameGroundChallengeExport;
9799
```
98100

99-
100-
101-
102-
103101
## Manually
104102

105103
### Creating a folder

apps/web/app/tracks/[track]/challenge/[challenge]/_page.client.tsx

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
useTransition,
2323
} from "react";
2424
import { usePathname, useRouter } from "next/navigation";
25-
import { useTerminal } from "@repo/terminal";
25+
import { useTerminal, TerminalProps } from "@repo/terminal";
2626
import {
2727
createWebContainerInstance,
2828
FileSystemTree,
@@ -42,7 +42,8 @@ import EnrollInTrack from "./_components/enroll";
4242
import { attemptChallenge, solveChallenge } from "./action";
4343
import { signIn, useSession } from "next-auth/react";
4444
import { languages } from "@/constants/languages";
45-
import SplitEditor, {CodeEditor} from "@repo/monaco/exports"
45+
import SplitEditor from "@repo/monaco/exports";
46+
import { fontMono } from "@/fonts";
4647

4748
let timeout: NodeJS.Timeout;
4849

@@ -56,6 +57,7 @@ export default function Editor({
5657
files,
5758
CommentsSection,
5859
SolutionsSection,
60+
packages,
5961
}: {
6062
challenge: Challenge & {
6163
authors: User[];
@@ -72,17 +74,19 @@ export default function Editor({
7274
files: FrameGroundChallengeExport["files"];
7375
CommentsSection: ReactNode;
7476
SolutionsSection: ReactNode;
77+
packages: string[];
7578
}) {
7679
const session = useSession();
7780
const [_, startTransition] = useTransition();
7881
const { replace } = useRouter();
7982
const { activeFile, setActiveFile } = useEditorFileState();
8083

81-
const terminalOptions = useMemo(() => {
82-
const baseConfig = {
84+
const terminalOptions = useMemo<TerminalProps["options"]>(() => {
85+
const baseConfig: TerminalProps["options"] = {
8386
cursorBlink: false,
8487
convertEol: true,
8588
disableStdin: false,
89+
fontFamily: fontMono.style.fontFamily,
8690
};
8791
if (
8892
Object.keys((challenge?.terminalConfig as unknown as Object) || {}).length
@@ -222,8 +226,11 @@ const command = ${
222226
}
223227
}, []);
224228
const [hiddenIframe, setHiddenIframe] = useState(false);
229+
const path = useMemo(
230+
() => generateFilePath(files, activeFile?.path || "0"),
231+
[activeFile?.path, files]
232+
);
225233
function handleInput(value: string) {
226-
const path = generateFilePath(files, activeFile?.path || "0");
227234
if (path) containerRef?.current?.fs?.writeFile(path, value);
228235
}
229236
const debouncedHandleInput = (val: string) => {
@@ -256,7 +263,7 @@ const command = ${
256263
minSize={10}
257264
defaultSize={10}
258265
className={cn(
259-
"flex flex-col h-full border-r border-l border-background bg-border rounded-md overflow-scroll custom-scrollable-element max-h-screen"
266+
"flex flex-col h-full border-r border-l border-background bg-border rounded-md overflow-scroll custom-scrollable-element "
260267
)}
261268
>
262269
<div className="uppercase font-bold flex flex-row items-center justify-between text-sm p-2 border-b-[12px] border-background line-clamp-1">
@@ -353,21 +360,26 @@ const command = ${
353360
</div>
354361

355362
<SplitEditor
356-
height={"100vh"}
357-
activeFile={"Challenge.md"}
363+
height={"100vh"}
364+
initialPackages={packages}
365+
activeFile={"Challenge.md"}
366+
activeFilePath={path}
358367
value={content || ""}
359368
onChange={(value) => {
360369
debouncedHandleInput(value || "");
361370
}}
362371
theme={"vs-dark"}
363-
language={language}
372+
defaultLanguage={language}
373+
defaultValue={content || ""}
374+
path={`file://${path}`}
364375
options={{
365376
fontSize: 16,
366377
readOnly:
367378
activeFile?.editable === undefined
368379
? true
369380
: !activeFile?.editable,
370381
wordWrap: "on",
382+
fontFamily: fontMono.style.fontFamily,
371383
}}
372384
/>
373385

@@ -424,8 +436,8 @@ const command = ${
424436
{testsPassed
425437
? "Tests Passed"
426438
: !session?.data?.user?.id
427-
? "Login to Test"
428-
: "Test"}
439+
? "Login to Test"
440+
: "Test"}
429441
</button>
430442
<button
431443
className="bg-green-500 hover:bg-green-600 text-white max-h-fit px-4 py-1 rounded-md "

apps/web/app/tracks/[track]/challenge/[challenge]/page.client.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ function ChallengeTabs({
4141

4242
useEffect(() => {
4343
const value = localStorage.getItem("faq_modal_shown");
44-
console.log(value);
4544
if (!value || value === "false") {
4645
setIsFAQModalOpened(true);
4746
}

apps/web/app/tracks/[track]/challenge/[challenge]/page.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ async function Challenge({
103103
},
104104
...(challenge.initialFiles as unknown as FrameGroundChallengeExport["files"]),
105105
];
106+
const packages = [];
107+
const packageJsonContent = JSON.parse(
108+
(
109+
challenge.initialFiles.filter(
110+
(d: any) => d.name === "package.json"
111+
)[0]! as unknown as FrameGroundChallengeExport["files"][0]
112+
).content as string
113+
);
114+
115+
packages.push(
116+
...Object.keys(packageJsonContent.dependencies),
117+
...Object.keys(packageJsonContent.devDependencies)
118+
);
106119
if (challenge.jestConfig) {
107120
// add at index 1
108121
files.splice(1, 0, {
@@ -157,7 +170,7 @@ async function Challenge({
157170
}
158171
});
159172
return (
160-
<div className="px-4 sticky h-screen top-[40px]">
173+
<div className="px-4 sticky h-full top-[40px]">
161174
<div className="flex flex-row h-screen">
162175
<Editor
163176
//@ts-expect-error
@@ -166,6 +179,7 @@ async function Challenge({
166179
fileSystem={fileSystem}
167180
queryParams={searchParams}
168181
files={files as any}
182+
packages={packages}
169183
CommentsSection={
170184
<Comments
171185
sortBy={searchParams.sort_comments as "oldest" | "newest"}

apps/web/components/markdown/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import { vscDarkPlus } from "./themes/vs-dark-plus";
1313
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
1414
import { Button } from "../ui/button";
1515
import { Check, Copy } from "lucide-react";
16-
import { vsDark,vscDarkPlus as vscDarkPlusPrisma} from "react-syntax-highlighter/dist/cjs/styles/prism";
16+
import {
17+
vsDark,
18+
vscDarkPlus as vscDarkPlusPrisma,
19+
} from "react-syntax-highlighter/dist/cjs/styles/prism";
1720
import raw from "rehype-raw";
1821
import { Callout } from "../callout";
1922

20-
2123
const HTML_COMMENT_REGEX = new RegExp("<!--([\\s\\S]*?)-->", "g");
2224

2325
/**
@@ -52,9 +54,6 @@ export function Markdown({
5254
children: string;
5355
className?: string;
5456
}) {
55-
const { theme } = useTheme();
56-
const syntaxHighlighterTheme = theme === "light" ? vs : vscDarkPlus;
57-
5857
return (
5958
<ReactMarkdown
6059
skipHtml

apps/web/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@repo/monaco": "workspace:^",
2929
"@repo/terminal": "workspace:^",
3030
"@repo/utils": "workspace:^",
31+
"@stefanprobst/remark-shiki": "^2.2.1",
3132
"@t3-oss/env-nextjs": "^0.7.1",
3233
"@vercel/analytics": "^1.1.2",
3334
"@vercel/og": "^0.6.2",
@@ -54,6 +55,7 @@
5455
"react-textarea-autosize": "^8.5.3",
5556
"rehype-raw": "^7.0.0",
5657
"remark-gfm": "^4.0.0",
58+
"shiki": "^1.4.0",
5759
"sonner": "^1.3.1",
5860
"tailwind-merge": "^2.2.0",
5961
"tailwindcss-animate": "^1.0.7",

challenges/react/class-components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default {
8686
{
8787
type: "file",
8888
name: "greet.jsx",
89-
content: "",
89+
content: "\n\n\n\n\n\n",
9090
editable: true,
9191
},
9292
],

challenges/react/functional-components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default {
8686
{
8787
type: "file",
8888
name: "greet.jsx",
89-
content: "",
89+
content: "\n\n\n\n\n\n",
9090
editable: true,
9191
},
9292
],

0 commit comments

Comments
 (0)