Skip to content

Commit

Permalink
feat: rework books list/table
Browse files Browse the repository at this point in the history
  • Loading branch information
ufaboy committed Jun 28, 2024
1 parent 3a78416 commit 22a1d50
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 92 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lib-vue",
"private": true,
"version": "1.9.5",
"version": "1.10.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/style/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
@apply text-teal-400 lg:bg-transparent lg:text-teal-400 lg:p-0 dark:text-teal-400 lg:dark:text-blue-500
}
.sidebar-link {
@apply flex items-center gap-2 px-2 py-1 rounded lg:hover:bg-transparent lg:border-0 lg:hover:text-teal-300 dark:text-white lg:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white lg:dark:hover:bg-transparent
@apply flex items-center gap-2 px-2 py-1 lg:hover:bg-transparent lg:border-0 lg:hover:text-teal-300 dark:text-white lg:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white lg:dark:hover:bg-transparent
}
.sidebar-link-active {
@apply text-teal-400 lg:bg-transparent lg:text-teal-400 dark:text-teal-400 lg:dark:text-blue-500
Expand Down
98 changes: 61 additions & 37 deletions src/components/TheSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
import { computed } from 'vue';
import { RouterLink, useRoute } from 'vue-router';
import ThemeSwitcher from '@/components/ThemeSwitcher.vue';
import IconBurger from '@/components/IconBurger.vue';
const emit = defineEmits(['toggleSidebar']);
const props = defineProps({
expanded: Boolean
})
const route = useRoute()
Expand All @@ -15,8 +20,19 @@ const bookID = computed(() => {
</script>

<template>
<aside class="scrollbar bg-white dark:bg-gray-900">
<ul class="sticky top-0 w-full gap-3 bg-white dark:text-white dark:bg-gray-900">
<div class="sticky top-0 z-30 flex h-8 w-full items-center px-3 dark:bg-gray-900 dark:text-white lg:hidden">
<button class="" @click="$emit('toggleSidebar')">
<IconBurger class="size-6" :class="{ active: expanded }" />
</button>
<div id="header-target" class="ml-auto flex items-center gap-1 md:gap-3" />
</div>

<aside
v-bind="$attrs"
class="fixed -left-40 top-0 z-20 lg:left-0 h-full w-40 bg-white pt-8 lg:pt-0 shadow transition dark:bg-gray-900 dark:text-white"
:class="{'translate-x-40': expanded}">
<ul
class=" gap-3 ">
<li class="w-full">
<RouterLink
:to="{ name: 'books' }"
Expand Down Expand Up @@ -72,40 +88,48 @@ const bookID = computed(() => {
<span>Media</span>
</RouterLink>
</li>
<!-- <hr class="my-1"> -->
<li v-if="route.name === 'books'" class="w-full">
<RouterLink
:to="{ name: 'book-create' }"
class="sidebar-link flex items-center gap-2"
active-class="sidebar-link-active">
<svg class="inline size-6" fill="none">
<use xlink:href="/icons/iconSprite.svg#bookAdd" />
</svg>
<span>Create</span>
</RouterLink>
</li>
<li v-if="route.name === 'book-update'" class="w-full">
<RouterLink
:to="{ name: 'book-view' }"
class="sidebar-link flex items-center gap-2"
active-class="sidebar-link-active">
<svg class="inline size-6" fill="none">
<use xlink:href="/icons/iconSprite.svg#openBook" />
</svg>
<span>View</span>
</RouterLink>
</li>
<li v-if="['book-view', 'comics-view'].includes(routeName)" class="w-full">
<RouterLink
:to="{ name: 'book-update', params: { id: bookID } }"
class="sidebar-link flex items-center gap-2"
active-class="sidebar-link-active">
<svg class="inline size-6" fill="none">
<use xlink:href="/icons/iconSprite.svg#openBook" />
</svg>
<span>Update</span>
</RouterLink>
</li>
<template v-if="route.name === 'books'">
<hr class="my-1">
<li class="w-full">
<RouterLink
:to="{ name: 'book-create' }"
class="sidebar-link flex items-center gap-2"
active-class="sidebar-link-active">
<svg class="inline size-6" fill="none">
<use xlink:href="/icons/iconSprite.svg#bookAdd" />
</svg>
<span>Create</span>
</RouterLink>
</li>
</template>
<template v-if="route.name === 'book-update'">
<hr class="my-1">
<li class="w-full">
<RouterLink
:to="{ name: 'book-view' }"
class="sidebar-link flex items-center gap-2"
active-class="sidebar-link-active">
<svg class="inline size-6" fill="none">
<use xlink:href="/icons/iconSprite.svg#openBook" />
</svg>
<span>View</span>
</RouterLink>
</li>
</template>
<template v-if="['book-view', 'comics-view'].includes(routeName)">
<hr class="my-1">
<li class="w-full">
<RouterLink
:to="{ name: 'book-update', params: { id: bookID } }"
class="sidebar-link flex items-center gap-2"
active-class="sidebar-link-active">
<svg class="inline size-6" fill="none">
<use xlink:href="/icons/iconSprite.svg#openBook" />
</svg>
<span>Update</span>
</RouterLink>
</li>
</template>
<hr class="my-1">

<!-- <li class="px-4">
Expand Down
35 changes: 19 additions & 16 deletions src/layouts/LayoutMain.vue
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from 'vue';
import { onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { useScroll } from '@/composables/scroll';
import TheSidebar from '@/components/TheSidebar.vue';
import BtnScrollToTop from '@/components/BtnScrollToTop.vue';
import TheHeader from '@/components/TheHeader.vue';
const { btnTopShow, scrollingProgress, observedElement, scrollTo, throttleScroll } = useScroll();
const { btnTopShow, scrollingProgress, scrollTo, throttleScroll } = useScroll();
const route = useRoute();
const sidebarShow = ref(false);
watch(
() => route.name,
() => (sidebarShow.value = false),
);
onMounted(() => {
window.addEventListener('scroll', throttleScroll, { passive: true });
observedElement.value = document.documentElement;
document.addEventListener('scroll', throttleScroll, { passive: true });
});
onBeforeUnmount(() => {
window.removeEventListener('scroll', throttleScroll);
document.removeEventListener('scroll', throttleScroll);
});
document.documentElement.classList.add('scrollbar-gutter');
</script>
<template>
<div
id="layout"
class="min-h-full">
<TheHeader class="sticky top-0 z-10" />
<router-view
:progress="scrollingProgress.progress"
class="px-2 lg:px-4" />
<div id="layout" class="relative flex min-h-full flex-col lg:flex-row">
<TheSidebar class="" :expanded="sidebarShow" @toggle-sidebar="sidebarShow = !sidebarShow" />
<router-view :progress="scrollingProgress.progress" class="relative px-2 lg:left-40" />
<BtnScrollToTop
v-if="btnTopShow"
class="fixed bottom-20 right-5 z-10 flex size-10 items-center justify-center"
class="fixed bottom-20 right-10 z-10 flex size-10 items-center justify-center"
@click="scrollTo()" />
</div>
</template>
27 changes: 0 additions & 27 deletions src/layouts/LayoutSidebar.vue

This file was deleted.

10 changes: 2 additions & 8 deletions src/router.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { createRouter, createWebHistory, RouteRecordRaw, RouterOptions } from 'vue-router';
import { isSmallDevice } from './utils/helper';

const LayoutMain = () => import('./layouts/LayoutMain.vue');
const LayoutSidebar = () => import('./layouts/LayoutSidebar.vue');
const BookTable = () => import('./views/BookTable.vue');
const BookList = () => import('./views/BookList.vue');

const routes: RouteRecordRaw[] = [
{
path: '/',
component: isSmallDevice() ? LayoutMain : LayoutSidebar,
component: () => import('./layouts/LayoutMain.vue'),
children: [
{
path: '',
Expand All @@ -23,7 +17,7 @@ const routes: RouteRecordRaw[] = [
{
path: '/books',
name: 'books',
component: isSmallDevice() ? BookList : BookTable,
component: () => import('./views/books/BooksMain.vue'),
},
{
path: '/book/:id',
Expand Down
2 changes: 1 addition & 1 deletion src/views/BookList.vue → src/views/books/BookList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ getTags();
<div class="truncate font-bold">
{{ book.name }}
</div>
<div class="line-clamp-2 break-all">
<div class="line-clamp-2">
{{ book.description }}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/views/BookTable.vue → src/views/books/BookTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ if (!series.value) getSeries({ perPage: 100, page: 1, sort: 'name' });
</button>
</div>
</th>
<th class="th sticky top-0" :class="{ '!border-black ': scrolled }">
<th class="th sticky top-0 w-24" :class="{ '!border-black ': scrolled }">
<div
class="flex flex-row items-center"
:class="{ 'text-emerald-300': queryBooks.sort.includes('count') }">
Expand Down
30 changes: 30 additions & 0 deletions src/views/books/BooksMain.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script setup lang="ts">
import { defineAsyncComponent, onMounted, onUnmounted, ref } from 'vue'
import { isSmallDevice } from '../../utils/helper';
const BookTable = defineAsyncComponent(() =>
import('./BookTable.vue')
)
const BookList = defineAsyncComponent(() =>
import('./BookList.vue')
)
const smallDedice = ref(isSmallDevice());
function updateDeviceSize() {
smallDedice.value = isSmallDevice();
}
onMounted(() => {
window.addEventListener('resize', updateDeviceSize);
});
onUnmounted(() => {
window.removeEventListener('resize', updateDeviceSize);
});
</script>


<template>
<component :is="smallDedice ? BookList : BookTable" />
</template>

0 comments on commit 22a1d50

Please sign in to comment.