Skip to content

Commit

Permalink
copied over everything for tutorial state - small bug in saving
Browse files Browse the repository at this point in the history
  • Loading branch information
reevafaisal committed Oct 31, 2024
1 parent db0cf93 commit 3f1838e
Show file tree
Hide file tree
Showing 16 changed files with 1,632 additions and 31 deletions.
675 changes: 675 additions & 0 deletions src/haz3lschool/Tutorial.re

Large diffs are not rendered by default.

106 changes: 97 additions & 9 deletions src/haz3lweb/Editors.re
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type exercises = (int, list(Exercise.spec), Exercise.state);
type t =
| Scratch(int, list(ScratchSlide.state))
| Documentation(string, list((string, ScratchSlide.state)))
| Tutorial(string, list((string, Tutorial.state)))
| Exercises(int, list(Exercise.spec), Exercise.state);

let get_editor = (editors: t): Editor.t =>
Expand All @@ -24,9 +25,16 @@ let get_editor = (editors: t): Editor.t =>
| Documentation(name, slides) =>
assert(List.mem_assoc(name, slides));
List.assoc(name, slides).hidden_tests.tests;
| Tutorial(name, slides) =>
assert(List.mem_assoc(name, slides));
let slide_state = List.assoc(name, slides);
Tutorial.editor_of_state(slide_state);
| Exercises(_, _, exercise) => Exercise.editor_of_state(exercise)
};

let update_assoc = ((k, v), lst) =>
List.map(((k', v')) => k == k' ? (k, v) : (k', v'), lst);

let put_editor = (ed: Editor.t, eds: t): t =>
switch (eds) {
| Scratch(n, slides) =>
Expand All @@ -43,19 +51,56 @@ let put_editor = (ed: Editor.t, eds: t): t =>
Scratch(n, Util.ListUtil.put_nth(n, updatedSlide, slides));
| Documentation(name, slides) =>
assert(List.mem_assoc(name, slides));
let originalSlide = List.assoc(name, slides);
let updatedSlide: ScratchSlide.state = {
title: originalSlide.title,
description: originalSlide.description,
// let originalSlide = List.assoc(name, slides);
// let updatedSlide: ScratchSlide.state = {
// title: originalSlide.title,
// description: originalSlide.description,
// hidden_tests: {
// tests: ed,
// hints: originalSlide.hidden_tests.hints,
// },
// };
// Documentation(
// name,
// slides |> ListUtil.update_assoc((name, updatedSlide)),
// );
let new_ed: ScratchSlide.state = {
title: "",
description: "",
hidden_tests: {
tests: ed,
hints: originalSlide.hidden_tests.hints,
hints: [],
},
};
Documentation(
name,
slides |> ListUtil.update_assoc((name, updatedSlide)),
);
Documentation(name, slides |> update_assoc((name, new_ed)));

| Tutorial(name, slides) =>
assert(List.mem_assoc(name, slides));

// Function to update the slide based on `editor`
let update_slide =
(hint: string, state: Tutorial.state): (string, Tutorial.state) =>
if (hint == name) {
print_endline(hint);
print_endline(name);

let updatedState = Tutorial.put_editor(state, ed);

(hint, updatedState);
} else {
(hint, state);
};

let updatedSlides =
List.map(
slide => {
let (hint, state) = slide;
update_slide(hint, state);
},
slides,
);

Tutorial(name, updatedSlides);
| Exercises(n, specs, exercise) =>
Exercises(n, specs, Exercise.put_editor(exercise, ed))
};
Expand Down Expand Up @@ -91,13 +136,15 @@ let get_ctx_init = (~settings as _: Settings.t, editors: t): Ctx.t =>
| Scratch(_)
| Exercises(_)
| Documentation(_) => Builtins.ctx_init
| Tutorial(_) => Builtins.ctx_init
};

let get_env_init = (~settings as _: Settings.t, editors: t): Environment.t =>
switch (editors) {
| Scratch(_)
| Exercises(_)
| Documentation(_) => Builtins.env_init
| Tutorial(_) => Builtins.env_init
};

/* Each mode (e.g. Scratch, School) requires
Expand All @@ -121,13 +168,29 @@ let get_spliced_elabs =
let statics = get_editor(editors).state.meta.statics;
let d = Interface.elaborate(~settings, statics.info_map, statics.term);
[(key, {d: d})];
| Tutorial(name, slides) =>
let slideState = List.assoc(name, slides);
Tutorial.spliced_elabs(settings, slideState);
| Exercises(_, _, exercise) => Exercise.spliced_elabs(settings, exercise)
};

let set_instructor_mode = (editors: t, instructor_mode: bool): t =>
switch (editors) {
| Scratch(_)
| Documentation(_) => editors
| Tutorial(name, slides) =>
// Assuming you want to pass instructor_mode down to each slide
let updated_slides =
List.map(
((slide_name, slide_state)) => {
(
slide_name,
Tutorial.set_instructor_mode(slide_state, instructor_mode),
)
},
slides,
);
Tutorial(name, updated_slides);
| Exercises(n, specs, exercise) =>
Exercises(
n,
Expand Down Expand Up @@ -179,6 +242,29 @@ let reset_current =
| Scratch(n, slides) => Scratch(n, reset_nth_slide(~settings, n, slides))
| Documentation(name, slides) =>
Documentation(name, reset_named_slide(~settings, name, slides))
| Tutorial(name, slides) =>
let from_tup = ((word: string, status: Tutorial.state)) => {
let your_impl_zipper = status.eds.your_impl.state.zipper;
let hidden_tests_zipper = status.eds.hidden_tests.tests.state.zipper;
let spec: Tutorial.spec = {
title: status.eds.title,
description: status.eds.description,
your_impl: your_impl_zipper,
hidden_tests: {
tests: hidden_tests_zipper,
hints: status.eds.hidden_tests.hints,
},
};

let new_state =
Tutorial.state_of_spec(spec, ~settings, ~instructor_mode);
(word, new_state);
};

let updatedSlides = List.map(from_tup, slides);

Tutorial(name, updatedSlides);

| Exercises(n, specs, _) =>
Exercises(
n,
Expand All @@ -191,6 +277,7 @@ let reset_current =
let import_current = (~settings, editors: t, data: option(string)): t =>
switch (editors) {
| Documentation(_)
| Tutorial(_)
| Exercises(_) => failwith("impossible")
| Scratch(idx, slides) =>
switch (data) {
Expand All @@ -210,4 +297,5 @@ let switch_example_slide = (editors: t, name: string): option(t) =>
when !List.mem_assoc(name, slides) || cur == name =>
None
| Documentation(_, slides) => Some(Documentation(name, slides))
| Tutorial(_, slides) => Some(Tutorial(name, slides))
};
Loading

0 comments on commit 3f1838e

Please sign in to comment.