Skip to content

Commit

Permalink
Fix a bunch of shit, hopefully
Browse files Browse the repository at this point in the history
  • Loading branch information
lyssieth committed Jan 6, 2024
1 parent 97227ef commit 01d9e59
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
5 changes: 5 additions & 0 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
>on one of these places I exist on</a
>.
</p>
<p>
Currently, entering Edit Mode forcibly refreshes the display without giving
a prompt to save first. Please be aware of this and don't edit a template
while filling it in.
</p>
<hr />
<div id="questionnaire">
<Controls />
Expand Down
9 changes: 9 additions & 0 deletions src/lib/Controls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@
return template.name;
}
}
editMode.subscribe((v) => {
if (v && $current) {
current.update((v) => v); // noop just to trigger the update
if ($current.author instanceof Object)
$current.author = $current.author.name; // remove the link so nobody can claim it's an official template
}
});
</script>

<div class="controls">
Expand Down
28 changes: 22 additions & 6 deletions src/lib/Question.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<script lang="ts">
import EditableText from "./EditableText.svelte";
import QuestionTitle from "./QuestionTitle.svelte";
import { editMode } from "./store";
import { current, editMode } from "./store";
import type { TemplateQuestion } from "./types/template";
let self: HTMLLIElement | null;
export let question: TemplateQuestion;
export let questionChanged: (
question: TemplateQuestion,
hasValue: boolean
) => void;
let changed = false;
let qChanged = false;
const { type, placeholder } = question;
const rows = {
Expand All @@ -23,17 +24,32 @@
const el = evt.target as HTMLInputElement | HTMLTextAreaElement;
if (el.value.length === 0) {
changed = false;
qChanged = false;
questionChanged(question, false);
return;
}
changed = true;
qChanged = true;
questionChanged(question, true);
}
current.subscribe(() => {
qChanged = false;
if (self) {
const inputElement = self.querySelector(".answer");
if (
inputElement instanceof HTMLInputElement ||
inputElement instanceof HTMLTextAreaElement
) {
inputElement.value = "";
}
}
});
</script>

<li class="question" data-question="{question.question}">
<li class="question" data-question="{question.question}" bind:this="{self}">
{#if $editMode}
<div class="editable-block">
<h3>Title</h3>
Expand Down Expand Up @@ -66,7 +82,7 @@
</div>
{:else}
<label>
<QuestionTitle {changed}
<QuestionTitle changed="{qChanged}"
><EditableText bind:value="{question.question}" />
<slot /></QuestionTitle
>
Expand Down
7 changes: 2 additions & 5 deletions src/lib/Questionnaire.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@
});
}
editMode.subscribe((v) => {
if (v && $current) {
if ($current.author instanceof Object)
$current.author = $current.author.name; // remove the link so nobody can claim it's an official template
}
current.subscribe(() => {
sectionMap = new Map();
});
</script>

Expand Down
13 changes: 9 additions & 4 deletions src/lib/Section.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
let questionMap: Map<string, boolean> = new Map(
section.questions.map((q) => [q.question, false])
);
let changed = false;
let sChanged = false;
let count = 0;
function anyHasValue() {
Expand All @@ -24,8 +24,7 @@
function questionChanged(question: TemplateQuestion, hasValue: boolean) {
questionMap.set(question.question, hasValue);
changed = anyHasValue();
// TODO: make it mark the section as changed somehow
sChanged = anyHasValue();
sectionChanged(section, anyHasValue());
count = Array.from(questionMap.values()).filter((v) => v).length;
Expand All @@ -52,11 +51,17 @@
return c;
});
}
current.subscribe(() => {
questionMap = new Map(section.questions.map((q) => [q.question, false]));
sChanged = false;
count = 0;
});
</script>

<details class="section" data-section="{section.title}">
<summary title="Click to expand/collapse">
<SectionTitle {changed}
<SectionTitle changed="{sChanged}"
><EditableText bind:value="{section.title}" /> ({count}/{section.questions
.length}) <slot /></SectionTitle
>
Expand Down

0 comments on commit 01d9e59

Please sign in to comment.