Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/develop' into corpus-que…
Browse files Browse the repository at this point in the history
…ry-component

Add typing to corpus-text.vue
  • Loading branch information
simar0at committed Nov 24, 2023
2 parents b38a84c + 44aa07f commit dd261d7
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 83 deletions.
63 changes: 1 addition & 62 deletions components/app-navigation-menu.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script lang="ts" setup>
import { AppWindowIcon, CheckIcon } from "lucide-vue-next";
import type { ItemType, MainItemType } from "@/lib/api-client";
const props = defineProps<{
Expand All @@ -13,13 +11,6 @@ const emit = defineEmits<{
const { menus } = toRefs(props);
const router = useRouter();
const route = useRoute();
const windowsStore = useWindowsStore();
const { setWindowArrangement } = windowsStore;
const { arrangement: currentArrangement, registry } = storeToRefs(windowsStore);
const currentMenu = ref("");
function close() {
Expand Down Expand Up @@ -58,58 +49,6 @@ onScopeDispose(() => {
</template>
</MenubarContent>
</MenubarMenu>

<MenubarMenu>
<MenubarTrigger aria-label="Windows" class="ml-auto">
<AppWindowIcon class="h-6 w-6" />
</MenubarTrigger>
<MenubarContent align="end">
<template v-if="registry.size === 0">
<MenubarLabel>No windows open</MenubarLabel>
</template>
<template v-else>
<MenubarLabel>Windows ({{ registry.size }})</MenubarLabel>
<MenubarSeparator />
<MenubarItem
v-for="[id, item] of registry"
:key="id"
@select="
() => {
// @ts-expect-error Property missing in upstream types.
if (item.winbox.min) {
// @ts-expect-error Method missing in upstream types.
item.winbox.restore();
}
item.winbox.focus();
/** Windows are only displayed on `/`. */
if (route.path !== '/') {
void router.push('/');
}
}
"
>
{{ item.winbox.title }}
</MenubarItem>
<MenubarSeparator />
<MenubarLabel>Arrangement</MenubarLabel>
<MenubarSeparator />
<MenubarItem
v-for="(arrangement, id) of arrangements"
:key="id"
class="justify-between"
@select="
() => {
setWindowArrangement(id);
}
"
>
{{ arrangement.label }}
<CheckIcon v-if="id === currentArrangement" class="h-4 w-4" />
</MenubarItem>
</template>
</MenubarContent>
</MenubarMenu>
<WindowListDropdown :is-mobile="false" />
</Menubar>
</template>
3 changes: 3 additions & 0 deletions components/app-navigation-mobile-menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ onScopeDispose(() => {

<template>
<Sheet v-model:open="isSidepanelOpen">
<Menubar class="w-full border-none">
<WindowListDropdown :is-mobile="true" />
</Menubar>
<SheetTrigger aria-label="Toggle menu" class="cursor-default">
<MenuIcon class="mx-3 my-1.5 h-5 w-5" />
</SheetTrigger>
Expand Down
36 changes: 22 additions & 14 deletions components/corpus-text.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@
import "v3-infinite-loading/lib/style.css"; //required if you're not going to override default slots
import InfiniteLoading from "v3-infinite-loading";
import type { StateHandler } from "v3-infinite-loading/lib/types";
import type { CorpusText, CorpusTextUtterances, HttpResponse } from "@/lib/api-client";
interface CorpusTextParams {
id: string;
hits: string;
u: string;
}
const props = defineProps<{
params: Record<any, any>;
params: CorpusTextParams;
}>();
const utterances = ref([]);
const utteranceElements = ref([]);
const utterances = ref<Array<CorpusTextUtterances>>([]);
const utteranceElements = ref<Array<Element>>([]);
const currentPage = ref(1);
const api = useApiClient();
const loadNextPage = async function () {
let text;
let text: HttpResponse<CorpusText, string>;
text = await api.vicav.getCorpusText(
{
id: props.params.id,
Expand All @@ -22,17 +31,19 @@ const loadNextPage = async function () {
},
{ headers: { Accept: "application/json" } },
);
utterances.value = utterances.value.concat(text.data.utterances);
currentPage.value = currentPage.value + 1;
if (text.data.utterances !== undefined) {
utterances.value = utterances.value.concat(text.data.utterances);
currentPage.value = currentPage.value + 1;
}
return text;
};
const handleInfiniteScroll = async function ($state) {
const handleInfiniteScroll = async function ($state: StateHandler) {
try {
const text = await loadNextPage();
currentPage.value = currentPage.value + 1;
$state.loaded();
if (text.data.utterances.length < 10) $state.complete();
if (text.data.utterances !== undefined && text.data.utterances.length < 10) $state.complete();
} catch (e) {
$state.error(e);
}
Expand All @@ -41,12 +52,9 @@ const handleInfiniteScroll = async function ($state) {
const getText = async function () {
let text;
do {
try {
text = await loadNextPage();
} catch (e) {
console.log(e);
}
text = await loadNextPage();
} while (
text.data.utterances !== undefined &&
text.data.utterances.filter((u) => u.id === props.params.u).length === 0 &&
text.data.utterances.length !== 0
);
Expand All @@ -55,7 +63,7 @@ const getText = async function () {
onMounted(async () => {
await getText();
const u = utteranceElements.value.find((u) => u.id === props.params.u);
u.scrollIntoView({ behavior: "smooth" });
if (u !== undefined) u.scrollIntoView({ behavior: "smooth" });
});
</script>

Expand Down
69 changes: 69 additions & 0 deletions components/window-list-dropdown.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<script setup lang="ts">
import { AppWindowIcon, CheckIcon } from "lucide-vue-next";
// const props = defineProps(["isMobile"]);
const router = useRouter();
const route = useRoute();
const windowsStore = useWindowsStore();
const { setWindowArrangement } = windowsStore;
const { arrangement: currentArrangement, registry } = storeToRefs(windowsStore);
</script>

<template>
<MenubarMenu>
<MenubarTrigger aria-label="Windows" class="ml-auto">
<AppWindowIcon class="h-6 w-6" />
</MenubarTrigger>
<MenubarContent align="end">
<template v-if="registry.size === 0">
<MenubarLabel>No windows open</MenubarLabel>
</template>
<template v-else>
<MenubarLabel>Windows ({{ registry.size }})</MenubarLabel>
<MenubarSeparator />
<MenubarItem
v-for="[id, item] of registry"
:key="id"
@select="
() => {
// @ts-expect-error Property missing in upstream types.
if (item.winbox.min) {
// @ts-expect-error Method missing in upstream types.
item.winbox.restore();
}
item.winbox.focus();
/** Windows are only displayed on `/`. */
if (route.path !== '/') {
void router.push('/');
}
}
"
>
{{ item.winbox.title }}
</MenubarItem>
<template v-if="$props.isMobile === false">
<MenubarSeparator />
<MenubarLabel>Arrangement</MenubarLabel>
<MenubarSeparator />
<MenubarItem
v-for="(arrangement, id) of arrangements"
:key="id"
class="justify-between"
@select="
() => {
setWindowArrangement(id);
}
"
>
{{ arrangement.label }}
<CheckIcon v-if="id === currentArrangement" class="h-4 w-4" />
</MenubarItem>
</template>
</template>
</MenubarContent>
</MenubarMenu>
</template>
2 changes: 2 additions & 0 deletions components/window-manager.client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const rootElement = ref<HTMLElement | null>(null);
const debouncedArrangeWindows = debounce(arrangeWindows, 150);
useResizeObserver(rootElement, debouncedArrangeWindows);
onMounted(windowsStore.restoreState);
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"is-ci": "^3.0.1",
"leaflet": "^1.9.4",
"lucide-vue-next": "^0.289.0",
"nanoid": "^5.0.2",
"nanoid": "^5.0.3",
"npm-run-all2": "^6.1.1",
"nuxt": "^3.7.4",
"pinia": "^2.1.7",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dd261d7

Please sign in to comment.