From eead7a76fc0195c233568c68a2853589a6ca5345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zhan=20Efe=20Meral?= Date: Sun, 28 Jul 2024 17:54:46 +0200 Subject: [PATCH] chore: cleanup old code --- apps/next/contexts/CodeGeneratorContext.tsx | 106 ++------------------ 1 file changed, 10 insertions(+), 96 deletions(-) diff --git a/apps/next/contexts/CodeGeneratorContext.tsx b/apps/next/contexts/CodeGeneratorContext.tsx index d51b65b..3da6545 100644 --- a/apps/next/contexts/CodeGeneratorContext.tsx +++ b/apps/next/contexts/CodeGeneratorContext.tsx @@ -1,16 +1,9 @@ -/* eslint-disable no-unused-vars */ +import { CodeGeneratorState, generateCode } from "@ozhanefe/ts-codegenerator"; import { - CodeBlock, - CodeGeneratorState, - ElseIfBlock, - FunctionCallBlock, - generateCode, - IfBlock, - WhileLoopBlock, -} from "@ozhanefe/ts-codegenerator"; -import { - PropsWithChildren, createContext, + Dispatch, + PropsWithChildren, + SetStateAction, useContext, useEffect, useState, @@ -18,7 +11,7 @@ import { interface Context { state: CodeGeneratorState; - setState: (state: CodeGeneratorState) => void; + setState: Dispatch>; code: string; } @@ -35,9 +28,11 @@ const CodeGeneratorContext = createContext({ export const CodeGeneratorProvider: React.FC = ({ children, }) => { - const [state, setState] = useState( - generateRealisticDevDayState() - ); + const [state, setState] = useState({ + blocks: [], + variables: [], + isAsync: false, + }); const [code, setCode] = useState(""); useEffect(() => { @@ -60,84 +55,3 @@ export const CodeGeneratorProvider: React.FC = ({ export const useCodeGenerator = () => { return useContext(CodeGeneratorContext); }; - -function generateRealisticDevDayState(): CodeGeneratorState { - const wakeUp: FunctionCallBlock = { - functionInfo: { name: "wakeUp", returnType: "void" }, - returnVariable: { name: "awake", type: "boolean" }, - isAsync: false, - index: 0, - blockType: "functionCall", - }; - - const getCoffee: FunctionCallBlock = { - functionInfo: { name: "getCoffee", returnType: "void" }, - returnVariable: { name: "caffeinated", type: "boolean" }, - isAsync: false, - index: 1, - blockType: "functionCall", - }; - - const writeCode: FunctionCallBlock = { - functionInfo: { name: "writeCode", returnType: "number" }, - returnVariable: { name: "linesOfCode", type: "number" }, - isAsync: false, - index: 2, - blockType: "functionCall", - }; - - const ifTired: IfBlock = { - condition: "energyLevel < 30", - thenBlocks: [getCoffee], - elseBlock: { blocks: [writeCode] }, - index: 3, - blockType: "if", - }; - - const coding: WhileLoopBlock = { - condition: "workHours < 8", - loopBlocks: [ifTired], - index: 4, - blockType: "while", - }; - - const celebrate: FunctionCallBlock = { - functionInfo: { name: "celebrate", returnType: "void" }, - returnVariable: { name: "partyTime", type: "boolean" }, - isAsync: false, - index: 5, - blockType: "functionCall", - }; - - const playVideoGames: FunctionCallBlock = { - functionInfo: { name: "playVideoGames", returnType: "void" }, - returnVariable: { name: "stressRelieved", type: "boolean" }, - isAsync: false, - index: 6, - blockType: "functionCall", - }; - - const afterWorkMood: IfBlock = { - condition: "linesOfCode > 100", - thenBlocks: [celebrate], - elseBlock: { blocks: [playVideoGames] }, - index: 7, - blockType: "if", - }; - - const blocks: CodeBlock[] = [wakeUp, coding, afterWorkMood]; - - return { - blocks, - variables: [ - { name: "awake", type: "boolean", index: 0 }, - { name: "energyLevel", type: "number", index: 1 }, - { name: "workHours", type: "number", index: 2 }, - { name: "linesOfCode", type: "number", index: 3 }, - { name: "caffeinated", type: "boolean", index: 4 }, - { name: "partyTime", type: "boolean", index: 5 }, - { name: "stressRelieved", type: "boolean", index: 6 }, - ], - isAsync: false, - }; -}