Skip to content

Commit

Permalink
Revert "feat: ファイルピッカーでのインポート機能を追加 (#10)" (#11)
Browse files Browse the repository at this point in the history
This reverts commit 04b0337.
  • Loading branch information
nandenjin authored Jan 24, 2025
1 parent 04b0337 commit 89ed485
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 29 deletions.
19 changes: 0 additions & 19 deletions src/components/ControlUI.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<template #loading>クリップボードを読み取り中……</template>
<template #completed>クリップボードからインポートしました</template>
</ButtonWithState>
<button @click="importFromFile">ファイルからインポート</button>
<button
@click="
confirm('リセットすると入力中のすべてのデータが破棄されます。') &&
Expand Down Expand Up @@ -37,24 +36,6 @@ const importFromClipboard = async () => {
.map((line) => line.split('\t'))
book.value = b
}
const importFromFile = async (event: Event) => {
const input = event.target as HTMLInputElement
if (!input.files?.length) return
const file = input.files[0]
const reader = new FileReader()
reader.onload = (e) => {
const text = (e.target?.result as string) || ''
try {
dataStore.importCSVString(text)
} catch (error) {
alert('ファイルを正しく読み取ることができませんでした。正しいファイルが選択されているか確認してください。');
console.error('Error importing CSV:', error)
}
}
reader.readAsText(file)
}
</script>

<style scoped>
Expand Down
6 changes: 5 additions & 1 deletion src/components/DragDropImporter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
import { useDataStore } from '../store/data'
import { storeToRefs } from 'pinia'
import { parse as parseCSV } from 'papaparse'
const dataStore = useDataStore()
const { book } = storeToRefs(dataStore)
const isDragging = ref(false)
Expand All @@ -24,7 +27,8 @@ const onDrop = (e: DragEvent) => {
const reader = new FileReader()
reader.addEventListener('load', (e) => {
const text = e.target?.result as string
dataStore.importCSVString(text)
const { data } = parseCSV<string[]>(text)
book.value = data
})
reader.readAsText(files[0])
}
Expand Down
9 changes: 0 additions & 9 deletions src/store/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
import { Transaction, TransactionCategory } from '../types/transaction'
import { replaceFullWidthWithHalfWidth } from '../lib/string'
import { parse as parseCSV } from 'papaparse'

/** 仕訳に応じて収支のセルの値を選択し返す
*
Expand Down Expand Up @@ -173,11 +172,6 @@ export const useDataStore = defineStore('data', () => {
)
}

const importCSVString = (csvString: string) => {
const { data } = parseCSV<string[]>(csvString)
book.value = data
}

return {
/** 団体名 */
orgName,
Expand Down Expand Up @@ -232,8 +226,5 @@ export const useDataStore = defineStore('data', () => {

/** ストアを初期状態を戻す */
reset,

/** CSV文字列をパースしてbookに設定する */
importCSVString,
}
})

0 comments on commit 89ed485

Please sign in to comment.