Skip to content

Commit

Permalink
fixed the editor linkage issue, working on making sure user progress …
Browse files Browse the repository at this point in the history
…is saved
  • Loading branch information
reevafaisal committed Sep 27, 2024
1 parent a0ab52c commit 9b7d7ab
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 488 deletions.
215 changes: 107 additions & 108 deletions src/haz3lschool/DocumentationEnv.re
Original file line number Diff line number Diff line change
Expand Up @@ -159,58 +159,29 @@ module D = (DocEnv: DocEnv) => {
// | CorrectImpl => eds.correct_impl
// | YourTestsValidation => eds.your_tests.tests
// | YourTestsTesting => eds.your_tests.tests
| YourImpl => eds.your_impl
| YourImpl =>
// print_endline("grabs YourImpl");
eds.your_impl
// | HiddenBugs(i) => List.nth(eds.hidden_bugs, i).impl
| HiddenTests => eds.hidden_tests.tests
| HiddenTests =>
// print_endline("grabs HiddenTests");
eds.hidden_tests.tests
};

let put_editor = ({pos, eds, _} as state: state, editor: Editor.t) =>
let put_editor = ({pos, eds} as state: state, editor: Editor.t) =>
switch (pos) {
// | Prelude => {
// ...state,
// eds: {
// ...eds,
// prelude: editor,
// },
// }
// | CorrectImpl => {
// ...state,
// eds: {
// ...eds,
// correct_impl: editor,
// },
// }
// | YourTestsValidation
// | YourTestsTesting => {
// ...state,
// eds: {
// ...eds,
// your_tests: {
// ...eds.your_tests,
// tests: editor,
// },
// },
// }
| YourImpl => {
| YourImpl =>
// print_endline("YourImpl");
{
...state,
eds: {
...eds,
your_impl: editor,
},
}
// | HiddenBugs(n) => {
// ...state,
// eds: {
// ...eds,
// hidden_bugs:
// Util.ListUtil.put_nth(
// n,
// {...List.nth(eds.hidden_bugs, n), impl: editor},
// eds.hidden_bugs,
// ),
// },
// }
| HiddenTests => {
| HiddenTests =>
// print_endline("HiddenTests");
{
...state,
eds: {
...eds,
Expand All @@ -222,21 +193,22 @@ module D = (DocEnv: DocEnv) => {
}
};

let editors = ({eds, _}: state) =>
[
// eds.prelude,
// eds.correct_impl,
// eds.your_tests.tests,
// eds.your_tests.tests,
eds.your_impl,
]
// @ List.map(wrong_impl => wrong_impl.impl, eds.hidden_bugs)
@ [eds.hidden_tests.tests];

let editor_positions =
[YourImpl]
// @ List.mapi((i, _) => HiddenBugs(i), eds.hidden_bugs)
@ [HiddenTests];
let editors = ({eds, _}: state) => [
// eds.prelude,
// eds.correct_impl,
// eds.your_tests.tests,
// eds.your_tests.tests,
eds.your_impl,
eds.hidden_tests.tests,
];
// @ List.map(wrong_impl => wrong_impl.impl, eds.hidden_bugs)
// @ [eds.hidden_tests.tests];

// let editor_positions =
// [YourImpl]
// // @ List.mapi((i, _) => HiddenBugs(i), eds.hidden_bugs)
// @ [HiddenTests];
let editor_positions = [YourImpl, HiddenTests];

let positioned_editors = state =>
List.combine(editor_positions, editors(state));
Expand Down Expand Up @@ -281,35 +253,41 @@ module D = (DocEnv: DocEnv) => {
let switch_editor = (~pos, instructor_mode, ~documentation) =>
if (!instructor_mode) {
switch (pos) {
| HiddenTests =>
// Update the `hidden_tests` editor when position is HiddenTests
let updated_hidden_tests = documentation.eds.hidden_tests.tests;
{
// ...documentation,
eds: {
...documentation.eds,
hidden_tests: {
...documentation.eds.hidden_tests,
tests: updated_hidden_tests,
},
},
pos: HiddenTests,
};
| YourImpl =>
// Update the `your_impl` editor when position is YourImpl
let updated_your_impl = documentation.eds.your_impl;
{
// ...documentation,
eds: {
...documentation.eds,
your_impl: updated_your_impl,
},
pos: YourImpl,
};
// | _ => {
// // Handle other cases by just updating the position
// {eds: documentation.eds, pos};
// }
| HiddenTests
// =>
// Update the `hidden_tests` editor when position is HiddenTests
// print_endline("Updating HiddenTests editor");
// let updated_hidden_tests = documentation.eds.hidden_tests.tests;
// {
// // ...documentation,
// eds: {
// ...documentation.eds,
// hidden_tests: {
// ...documentation.eds.hidden_tests,
// tests: updated_hidden_tests,
// },
// your_impl: documentation.eds.your_impl,
// },
// pos: HiddenTests,
// };
// | YourImpl =>
// // Update the `your_impl` editor when position is YourImpl
// print_endline("Updating YourImpl editor");
// let updated_your_impl = documentation.eds.your_impl;
// {
// // ...documentation,
// eds: {
// ...documentation.eds,
// your_impl: updated_your_impl,
// hidden_tests: documentation.eds.hidden_tests,
// },
// pos: YourImpl,
// };
| _ => {
// Handle other cases by just updating the position
eds: documentation.eds,
pos,
}
};
} else {
{
Expand Down Expand Up @@ -478,6 +456,11 @@ module D = (DocEnv: DocEnv) => {
};
};

// let state_of_spec = (spec, ~instructor_mode: bool): state => {
// let eds = eds_of_spec(spec);
// set_instructor_mode({pos: HiddenTests, eds}, instructor_mode);
// };

let state_of_spec = (spec, ~instructor_mode: bool): state => {
let eds = eds_of_spec(spec);
set_instructor_mode({pos: HiddenTests, eds}, instructor_mode);
Expand Down Expand Up @@ -608,33 +591,48 @@ module D = (DocEnv: DocEnv) => {
// term_of(ed3),
// );

// let stitch_term = ({eds, _}: state): stitched(TermItem.t) => {
// let instructor = eds.hidden_tests.tests |> term_of;
// let user_impl_term = {
// // let your_impl_term =
// eds.your_impl |> term_of |> wrap_filter(FilterAction.Step); // let prelude_term =
// // EditorUtil.append_exp(your_impl_term);
// };
// // let test_validation_term =
// // stitch3(eds.prelude, eds.correct_impl, eds.your_tests.tests);
// // let user_tests_term =
// // EditorUtil.append_exp(user_impl_term, term_of(eds.your_tests.tests));
// let hidden_tests_term =
// EditorUtil.append_exp(user_impl_term, term_of(eds.hidden_tests.tests));
// {
// // test_validation: wrap(test_validation_term, eds.your_tests.tests),
// user_impl: wrap(user_impl_term, eds.your_impl),
// // user_tests: wrap(user_tests_term, eds.your_tests.tests),
// // instructor works here as long as you don't shadow anything in the prelude
// // prelude: wrap(instructor, eds.prelude),
// instructor: wrap(instructor, eds.hidden_tests.tests),
// // hidden_bugs:
// // List.map(
// // (t): TermItem.t =>
// // // term_of(t.impl),
// // wrap(stitch3(eds.prelude, t.impl, eds.your_tests.tests), t.impl),
// // eds.hidden_bugs,
// // ),
// hidden_tests: wrap(hidden_tests_term, eds.hidden_tests.tests),
// };
// };
let stitch_term = ({eds, _}: state): stitched(TermItem.t) => {
let instructor = eds.hidden_tests.tests |> term_of;
let user_impl_term = {
// let your_impl_term =
eds.your_impl |> term_of |> wrap_filter(FilterAction.Step); // let prelude_term =
// EditorUtil.append_exp(your_impl_term);
eds.your_impl |> term_of |> wrap_filter(FilterAction.Step);
};
// let test_validation_term =
// stitch3(eds.prelude, eds.correct_impl, eds.your_tests.tests);
// let user_tests_term =
// EditorUtil.append_exp(user_impl_term, term_of(eds.your_tests.tests));
let hidden_tests_term =
EditorUtil.append_exp(user_impl_term, term_of(eds.hidden_tests.tests));

// No combining of your_impl_term with hidden_tests
let hidden_tests_term = term_of(eds.hidden_tests.tests);

{
// test_validation: wrap(test_validation_term, eds.your_tests.tests),
user_impl: wrap(user_impl_term, eds.your_impl),
// user_tests: wrap(user_tests_term, eds.your_tests.tests),
// instructor works here as long as you don't shadow anything in the prelude
// prelude: wrap(instructor, eds.prelude),
instructor: wrap(instructor, eds.hidden_tests.tests),
// hidden_bugs:
// List.map(
// (t): TermItem.t =>
// // term_of(t.impl),
// wrap(stitch3(eds.prelude, t.impl, eds.your_tests.tests), t.impl),
// eds.hidden_bugs,
// ),
hidden_tests: wrap(hidden_tests_term, eds.hidden_tests.tests),
};
};
Expand All @@ -647,6 +645,7 @@ module D = (DocEnv: DocEnv) => {
Stitching is necessary to concatenate terms
from different editors, which are then typechecked. */

let stitch_static =
(settings: CoreSettings.t, t: stitched(TermItem.t)): stitched_statics => {
let mk = ({term, term_ranges, _}: TermItem.t): StaticsItem.t => {
Expand Down Expand Up @@ -953,7 +952,7 @@ module D = (DocEnv: DocEnv) => {
// let prelude = Zipper.next_blank();
// let correct_impl = Zipper.next_blank();
// let your_tests_tests = Zipper.next_blank();
let your_impl = Zipper.next_blank();
let your_impl_m = Zipper.next_blank();
// let hidden_bugs =
// List.init(
// num_wrong_impls,
Expand All @@ -977,7 +976,7 @@ module D = (DocEnv: DocEnv) => {
// required: required_tests,
// provided: provided_tests,
// },
your_impl,
your_impl: your_impl_m,
// hidden_bugs,
hidden_tests: {
tests: hidden_tests_tests,
Expand Down
6 changes: 5 additions & 1 deletion src/haz3lschool/Exercise.re
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ module F = (ExerciseEnv: ExerciseEnv) => {
| _ => {eds: exercise.eds, pos}
};
} else {
{eds: exercise.eds, pos};
{
// print_endline("im exercise");
eds: exercise.eds,
pos,
};
};

let zipper_of_code = code => {
Expand Down
21 changes: 15 additions & 6 deletions src/haz3lweb/Editors.re
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ type t =
| Documentation(string, list((string, DocumentationEnv.state)))
| Exercises(int, list(Exercise.spec), Exercise.state);

[@deriving (show({with_path: false}), sexp, yojson)]
type cur_state =
| ScratchState(ScratchSlide.state)
| DocumentationState(DocumentationEnv.state)
| ExerciseState(Exercise.state);
// [@deriving (show({with_path: false}), sexp, yojson)]
// type cur_state =
// | ScratchState(ScratchSlide.state)
// | DocumentationState(DocumentationEnv.state)
// | ExerciseState(Exercise.state);

let get_editor = (editors: t): Editor.t =>
switch (editors) {
Expand Down Expand Up @@ -120,10 +120,19 @@ let put_editor = (editor: Editor.t, eds: t): t =>
(hint: string, state: DocumentationEnv.state)
: (string, DocumentationEnv.state) =>
if (hint == name) {
// print_endline("hint == name");
print_endline(hint);
print_endline(name);

let updatedState = DocumentationEnv.put_editor(state, editor);

(hint, updatedState);
} else {
(hint, state);
(
// print_endline("different_slide");
hint,
state,
);
};

// Map the update function over the slides
Expand Down
5 changes: 4 additions & 1 deletion src/haz3lweb/Log.re
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ let import = (data: string): unit =>

let update = (action: UpdateAction.t): unit =>
if (is_action_logged(action)) {
Entry.save(Entry.mk(action));
// print_endline("Log Updating" ++ UpdateAction.show(action));
Entry.save(
Entry.mk(action),
);
};

let get_and = (f: string => unit): unit =>
Expand Down
1 change: 1 addition & 0 deletions src/haz3lweb/Main.re
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ let apply = (model, action, state, ~schedule_action): Model.t => {
| Error(FailedToPerform(err)) =>
// TODO(andrew): reinstate this history functionality
print_endline(Update.Failure.show(FailedToPerform(err)));
// print_endline("ERROR IN MAIN UPDATE");
//{...model, history: ActionHistory.failure(err, model.history)};
model;
| Error(err) =>
Expand Down
21 changes: 9 additions & 12 deletions src/haz3lweb/Model.re
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,13 @@ let load_editors =
(Scratch(idx, slides), results);
| Documentation =>
let (name, slides, results) = Store.Documentation.load(~settings);
// let toEditor = (state: DocumentationEnv.state): Editor.t => {
// switch (state) {
// | s => s.eds.hidden_tests.tests
// };
// };
// let from_tup = ((word: string, status: DocumentationEnv.state)) => (
// word,
// toEditor(status),
// );
// let slides = List.map(from_tup, slides);
// let slides = reset_named_slide(name, slides);

let fromEditor = (editor: Editor.t): DocumentationEnv.state => {
pos: DocumentationEnv.YourImpl,
eds: {
title: "",
description: "",
your_impl: editor,
your_impl: Editor.init(Zipper.init()),
hidden_tests: {
tests: editor,
hints: [],
Expand All @@ -101,7 +91,14 @@ let load_editors =
word,
fromEditor(editor),
);
print_endline("inside load editors");
let slides = List.map(to_tup, slides);
// let (n, specs, exercise) =
// Store.Exercise.load(
// ~specs=ExerciseSettings.exercises,
// ~instructor_mode,
// );
// (Exercises(n, specs, exercise), ModelResults.empty);

(Documentation(name, slides), results);
| Exercises =>
Expand Down
Loading

0 comments on commit 9b7d7ab

Please sign in to comment.