From cc8d6a3f23ea79817a4c0864985b1396a75d25e2 Mon Sep 17 00:00:00 2001
From: andrei
Date: Wed, 21 May 2025 19:28:57 +0200
Subject: [PATCH 01/16] Changed the Email Writer to support several forms that
get submitted individually. This version is incomplete, as the backend logic
has not yet been updated.
---
src/routes/write/+page.svelte | 305 +++++++++++++++++++++++++++-------
1 file changed, 244 insertions(+), 61 deletions(-)
diff --git a/src/routes/write/+page.svelte b/src/routes/write/+page.svelte
index 476b9a3f2..f88cfb87a 100644
--- a/src/routes/write/+page.svelte
+++ b/src/routes/write/+page.svelte
@@ -34,7 +34,7 @@
const maxMessages = 20
// Organizing the form questions into sections and subsections
- const formSections: FieldSection[] = [
+ const formSections_Target: FieldSection[] = [
{
title: 'Personal Context',
subsections: [
@@ -92,27 +92,47 @@
]
}
]
- },
+ }
+ ]
+
+ // Flatten the questions array for accessing by index
+ const paragraphText_Target: string[] = []
+ formSections_Target.forEach((section) => {
+ section.subsections.forEach((subsection) => {
+ subsection.questions.forEach((question) => {
+ paragraphText_Target.push(question)
+ })
+ })
+ })
+
+ const formSections_Research: FieldSection[] = [
{
- title: 'Information Needed About the Message',
+ title: 'Finding a target',
subsections: [
{
- title: 'Content Requirements',
- questions: ['Specific outcome desired', 'Concrete action requested'] /*
+ title: "Specify what sort of target you're looking for, and where.",
questions: [
- 'Clear, singular objective',
- 'Specific outcome desired',
- 'Concrete action requested'
- ]*/
- },
- {
- title: 'Supporting Evidence',
- questions: [
- 'Relevant facts',
- 'Context for the request',
- 'Potential impact or consequences'
+ 'If you have certain institutions in mind, mention those. Otherwise, your local representative could be a good place to start.'
]
- },
+ }
+ ]
+ }
+ ]
+
+ // Flatten the questions array for accessing by index
+ const paragraphText_Research: string[] = []
+ formSections_Research.forEach((section) => {
+ section.subsections.forEach((subsection) => {
+ subsection.questions.forEach((question) => {
+ paragraphText_Research.push(question)
+ })
+ })
+ })
+
+ const formSections_MessageDetails: FieldSection[] = [
+ {
+ title: 'The Message',
+ subsections: [
{
title: 'Logical Structure',
questions: [
@@ -165,11 +185,46 @@
]
// Flatten the questions array for accessing by index
- const paragraphText: string[] = []
- formSections.forEach((section) => {
+ const paragraphText_MessageDetails: string[] = []
+ formSections_Research.forEach((section) => {
+ section.subsections.forEach((subsection) => {
+ subsection.questions.forEach((question) => {
+ paragraphText_MessageDetails.push(question)
+ })
+ })
+ })
+
+ const formSections_Message: FieldSection[] = [
+ {
+ title: 'What is your Message?',
+ subsections: [
+ {
+ title: 'Content Requirements',
+ questions: ['Specific outcome desired', 'Concrete action requested'] /*
+ questions: [
+ 'Clear, singular objective',
+ 'Specific outcome desired',
+ 'Concrete action requested'
+ ]*/
+ },
+ {
+ title: 'Supporting Evidence',
+ questions: [
+ 'Relevant facts',
+ 'Context for the request',
+ 'Potential impact or consequences'
+ ]
+ }
+ ]
+ }
+ ]
+
+ // Flatten the questions array for accessing by index
+ const paragraphText_Message: string[] = []
+ formSections_Message.forEach((section) => {
section.subsections.forEach((subsection) => {
subsection.questions.forEach((question) => {
- paragraphText.push(question)
+ paragraphText_Message.push(question)
})
})
})
@@ -203,11 +258,11 @@
clear_arr(input_arr)
// Find index for specific fields based on their question text
- const roleAuthorityIndex = paragraphText.findIndex(
+ const roleAuthorityIndex = paragraphText_Target.findIndex(
(q) => q === 'Understanding their role and potential authority'
)
- const objectiveIndex = paragraphText.findIndex((q) => q === 'Concrete action requested')
- const outcomeIndex = paragraphText.findIndex((q) => q === 'Specific outcome desired')
+ const objectiveIndex = paragraphText_Target.findIndex((q) => q === 'Concrete action requested')
+ const outcomeIndex = paragraphText_Target.findIndex((q) => q === 'Specific outcome desired')
input_arr[roleAuthorityIndex] = 'You are writing for a child of about thirteen years old.'
input_arr[objectiveIndex] =
@@ -220,8 +275,8 @@
async function sendMessage() {
let input = ''
- for (var i in paragraphText) {
- input = input + paragraphText[i] + ':\n' + input_arr[i] + '\n\n'
+ for (var i in paragraphText_Target) {
+ input = input + paragraphText_Target[i] + ':\n' + input_arr[i] + '\n\n'
}
messages = [...messages, { content: input, role: 'user' }]
@@ -339,8 +394,10 @@
let currentField = -1
for (let line of lines) {
- // Look for field headers matching our paragraphText array
- const fieldIndex = paragraphText.findIndex((text) => line.trim().startsWith(text + ':'))
+ // Look for field headers matching our paragraphText_Target array
+ const fieldIndex = paragraphText_Target.findIndex((text) =>
+ line.trim().startsWith(text + ':')
+ )
if (fieldIndex >= 0) {
currentField = fieldIndex
@@ -399,9 +456,33 @@
// Function to get the index of a question across all sections
function getQuestionIndex(question: string): number {
- return paragraphText.findIndex((text) => text === question)
+ return paragraphText_Target.findIndex((text) => text === question)
}
+ // FORM FUNCTIONS //
+
+ // Add these variables for form toggling
+ let activeForm = 'form1' // Default active form
+
+ // Function to set the active form
+ function setActiveForm(formId) {
+ activeForm = formId
+ console.log(formId)
+ }
+
+ // UNTESTED AND GENERATED BY AI
+ // Create separate arrays for each form's inputs
+ //let input_arr = Array(formSections_Target.flatMap(s => s.subsections.flatMap(ss => ss.questions)).length).fill('');
+ let form2_input_arr = Array(
+ formSections_Target.flatMap((s) => s.subsections.flatMap((ss) => ss.questions)).length
+ ).fill('')
+ let form3_input_arr = Array(
+ formSections_Target.flatMap((s) => s.subsections.flatMap((ss) => ss.questions)).length
+ ).fill('')
+ let form4_input_arr = Array(
+ formSections_Target.flatMap((s) => s.subsections.flatMap((ss) => ss.questions)).length
+ ).fill('')
+
// Top of the page
const title = `Write Email Content`
const description = `This (beta!) webpage lets you write email content (with LLM assistance.)`
@@ -453,6 +534,34 @@
particular hardcoded values, and starts writing content.
+
+
+
+
+
+
+
+