Prettify preview and add "From" option

This commit is contained in:
Badri Sunderarajan 2021-05-28 21:37:04 +05:30
parent 27b41a4523
commit a56e9cd9c2

View file

@ -12,7 +12,9 @@
let step = 0 let step = 0
let tkList = [] let tkList = []
let cookiePreviewText = '' let fromEmail = ''
let cookiePreviewData = { text: '', email: ''}
let cookiePreviewRow = 0 let cookiePreviewRow = 0
function showEmail() { function showEmail() {
@ -63,7 +65,7 @@
node: editor, node: editor,
columns: columns, columns: columns,
onChange(data) { onChange(data) {
cookiePreviewText = getPreview() cookiePreviewData = getPreview()
} }
}) })
@ -127,7 +129,7 @@
sheetOne.setData(newData) sheetOne.setData(newData)
// don't forget to refresh the preview! // don't forget to refresh the preview!
cookiePreviewText = getPreview() cookiePreviewData = getPreview()
} }
function incrementPreviewRow() { function incrementPreviewRow() {
@ -171,17 +173,20 @@
for (let tk of tkList) { for (let tk of tkList) {
// figure out which column holds values for this TK // figure out which column holds values for this TK
let tkIndex = window.sheetOne.columns.findIndex(t => t.label == tk) let tkIndex = sheetOne.columns.findIndex(t => t.label == tk)
// replace it! // replace it!
previewText = previewText.replace(new RegExp(`\\[TK ${tk}\\]`, 'g'), r[tkIndex]) previewText = previewText.replace(new RegExp(`\\[TK ${tk}\\]`, 'g'), r[tkIndex])
} }
return previewText // save the email
let previewEmail = r[sheetOne.columns.findIndex(t => t.label == 'email')]
return { text: previewText, email: previewEmail }
} }
// automatically update // automatically update
$: cookiePreviewText = getPreview(cookiePreviewRow) $: cookiePreviewData = getPreview(cookiePreviewRow)
function next() { function next() {
step += 1 step += 1
@ -205,7 +210,9 @@
<div class="instructions"> <div class="instructions">
<p>Compose your email below, leaving [TK stuff] to be replaced in the table. Make sure each TK is a single word: no spaces allowed!</p> <p>Compose your email below, leaving [TK stuff] to be replaced in the table. Make sure each TK is a single word: no spaces allowed!</p>
</div> </div>
<div class="email-content"> <div class="email-content">
<p>From: <input type="text" bind:value={fromEmail}/></p>
<textarea bind:value={emailContent}/> <textarea bind:value={emailContent}/>
<p> <p>
<strong>Detected fields:</strong> <strong>Detected fields:</strong>
@ -298,5 +305,7 @@
text-align: left; text-align: left;
max-width: 640px; max-width: 640px;
margin: auto; margin: auto;
padding: 1em;
border: 1px solid black;
} }
</style> </style>