Skip to content

Commit

Permalink
minor errors
Browse files Browse the repository at this point in the history
  • Loading branch information
christabusho committed Jul 8, 2024
2 parents b442585 + bdfb196 commit d816a80
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 92 deletions.
165 changes: 84 additions & 81 deletions src/app/editor/components/CodeEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,94 +1,97 @@
'use client'
import YamlEditor from '@uiw/react-textarea-code-editor'
import { useState, useEffect } from 'react'
import { useState, useEffect, useMemo } from 'react'
import { parse } from 'yaml'
import { stringify } from 'yaml'

export default function CodeEditor() {
const [code, setCode] = useState('')

const defaultTreatment = {
name: 'Example Treatment',
desc: 'Run through the entire negotiation sequence.',
playerCount: 3,
assignPositionsBy: 'random',
gameStages: [
{
name: 'Role Assignment and General Instructions',
duration: 300,
desc: 'Assign participants a role',
elements: [
{
type: 'prompt',
file: 'projects/3-way-negotiation/01a_instructions_3_way_negotiation.md',
showToPositions: [0],
},
{
type: 'prompt',
file: 'projects/3-way-negotiation/01b_instructions_3_way_negotiation.md',
showToPositions: [1],
},
{
type: 'prompt',
file: 'projects/3-way-negotiation/01c_instructions_3_way_negotiation.md',
showToPositions: [2],
},
{
type: 'submitButton',
},
],
},
{
name: 'Main Discussion',
duration: 600,
desc: 'Main Discussion Time',
discussion: {
chatType: 'text',
showNickname: false,
showTitle: true,
const defaultTreatment = useMemo(
() => ({
name: 'Example Treatment',
desc: 'Run through the entire negotiation sequence.',
playerCount: 3,
assignPositionsBy: 'random',
gameStages: [
{
name: 'Role Assignment and General Instructions',
duration: 300,
desc: 'Assign participants a role',
elements: [
{
type: 'prompt',
file: 'projects/3-way-negotiation/01a_instructions_3_way_negotiation.md',
showToPositions: [0],
},
{
type: 'prompt',
file: 'projects/3-way-negotiation/01b_instructions_3_way_negotiation.md',
showToPositions: [1],
},
{
type: 'prompt',
file: 'projects/3-way-negotiation/01c_instructions_3_way_negotiation.md',
showToPositions: [2],
},
{
type: 'submitButton',
},
],
},
elements: [
{
type: 'prompt',
file: 'projects/3-way-negotiation/03a_rep_a.md',
showToPositions: [0],
},
{
type: 'prompt',
file: 'projects/3-way-negotiation/03b_rep_b.md',
showToPositions: [1],
},
{
type: 'prompt',
file: 'projects/3-way-negotiation/03c_rep_c.md',
showToPositions: [2],
},
{
type: 'prompt',
file: 'projects/3-way-negotiation/05_response_submission.md',
{
name: 'Main Discussion',
duration: 600,
desc: 'Main Discussion Time',
discussion: {
chatType: 'text',
showNickname: false,
showTitle: true,
},
{
type: 'separator',
style: 'thin',
},
{
type: 'prompt',
file: 'projects/3-way-negotiation/06_multipleChoice_agreement_submission.md',
name: 'dealsheet1',
},
{
type: 'prompt',
file: 'projects/3-way-negotiation/06_multipleChoice_agreement_submission_inclusion.md',
name: 'dealsheet2',
},
{
type: 'submitButton',
buttonText: 'Submit Now and End Negotiation',
},
],
},
],
}
elements: [
{
type: 'prompt',
file: 'projects/3-way-negotiation/03a_rep_a.md',
showToPositions: [0],
},
{
type: 'prompt',
file: 'projects/3-way-negotiation/03b_rep_b.md',
showToPositions: [1],
},
{
type: 'prompt',
file: 'projects/3-way-negotiation/03c_rep_c.md',
showToPositions: [2],
},
{
type: 'prompt',
file: 'projects/3-way-negotiation/05_response_submission.md',
},
{
type: 'separator',
style: 'thin',
},
{
type: 'prompt',
file: 'projects/3-way-negotiation/06_multipleChoice_agreement_submission.md',
name: 'dealsheet1',
},
{
type: 'prompt',
file: 'projects/3-way-negotiation/06_multipleChoice_agreement_submission_inclusion.md',
name: 'dealsheet2',
},
{
type: 'submitButton',
buttonText: 'Submit Now and End Negotiation',
},
],
},
],
}),
[]
)

useEffect(() => {
let value
Expand Down
6 changes: 3 additions & 3 deletions src/app/editor/components/EditElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function EditElement({
stageIndex: number
elementIndex: number
}) {
var currComponent: ElementType
var currComponent: ElementType | undefined
if (elementIndex !== -1) {
currComponent = treatment.gameStages[stageIndex].elements[elementIndex]
} else {
Expand All @@ -35,11 +35,11 @@ export function EditElement({
} = useForm({
defaultValues: {
name:
elementIndex !== -1 && currComponent.name !== undefined
elementIndex !== -1 && currComponent?.name !== undefined
? currComponent.name
: '',
selectedOption:
elementIndex !== -1 && currComponent.type !== undefined
elementIndex !== -1 && currComponent?.type !== undefined
? currComponent.type
: 'Pick one',
file: '',
Expand Down
24 changes: 16 additions & 8 deletions src/app/editor/components/EditStage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,29 @@ export function EditStage({
editTreatment: (treatment: TreatmentType) => void
stageIndex: number
}) {
var currComponent: StageType | undefined
if (stageIndex !== -1) {
currComponent = treatment.gameStages[stageIndex]
} else {
currComponent = undefined
}

const {
register,
watch,
handleSubmit,
setValue,
formState: { isValid, errors },
} = useForm<StageType>({
defaultValues: stageIndex !== undefined
? {
name: treatment?.gameStages[stageIndex]?.name || '',
duration: treatment?.gameStages[stageIndex]?.duration || 0,
}
: {
name: '',
duration: 0,
defaultValues: {
name:
stageIndex !== -1 && currComponent?.name !== undefined
? currComponent.name
: '',
duration:
stageIndex !== -1 && currComponent?.duration !== undefined
? currComponent.duration
: undefined,
},
resolver: zodResolver(stageSchema),
mode: 'onChange',
Expand Down

0 comments on commit d816a80

Please sign in to comment.