-
Notifications
You must be signed in to change notification settings - Fork 63
fix: fast username input bug fixed #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
719fe20
4ff011f
cca1b6e
c20f8b1
6ef7c51
993081e
91bdccf
a8c6955
91ea1c6
5042668
9bcaf51
f85b55b
219505f
b5063d3
6798046
a84c652
900a9ff
a085278
5c51588
5dabaf3
4fc1bcc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| :value="value ? value[field.name] : ''" | ||
| :item="value" | ||
| v-bind="field" | ||
| :error="usernameError" | ||
| :label="getLabel(field)" | ||
| @input="(val) => onFieldChange(field, val)" | ||
| /> | ||
|
|
@@ -32,9 +33,18 @@ | |
|
|
||
| <script> | ||
| import { camelcase } from '~/utils' | ||
| import { useDoc } from '~/use/doc' | ||
|
|
||
| export default { | ||
| name: 'TForm', | ||
| setup() { | ||
| const { find, id } = useDoc('profiles') | ||
|
|
||
| return { | ||
| find, | ||
| id | ||
| } | ||
| }, | ||
| components: { | ||
| TField: () => import('~/components/TField') | ||
| }, | ||
|
|
@@ -77,7 +87,8 @@ export default { | |
| } | ||
| }, | ||
| data: () => ({ | ||
| error: false | ||
| error: false, | ||
| usernameError: '' | ||
| }), | ||
| computed: { | ||
| visibleFields() { | ||
|
|
@@ -136,18 +147,26 @@ export default { | |
|
|
||
| this.$emit('copy', this.value) | ||
| }, | ||
| save() { | ||
| async save() { | ||
| this.error = false | ||
|
|
||
| if (!this.validate()) { | ||
| return | ||
| } | ||
|
|
||
| await this.find('username', this.value.username) | ||
|
|
||
| if (this.id && this.id !== this.value.id) { | ||
| this.usernameError = 'This name is already taken' | ||
| this.$emit('input', this.value) | ||
| return | ||
| } | ||
|
|
||
| this.$emit('save', this.value) | ||
| }, | ||
| onFieldChange(field, value) { | ||
| this.usernameError = '' | ||
| const val = { ...this.value } | ||
|
|
||
| if (value) { | ||
| this.$set(val, field.name, value) | ||
| } else { | ||
|
|
@@ -157,7 +176,6 @@ export default { | |
| if (field && field.onChange) { | ||
| field.onChange(val) | ||
| } | ||
|
|
||
| this.$emit('input', val) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is probably used somewhere, did you check?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i did and form seems to function the same without it
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check commit where this line was added and see why
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems redundant since inline emit in another file
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sets a new value for the form, whenever any field is changed. If this event is not emitted |
||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,18 +11,8 @@ | |
| </template> | ||
|
|
||
| <script> | ||
| import { useDoc } from '~/use/doc' | ||
|
|
||
| export default { | ||
| name: 'TInputUsername', | ||
| setup() { | ||
| const { find, id } = useDoc('profiles') | ||
|
|
||
| return { | ||
| find, | ||
| id | ||
| } | ||
| }, | ||
| inheritAttrs: false, | ||
| props: { | ||
| value: { | ||
|
|
@@ -36,11 +26,14 @@ export default { | |
| item: { | ||
| type: Object, | ||
| default: () => ({}) | ||
| }, | ||
| error: { | ||
| type: String, | ||
| default: '' | ||
| } | ||
| }, | ||
| data: () => ({ | ||
| computedValue: '', | ||
| error: '' | ||
| computedValue: '' | ||
| }), | ||
| watch: { | ||
| value(val) { | ||
|
|
@@ -53,21 +46,11 @@ export default { | |
| this.computedValue = this.value | ||
| }, | ||
| methods: { | ||
| async save(newName) { | ||
| this.error = '' | ||
|
|
||
| save(newName) { | ||
| if (newName === this.value) { | ||
| return | ||
| } | ||
|
|
||
| await this.find('username', newName) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe you can just put this code inside a new method |
||
|
|
||
| if (this.id && this.id !== this.item.id) { | ||
| this.error = 'This name is already taken' | ||
| this.$emit('input', this.value) | ||
| return | ||
| } | ||
|
|
||
| this.$emit('input', newName) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ | |
| </div> | ||
| </TPopup> | ||
|
|
||
| <TPopup v-else-if="slide == 2" @close="close"> | ||
| <TPopup v-else-if="slide === 2" @close="close"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this change is not part of this issue |
||
| <div class="p-4 text-center"> | ||
| <TIcon class="w-64" name="undraw_work_chat" /> | ||
| <div class="mt-8 w-64"> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a form components, username is not always one of the fields of the form