Skip to content

Commit

Permalink
add save method
Browse files Browse the repository at this point in the history
  • Loading branch information
mioe committed May 23, 2024
1 parent 742acbb commit 8766e4f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ async function handleColumnEdit(ev, rowId, colIdx, val) {
async function handleSave() {
console.log('🦕 handleSave')
const invalidColumns = table.columns.map((col, idx) => col ? null : idx).filter(colIdx => colIdx)
const bodyCsv = JSON.parse(JSON.stringify(csv.value))
.map(row => row.filter((_col, colIdx) => !invalidColumns.includes(colIdx - HIDDEN_COL)))
const headerCsv = table.columns.filter(col => col).map(col => col.id)
const data = [
['uuid', ...headerCsv],
...bodyCsv,
]
await fetch('/', {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8',
},
body: JSON.stringify(data),
})
}
watch(
Expand Down
2 changes: 1 addition & 1 deletion src/components/EditorHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const { toggleLocales } = useLocaleStore()
</button>
</div>
<div class="flex flex-wrap gap-2">
<button @click="save">
<button @click="$emit('save')">
{{ $t('save') }}
</button>
<button @click="toggleLocales">
Expand Down

0 comments on commit 8766e4f

Please sign in to comment.