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