From 27b41a4523a816e4c1600f432306b3da1e7b51ab Mon Sep 17 00:00:00 2001 From: Badri Sunderarajan Date: Fri, 28 May 2021 20:45:56 +0530 Subject: [PATCH] Allow re-editing draft after table has been generated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This does two things: 1. If the TKs in the draft has changed, add/remove the corresponding columns from the table 2. Either way, update the preview so it matches the draft text All this only happens once you click the "Refresh" button, because we don't want to be putting *too much* load on the app also 😜 --- src/App.svelte | 66 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index a60e09b..e771027 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -73,6 +73,63 @@ window.sheetOne = sheetOne } + /** + * Refresh sheet + * + * Destroys the current sheet, but saves the data first so if + * there are any columns in the new sheet that matches the old + * ones, it'll add them back. (Columns meaning TKs, of course) + */ + + function refreshSheet() { + let oldData = sheetOne.getData() + let oldColumns = sheetOne.columns.map(c => c.label) + + sheetOne.destroy() + + // now, make it up again with the new TKs + showSheet() + + // figure out the new data + let newData = [] + let tkOrder = [] + + // first, we figure out how the old column order corresponds to + // the new one + + for (let col of sheetOne.columns.map(c => c.label)) { + tkOrder.push(oldColumns.indexOf(col)) + } + + // now we fill this, row by row + for (let oldRow of oldData) { + + // skip empty rows + if (oldRow.every(v => !v)) continue + + // now, we figure out what to put for the new row + let newRow = [] + for (let tkIndex of tkOrder) { + if (tkIndex <= -1) { + // new TK; leave it blank + newRow.push('') + } else { + // old TK; keep it filled! + newRow.push(oldRow[tkIndex]) + } + } + + // and finally, when all is done, we save it. + newData.push(newRow) + } + + // fill it with the new data + sheetOne.setData(newData) + + // don't forget to refresh the preview! + cookiePreviewText = getPreview() + } + function incrementPreviewRow() { let sheetLength = sheetOne.getData().length @@ -144,7 +201,7 @@ {/if} - {#if step == 1} + {#if step >= 1}

Compose your email below, leaving [TK stuff] to be replaced in the table. Make sure each TK is a single word: no spaces allowed!

@@ -164,12 +221,17 @@

Now, fill in the fields for each user. (You can also copy-paste rows and columns directly from Air, if the ordering is right!)

{/if} -
{#if step == 1} {/if} + {#if step > 1} + + {/if} + +
+ {#if step == 2 && !!cookiePreviewText}

Preview