Skip to content

Commit

Permalink
UX optimizations for words navigation block
Browse files Browse the repository at this point in the history
  • Loading branch information
super16 committed Jan 28, 2023
1 parent 07041a1 commit 11ab8f9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/components/AlphabetList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const { currentLetter } = storeToRefs(store);
</script>

<template>
<nav>
<nav class="flex justify-center">
<ul class="flex flex-wrap">
<li
v-for="letter in alphabet"
Expand Down
4 changes: 1 addition & 3 deletions src/components/NavigationHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ const { showInfo } = storeToRefs(store);
</svg>
</div>
</div>
<div class="flex justify-center">
<AlphabetList />
</div>
<AlphabetList />
</header>
</template>
23 changes: 13 additions & 10 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import TheWordMain from '@/components/TheWordMain.vue';
export default createRouter({
history: createWebHistory('/eesti/'),
scrollBehavior(to) {
if (to.name === 'wordsList') {
const start = document.getElementById('start');
if (start) {
start.scrollIntoView({ behavior: 'smooth' });
return new Promise((resolve) => {
if (to.name === 'wordsList') {
const start = document.getElementById('start');
if (start) {
start.scrollIntoView({ behavior: 'smooth' });
}
} else if (to.name === 'exactWord') {
const definitionStart = document.getElementById('definition');
if (definitionStart) {
definitionStart.scrollIntoView({ behavior: 'smooth' });
}
}
} else if (to.name === 'exactWord') {
const definitionStart = document.getElementById('definition');
if (definitionStart) {
definitionStart.scrollIntoView({ behavior: 'smooth' });
}
}
resolve();
});
},
routes: [
{
Expand Down
16 changes: 11 additions & 5 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { defineStore } from 'pinia';
import wordsFilter from '@/utils/wordsFilter';
import domCleaner from '@/utils/domCleaner';
import {
CategoryMemberObject,
ParseParams,
QueryParams,
SectionObject,
Expand Down Expand Up @@ -39,6 +40,13 @@ export const mainStore = defineStore('main', {
};
},
actions: {
addWords(filteredWords: CategoryMemberObject[]) {
filteredWords.forEach((fWord: CategoryMemberObject) => {
window.requestAnimationFrame(() => {
this.words.push(fWord);
});
});
},
async getWords(letter: string): Promise<void> {
const params: QueryParams = {
cmstartsortkeyprefix: letter,
Expand All @@ -47,17 +55,15 @@ export const mainStore = defineStore('main', {
let response = await axios.get('', { params });
let data = response.data;
let categoryMembers = data.query.categorymembers;
this.words = wordsFilter(categoryMembers, letter);
this.words = [];
this.addWords(wordsFilter(categoryMembers, letter));
let lastElement = categoryMembers[categoryMembers.length - 1];
while (data && lastElement?.title.startsWith(letter)) {
params.cmcontinue = data.continue.cmcontinue;
response = await axios.get('', { params });
data = response.data;
categoryMembers = data.query.categorymembers;
this.words = [
...this.words,
...wordsFilter(categoryMembers, letter),
];
this.addWords(wordsFilter(categoryMembers, letter));
lastElement = categoryMembers[categoryMembers.length - 1];
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ export interface StoreState {
currentPageId: number | null,
currentWord: string,
showInfo: boolean,
words: CategoryMemberObject[] | [];
words: CategoryMemberObject[];
}

0 comments on commit 11ab8f9

Please sign in to comment.