Skip to content

Commit b97f5b9

Browse files
Reorganize components (#17)
* reorganize components again * wip * Update form.ts * fix check errors * wip
1 parent d75fca8 commit b97f5b9

File tree

46 files changed

+289
-323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+289
-323
lines changed

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"editor.defaultFormatter": "esbenp.prettier-vscode",
3+
"editor.insertSpaces": true,
4+
"editor.tabSize": 2,
5+
"files.eol": "\n",
6+
"[svelte]": {
7+
"editor.defaultFormatter": "svelte.svelte-vscode"
8+
}
9+
}

src/lib/components/form/form.svelte

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script lang="ts">
22
import type { User, Form } from '$lib/store';
3-
import QuestionInput from '$lib/components/form/question_input/question_input.svelte';
3+
import QuestionInput from '$lib/components/question_input/question_input.svelte';
44
5-
export let data: Form;
6-
export let user: User | undefined = undefined;
75
export let action = '';
86
export let method = 'POST';
7+
export let data: Form;
8+
export let user: User | undefined = undefined;
99
1010
if (data.questions.shuffled) {
1111
data.questions.data = data.questions.data.sort(() => Math.random() - 0.5);
@@ -27,16 +27,16 @@
2727
{/if}
2828
</p>
2929

30-
{#if data.schedule?.startDate}
31-
<p>Opened at: {data.schedule?.startDate}</p>
30+
{#if data.startDate}
31+
<p>Opened at: {data.startDate}</p>
3232
{/if}
33-
{#if data.schedule?.endDate}
34-
<p>Opened until: {data.schedule?.endDate}</p>
33+
{#if data?.endDate}
34+
<p>Opened until: {data?.endDate}</p>
3535
{/if}
3636
</div>
3737
</div>
3838
{#each data.questions.data as question}
39-
<QuestionInput data={question} />
39+
<QuestionInput {...question} />
4040
{/each}
4141

4242
<button type="submit">Submit</button>

src/lib/components/form/form_editor/form_editor.svelte

Lines changed: 0 additions & 108 deletions
This file was deleted.

src/lib/components/form/question_input/question_input.svelte

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/lib/components/form/question_input_editor/question_base_input.svelte

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<script lang="ts">
2+
import type { Form } from '$lib/store';
3+
import { QuestionType } from '$lib/form';
4+
import QuestionInput from '$lib/components/question_input/question_input.svelte';
5+
import QuestionListEditor from './question_list_editor/question_list_editor.svelte';
6+
7+
export let action: string;
8+
export let method: string;
9+
export let value: Form;
10+
11+
// TODO: Add discord data: channels, threads, guilds, roles.
12+
</script>
13+
14+
<form {action} {method}>
15+
<div class="form-header">
16+
<h1>Form editor</h1>
17+
<p class="form-description">Edit a form!</p>
18+
<hr />
19+
<div class="form-information">
20+
<p>Form ID: {value.id}</p>
21+
</div>
22+
</div>
23+
24+
<QuestionInput type={QuestionType.TEXT} name="title" content="Title" bind:value={value.title} />
25+
26+
<QuestionInput
27+
type={QuestionType.TEXTAREA}
28+
name="description"
29+
content="Description"
30+
bind:value={value.description}
31+
/>
32+
33+
<QuestionInput
34+
type={QuestionType.DATETIME}
35+
name="startDate"
36+
content="Start date"
37+
bind:value={value.startDate}
38+
/>
39+
40+
<QuestionInput
41+
type={QuestionType.DATETIME}
42+
name="endDate"
43+
content="End date"
44+
bind:value={value.endDate}
45+
/>
46+
47+
<QuestionInput
48+
type={QuestionType.TIMEZONE}
49+
name="timezone"
50+
content="Timezone (default: UTC/GMT)"
51+
bind:value={value.timezone}
52+
/>
53+
54+
<QuestionInput
55+
type={QuestionType.BOOLEAN}
56+
name="anonymized"
57+
content="Anonymized"
58+
bind:value={value.anonymized}
59+
/>
60+
61+
<QuestionInput
62+
type={QuestionType.BOOLEAN}
63+
name="shuffled"
64+
content="Shuffled"
65+
bind:value={value.questions.shuffled}
66+
/>
67+
68+
<QuestionListEditor bind:value={value.questions} />
69+
70+
<button type="submit">Submit</button>
71+
</form>
72+
73+
<style>
74+
form {
75+
display: flex;
76+
flex-direction: column;
77+
justify-content: center;
78+
align-items: center;
79+
margin: 0 auto;
80+
max-width: 400px;
81+
}
82+
</style>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script lang="ts">
2+
import type { QuestionBase } from '$lib/form';
3+
import { QuestionType } from '$lib/form';
4+
import QuestionInput from '$lib/components/question_input/question_input.svelte';
5+
6+
export let value: QuestionBase;
7+
</script>
8+
9+
<input type="hidden" name="type" value={value.type} />
10+
11+
<QuestionInput
12+
type={QuestionType.TEXT}
13+
name="name"
14+
content="The unique identifier for the question."
15+
bind:value={value.name}
16+
/>
17+
18+
<QuestionInput
19+
type={QuestionType.TEXTAREA}
20+
name="content"
21+
content="The markdown question content for the form field."
22+
bind:value={value.content}
23+
/>
24+
25+
<QuestionInput
26+
type={QuestionType.BOOLEAN}
27+
name="required"
28+
content="Whether or not the form field is required."
29+
bind:value={value.required}
30+
/>

src/lib/components/form/question_input_editor/question_input_editor.svelte renamed to src/lib/components/form_editor/question_input_editor/question_input_editor.svelte

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
// export let value: Question;
66
</script>
77

8-
<!-- <QuestionInput
9-
data={{
10-
type: value.type,
11-
name: value.name,
12-
content: value.content,
13-
value: value.value
14-
}}
15-
/> -->
8+
<!-- TODO: Reconcile changes made in
9+
https://github.com/acmcsufoss/form/pull/new/question-input-editor -->
10+
11+
<!-- TODO: Make a new PR out of this current branch. -->

src/lib/components/form/question_list_editor/add_item.svelte renamed to src/lib/components/form_editor/question_list_editor/add_item.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
// TODO: Add a helper function to create a blank question object for each type.
1111
addAction({ type });
1212
}
13+
14+
// function makeDefault(type: QuestionType): Question {
15+
// switch...
16+
// }
1317
</script>
1418

1519
<select bind:value={type}>

src/lib/components/form/question_list_editor/delete_item.svelte renamed to src/lib/components/form_editor/question_list_editor/delete_item.svelte

File renamed without changes.

0 commit comments

Comments
 (0)