Skip to content

Commit

Permalink
feat: space (#124)
Browse files Browse the repository at this point in the history
* feat: space

Refactored component props and loop structures in multiple components to improve
readability and maintainability. Updated props definitions in Header.vue,
Module.vue, and Flow components. Adjusted loop syntax in Index.vue and Module.vue
files to enhance consistency and clarity. Removed unused CSS styles from
Index.vue and default.vue layouts for better code cleanliness. Updated field
naming for consistency in the Space model in prisma/schema.prisma file.

* feat(space): add dynamic title to space page

Added dynamic title to the space page component using the space's title property. This enhances the user experience by displaying relevant information.

* refactor(api): Remove unnecessary code in space endpoint
  • Loading branch information
nexmoe authored May 6, 2024
1 parent ef23d89 commit 122ffa5
Show file tree
Hide file tree
Showing 14 changed files with 207 additions and 118 deletions.
2 changes: 1 addition & 1 deletion components/flow/Header.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
interface Props {
url: string | null
url?: string | null
title: string
id: string
}
Expand Down
37 changes: 10 additions & 27 deletions components/flow/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import type { AppRouter } from '@/server/trpc/routers'
type RouterOutput = inferRouterOutputs<AppRouter>
type FlowOutput = RouterOutput['flow']['get']
type Flow = Exclude<FlowOutput, null | undefined>
interface Props {
flow: FlowOutput
flow: Flow
header?: boolean
}
Expand All @@ -21,34 +22,34 @@ provide('flow', props.flow)
<div class="flow">
<FlowHeader
v-if="props.header"
:id="props.flow!.id"
:title="props.flow!.title"
:url="props.flow!.homepage"
:id="props.flow.id"
:title="props.flow.title"
:url="props.flow.homepage"
/>

<div
class="flow-body"
:class="[
props.flow!.configCard === 'gallery' ? 'n-gallery' : 'n-grid',
props.flow.configCard === 'gallery' ? 'n-gallery' : 'n-grid',
]"
>
<NuxtLink
v-for="(module) in props.flow!.module"
v-for="(module) in props.flow.module"
:key="module.url"
:title="module.title"
:to="module.url"
target="_blank"
>
<LazyModuleList
v-if="props.flow!.configCard === 'list'"
v-if="props.flow.configCard === 'list'"
v-bind="{ module }"
/>
<LazyModuleProject
v-else-if="props.flow!.configCard === 'project'"
v-else-if="props.flow.configCard === 'project'"
v-bind="{ module }"
/>
<LazyModuleGallery
v-else-if="props.flow!.configCard === 'gallery'"
v-else-if="props.flow.configCard === 'gallery'"
v-bind="{ module }"
/>
<LazyModuleImage
Expand All @@ -59,21 +60,3 @@ provide('flow', props.flow)
</div>
</div>
</template>

<style>
.flow {
@apply flex flex-col gap-6;
}
.flow-body.n-grid {
@apply grid grid-cols-1 gap-4 mb-32 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4;
}
.flow-body.n-gallery {
@apply columns-1 gap-4 lg:columns-2 xl:columns-3 2xl:columns-4;
}
.flow-body.n-gallery .module {
@apply mb-4;
}
</style>
2 changes: 1 addition & 1 deletion components/public/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const props = defineProps<Props>()
<template>
<footer class="mt-12 bg-white dark:bg-gray-900">
<div class="mx-auto w-full max-w-screen-xl">
<div v-if="props.sitemap" class="grid grid-cols-2 gap-8 px-4 py-6 lg:py-8 md:grid-cols-4">
<div v-if="props.sitemap" class="grid grid-cols-2 gap-8 px-4 pt-12 lg:py-8 md:grid-cols-4">
<div v-for="item in props.sitemap" :key="item.title">
<h2 class="mb-6 text-sm font-semibold text-gray-900 uppercase dark:text-white">{{ item.title }}</h2>
<ul v-for="list in item.list" :key="list.title"
Expand Down
38 changes: 38 additions & 0 deletions components/space/Flow.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<script setup lang="ts">
import type { inferRouterOutputs } from '@trpc/server'
import type { AppRouter } from '@/server/trpc/routers'
type RouterOutput = inferRouterOutputs<AppRouter>
type SpaceOutput = RouterOutput['space']['get']
type Space = Exclude<SpaceOutput, null>
interface Props {
space: Space
header?: boolean
}
const props = withDefaults(defineProps<Props>(), {
header: true,
})
</script>

<template>
<div class="flow">
<FlowHeader
v-if="props.header"
:id="props.space.id"
:title="props.space.title"
/>

<div class="flow-body n-grid">
<NuxtLink
v-for="flow in props.space.flows"
:key="flow.id"
:title="flow.title"
target="_blank"
>
<LazySpaceModule v-bind="{ flow }" />
</NuxtLink>
</div>
</div>
</template>
41 changes: 41 additions & 0 deletions components/space/Module.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script setup lang="ts">
import type { inferRouterOutputs } from '@trpc/server'
import type { AppRouter } from '@/server/trpc/routers'
type RouterOutput = inferRouterOutputs<AppRouter>
type FlowOutput = RouterOutput['flow']['get']
type Flow = Exclude<FlowOutput, null | undefined>
interface Props {
flow: Flow
}
const props = defineProps<Props>()
</script>

<template>
<div class="module shu-card p-4">
<div class="px-3 py-2 text-base">
{{ flow.title }}
</div>
<div class="list-none m-0 p-0">
<NuxtLink
v-for="module in props.flow.module"
:key="module.id"
:title="module.title"
:href="module.url"
target="_blank"
class="flex flex-row items-center gap-2 hover:bg-gray-100 focus:bg-gray-200 rounded-2xl px-3 py-2 transition duration-300"
>
<LinkIcon
class="w-5 h-5 basis-5"
:width="20"
:url="module.url"
/>
<div class="truncate ">
{{ module.title }}
</div>
</NuxtLink>
</div>
</div>
</template>
16 changes: 16 additions & 0 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,20 @@ body {
.nexmoe-shadow {
box-shadow: 0 0.125rem 0.5rem rgb(204 177 161 / 30%);
}
.flow {
@apply flex flex-col gap-6;
}
.flow-body.n-grid {
@apply grid grid-cols-1 gap-4 mb-32 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4;
}
.flow-body.n-gallery {
@apply columns-1 gap-4 lg:columns-2 xl:columns-3 2xl:columns-4;
}
.flow-body.n-gallery .module {
@apply mb-4;
}
</style>
2 changes: 1 addition & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defineOgImageComponent('NuxtSeo', {
</div>
</PublicProse>
<template
v-for=" flow in flows "
v-for="flow in flows "
:key="flow.id"
>
<LazyFlow
Expand Down
59 changes: 59 additions & 0 deletions pages/space/[id].vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<script setup lang="ts">
const id = useRoute().params.id as string
const { $client } = useNuxtApp()
const space = await $client.space.get.query({ id })
const config = await useGetConfig()
if (!space) {
throw createError({
statusCode: 404,
})
}
defineOgImageComponent('NuxtSeo', {
theme: config.ogTheme,
title: space.title,
description: space.description,
})
</script>

<template>
<div class="page">
<Head>
<Title>{{ space.title }}</Title>
</Head>
<div class="container">
<PublicProse
v-if="space.description"
:title="space.title"
>
{{ space.description }}
</PublicProse>
<PublicProse
v-else
:title="space.title"
/>
<SpaceFlow v-bind="{ header: false, space }" />
<template
v-for=" flow in space.flows"
:key="flow.id"
>
<LazyFlow
v-if="flow.module.length > 0"
v-bind="{ flow }"
/>
</template>
</div>
</div>
</template>

<style scoped>
.sidebar {
@apply fixed w-0 lg:w-64 bg-white h-full;
}
.content {
@apply lg:pl-72 lg:pr-8;
}
</style>
46 changes: 0 additions & 46 deletions pages/space/_[id].vue

This file was deleted.

5 changes: 2 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ model Flow {
configNoContent Boolean @default(false)
configNoTitle Boolean @default(false)
configOpenURL Boolean @default(false)
spaceId String?
api API[]
space Space? @relation(fields: [spaceId], references: [id])
module Module[]
spaces Space[]
}

model Space {
Expand All @@ -65,5 +64,5 @@ model Space {
title String
details String
description String?
flow Flow[]
flows Flow[]
}
23 changes: 0 additions & 23 deletions server/api/space/[id].get.ts

This file was deleted.

2 changes: 1 addition & 1 deletion server/trpc/routers/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from 'zod'
import { publicProcedure, router } from '../trpc'
import { flowingByFlowId } from '~/server/flowing'

export const flowRouter = router({
export default router({
list: publicProcedure
.query(async ({ ctx }) => {
const prisma = ctx.prisma
Expand Down
20 changes: 5 additions & 15 deletions server/trpc/routers/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { z } from 'zod'
import { publicProcedure, router } from '../trpc'
import { router } from '../trpc'
import config from './config'
import { flowRouter } from './flow'
import flow from './flow'
import module from './module'
import space from './space'

export const appRouter = router({
hello: publicProcedure
.input(
z.object({
text: z.string().nullish(),
}),
)
.query(({ input }) => {
return {
greeting: `hello ${input?.text ?? 'world'}`,
}
}),
config,
flow: flowRouter,
flow,
module,
space,
})

// export type definition of API
Expand Down
Loading

0 comments on commit 122ffa5

Please sign in to comment.