Skip to content

Commit

Permalink
fixed context errors
Browse files Browse the repository at this point in the history
  • Loading branch information
evanping committed Jul 18, 2024
1 parent 17355db commit 06b2ba9
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 33 deletions.
5 changes: 4 additions & 1 deletion @empirica-mocks/core/mocks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { useContext } from 'react';
import { StageContext } from './stageContext';
// import { StageContext } from '@/editor/stageContext';

// file is in deliberation-empirica/client/node_modules/@empirica/core/mocks.js
import { StageContext } from "../../../../../src/app/editor/stageContext"

export function usePlayer() {
// This is a mock function that returns a mock player object
Expand Down
23 changes: 0 additions & 23 deletions @empirica-mocks/core/stageContext.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/editor/components/EditStage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
stageSchema,
StageType,
ElementType,
} from '@/../deliberation-empirica/server/src/preFlight/validateTreatmentFile'
} from '../../../../deliberation-empirica/server/src/preFlight/validateTreatmentFile'
import { zodResolver } from '@hookform/resolvers/zod'
import * as zod from 'zod'

Expand Down
2 changes: 1 addition & 1 deletion src/app/editor/components/ElementCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react'
import { Modal } from './Modal'
import { EditElement } from './EditElement'
import { TreatmentType } from '@/../deliberation-empirica/server/src/preFlight/validateTreatmentFile'
import { TreatmentType } from '../../../../deliberation-empirica/server/src/preFlight/validateTreatmentFile'

export function ElementCard({
element,
Expand Down
2 changes: 1 addition & 1 deletion src/app/editor/components/RenderPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TimePicker from './TimePicker'
import { Stage } from './../../../.././deliberation-empirica/client/src/Stage.jsx'
import RenderDelibElement from './RenderDelibElement'

import { StageContext } from '../../../.././@empirica-mocks/core/stageContext'
import { StageContext } from '@/editor/stageContext'

{
/*const Stage = dynamic(
Expand Down
4 changes: 2 additions & 2 deletions src/app/editor/components/StageCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'
import React, { useState, useContext } from 'react'
import { ElementCard } from './ElementCard'
import { cn } from '@/app/components/utils'
import { cn } from '@/components/utils'
import { Modal } from './Modal'
import { EditStage } from './EditStage'
import { EditElement } from './EditElement'
Expand All @@ -12,7 +12,7 @@ import {
import { setCurrentStageIndex } from './utils'
import { useStage } from '../../../../@empirica-mocks/core/mocks'

import { StageContext } from '../../../.././@empirica-mocks/core/stageContext'
import { StageContext } from '../stageContext.jsx'

export function StageCard({
title,
Expand Down
2 changes: 1 addition & 1 deletion src/app/editor/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CodeEditor from './components/CodeEditor'
import { RenderPanel } from './components/RenderPanel'
import Timeline from './components/Timeline'

import { StageProvider } from '../../../@empirica-mocks/core/stageContext.js'
import { StageProvider } from './stageContext.jsx'

const defaultStageContext = {
currentStageIndex: undefined,
Expand Down
66 changes: 66 additions & 0 deletions src/app/editor/stageContext.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { createContext, useState } from 'react';

// export const StageContext = createContext({
// currentStageIndex: "default",
// elapsed: "default"
// });

const StageContext = createContext();

const StageProvider = ({ children }) => {
const [currentStageIndex, setCurrentStageIndex] = useState('default');
const [elapsed, setElapsed] = useState('default');

const contextValue = {
currentStageIndex,
setCurrentStageIndex,
elapsed,
setElapsed
};

return (
<StageContext.Provider value={contextValue}>
{children}
</StageContext.Provider>
);
};

export { StageContext, StageProvider };

// import React, { createContext, useState, useContext } from 'react';

// // Create the context
// const StageContext = createContext();

// // Create a custom hook for easy access to the context
// const useStageContext = () => useContext(StageContext);

// // Create the provider component
// const StageProvider = ({ children }) => {
// const [state, setState] = useState({
// currentStageIndex: 'default',
// elapsed: 'default'
// });

// const setCurrentStageIndex = (value) => {
// setState((prevState) => ({
// ...prevState,
// currentStageIndex: value
// }));
// };

// const setElapsed = (value) => {
// setState((prevState) => ({
// ...prevState,
// elapsed: value
// }));
// };

// return (
// <StageContext.Provider value={{ ...state, setCurrentStageIndex, setElapsed }}>
// {children}
// </StageContext.Provider>
// );
// };

// export { StageProvider, useStageContext };
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
"name": "next"
}
],
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@/api/*": ["./src/app/api/*"],
"@deliberation-empirica": ["./deliberation-empirica"]
"@/*": ["src/app/*"],
"@/api/*": ["src/app/api/*"],
"@deliberation-empirica": ["deliberation-empirica"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
Expand Down

0 comments on commit 06b2ba9

Please sign in to comment.