Skip to content

Commit

Permalink
fix again...
Browse files Browse the repository at this point in the history
  • Loading branch information
pyj-pd committed Nov 12, 2024
1 parent 0b6190c commit 0123386
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/components/picker/sections/NameSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DATA_ARE_SAVED_TEXT, NAME_LINE_BREAK } from '@/constants/seat'
import { useSectionNavigation } from '@/composables/useSectionNavigation'
import CheckboxInput from '@/components/common/CheckboxInput.vue'
import { useOptionStore } from '@/stores/useOptionStore'
import { ref } from 'vue'
const seatDataStore = useSeatDataStore(),
{ setNameData, clearNameData } = seatDataStore,
Expand All @@ -18,29 +19,40 @@ const optionStore = useOptionStore(),
const { setCurrentSectionId } = useSectionNavigation()
const textareaRef = ref<HTMLTextAreaElement | null>(null)
/**
* Detect if text input exceeds max line
* and trim if it does.
* @param event
*/
const validateTextarea = (event: Event) => {
const target = event.target as HTMLTextAreaElement
const lineSplit: string[] = target.value.split(NAME_LINE_BREAK)
const validateTextarea = () => {
const element = textareaRef.value
if (element === null) return
const lineSplit: string[] = element.value.split(NAME_LINE_BREAK)
// If line exceeds total seat number, don't.
if (lineSplit.length > totalSeatNumber.value) {
const { selectionStart, selectionEnd } = target
const { selectionStart, selectionEnd } = element
lineSplit.splice(totalSeatNumber.value)
target.value = lineSplit.join(NAME_LINE_BREAK)
target.setSelectionRange(selectionStart, selectionEnd)
element.value = lineSplit.join(NAME_LINE_BREAK)
element.setSelectionRange(selectionStart, selectionEnd)
}
}
const updateNameData = (event: Event) => {
validateTextarea(event)
setNameData((event.target as HTMLInputElement).value)
const updateNameData = () => {
const element = textareaRef.value
if (element === null) return
validateTextarea(element)
setNameData(element.value)
}
const moveToNextSection = () => {
updateNameData()
setCurrentSectionId('random-pick-seat')
}
</script>

Expand All @@ -61,6 +73,7 @@ const updateNameData = (event: Event) => {
</div>
</div>
<textarea
ref="textareaRef"
:class="$style.textarea"
:value="nameDataString"
@input="validateTextarea"
Expand All @@ -70,9 +83,7 @@ const updateNameData = (event: Event) => {
</div>
<ButtonContainer sticky>
<ShadowButton warning @click="clearNameData">이름 초기화</ShadowButton>
<ShadowButton @click="() => setCurrentSectionId('random-pick-seat')"
>뽑기 화면으로</ShadowButton
>
<ShadowButton @click="moveToNextSection">뽑기 화면으로</ShadowButton>
</ButtonContainer>
</main>
</template>
Expand Down

0 comments on commit 0123386

Please sign in to comment.