Skip to content

Commit

Permalink
Merge pull request #92 from takanotume24/bug/90__file_list_has_not_be…
Browse files Browse the repository at this point in the history
…en_reset

feat: Update ChatInputForm and FileSelector components for v-model bi…
  • Loading branch information
takanotume24 authored Dec 4, 2024
2 parents 566ccc2 + 5d00c01 commit 43229a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
5 changes: 1 addition & 4 deletions src/components/ChatInputForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@keydown="checkCtrlEnter"></textarea>
</div>
<div class="d-flex justify-content-between align-items-center">
<FileSelector @files-selected="handleFilesSelected" />
<FileSelector v-model="selectedFiles"/>
<button type="submit" class="btn btn-primary">Send</button>
</div>
</form>
Expand Down Expand Up @@ -51,9 +51,6 @@ export default defineComponent({
this.handleSubmit();
}
},
handleFilesSelected(files: File[]) {
this.selectedFiles = files;
},
},
mounted() {
Expand Down
24 changes: 17 additions & 7 deletions src/components/FileSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,30 @@
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';
import { defineComponent, ref, watch } from 'vue';
export default defineComponent({
emits: ['files-selected'],
setup(_, { emit }) {
const selectedFiles = ref<File[]>([]);
props: {
modelValue: {
type: Array as () => File[],
default: () => []
}
},
emits: ['update:modelValue'],
setup(props, { emit }) {
const fileNames = ref<string[]>([]);
const fileInput = ref<HTMLInputElement | null>(null);
// Watch for changes in modelValue and update fileNames
watch(() => props.modelValue, (newFiles) => {
fileNames.value = newFiles.map(file => file.name);
}, { immediate: true });
const handleFileChange = (event: Event) => {
const target = event.target as HTMLInputElement;
if (target.files) {
selectedFiles.value = Array.from(target.files);
fileNames.value = selectedFiles.value.map(file => file.name);
emit('files-selected', selectedFiles.value);
const files = Array.from(target.files);
emit('update:modelValue', files);
}
};
Expand All @@ -49,4 +58,5 @@ export default defineComponent({
});
</script>


<style scoped></style>

0 comments on commit 43229a7

Please sign in to comment.