mirror of
https://github.com/Spythere/pojazdownik.git
synced 2026-05-05 12:28:12 +00:00
keydown hotfix
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
<div class="section_modes">
|
<div class="section_modes">
|
||||||
<button
|
<button
|
||||||
class="btn"
|
class="btn"
|
||||||
|
ref="sectionButtonRefs"
|
||||||
v-for="(id, name, i) in sectionModes"
|
v-for="(id, name, i) in sectionModes"
|
||||||
@click="chooseSection(id)"
|
@click="chooseSection(id)"
|
||||||
:data-selected="store.stockSectionMode == id"
|
:data-selected="store.stockSectionMode == id"
|
||||||
@@ -21,13 +22,15 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, KeepAlive, onMounted } from 'vue';
|
import { computed, KeepAlive, onMounted, ref } from 'vue';
|
||||||
import { useStore } from '../../store';
|
import { useStore } from '../../store';
|
||||||
import StockListTab from '../tabs/StockListTab.vue';
|
import StockListTab from '../tabs/StockListTab.vue';
|
||||||
import StockGeneratorTab from '../tabs/StockGeneratorTab.vue';
|
import StockGeneratorTab from '../tabs/StockGeneratorTab.vue';
|
||||||
import NumberGeneratorTab from '../tabs/NumberGeneratorTab.vue';
|
import NumberGeneratorTab from '../tabs/NumberGeneratorTab.vue';
|
||||||
import WikiListTab from '../tabs/WikiListTab.vue';
|
import WikiListTab from '../tabs/WikiListTab.vue';
|
||||||
|
|
||||||
|
const sectionButtonRefs = ref([]);
|
||||||
|
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
type SectionMode = typeof store.stockSectionMode;
|
type SectionMode = typeof store.stockSectionMode;
|
||||||
|
|
||||||
@@ -38,13 +41,27 @@ const sectionModes: { [key: string]: SectionMode } = {
|
|||||||
'GNR SKŁADU': 'stock-generator',
|
'GNR SKŁADU': 'stock-generator',
|
||||||
};
|
};
|
||||||
|
|
||||||
const sectionKeyIndexes: { [key: string]: SectionMode } = {
|
const sectionKeyIndexes: { [key: number]: SectionMode } = {
|
||||||
'1': 'stock-list',
|
1: 'stock-list',
|
||||||
'2': 'wiki-list',
|
2: 'wiki-list',
|
||||||
'3': 'number-generator',
|
3: 'number-generator',
|
||||||
'4': 'stock-generator',
|
4: 'stock-generator',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
console.log(sectionButtonRefs.value);
|
||||||
|
|
||||||
|
window.addEventListener('keydown', (e) => {
|
||||||
|
if (e.target instanceof HTMLInputElement) return;
|
||||||
|
|
||||||
|
if (e.key == '1' || e.key == '2' || e.key == '3' || e.key == '4') {
|
||||||
|
const keyNum = Number(e.key);
|
||||||
|
store.stockSectionMode = sectionKeyIndexes[keyNum];
|
||||||
|
(sectionButtonRefs.value[keyNum - 1] as HTMLButtonElement).focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const chosenSectionComponent = computed(() => {
|
const chosenSectionComponent = computed(() => {
|
||||||
switch (store.stockSectionMode) {
|
switch (store.stockSectionMode) {
|
||||||
case 'stock-list':
|
case 'stock-list':
|
||||||
@@ -67,14 +84,6 @@ const chosenSectionComponent = computed(() => {
|
|||||||
function chooseSection(sectionId: SectionMode) {
|
function chooseSection(sectionId: SectionMode) {
|
||||||
store.stockSectionMode = sectionId;
|
store.stockSectionMode = sectionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
window.addEventListener('keydown', (e) => {
|
|
||||||
if (e.key == '1' || e.key == '2' || e.key == '3' || e.key == '4') {
|
|
||||||
store.stockSectionMode = sectionKeyIndexes[e.key];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
|||||||
Reference in New Issue
Block a user