Skip to content

Commit

Permalink
feat: note redirect
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Jun 15, 2023
1 parent 9c8ed44 commit 0151192
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/app/notes/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { apiClient } from '~/utils/request'

export const GET = async (request: NextRequest) => {
const url = request.nextUrl.clone()
const { data: {nid}}= await apiClient.note.getLatest()
url.pathname = `/notes/${nid}`
return NextResponse.redirect(url)
}
13 changes: 3 additions & 10 deletions src/components/layout/header/HeaderDataConfigureProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
'use client'

import {
createContext,
useContext,
useEffect,
useMemo,
useState,
} from 'react'
import { createContext, useContext, useEffect, useMemo, useState } from 'react'

import { useAggregation } from '~/hooks/data/use-aggregation'
import { cloneDeep } from '~/lib/_'

import { headerMenuConfig as baseHeaderMenuConfig } from './config'

Expand All @@ -24,9 +19,7 @@ export const HeaderDataConfigureProvider: Component = ({ children }) => {

useEffect(() => {
if (!data) return
const nextMenuConfig = JSON.parse(
JSON.stringify(baseHeaderMenuConfig),
) as typeof baseHeaderMenuConfig
const nextMenuConfig = cloneDeep(baseHeaderMenuConfig)
if (data.pageMeta) {
const homeIndex = nextMenuConfig.findIndex((item) => item.type === 'Home')
if (homeIndex !== -1) {
Expand Down
14 changes: 14 additions & 0 deletions src/lib/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,17 @@ export const throttle = <F extends (...args: any[]) => any>(

export const isUndefined = (val: any): val is undefined =>
typeof val === 'undefined'

export const cloneDeep = <T>(val: T): T => {
if (Array.isArray(val)) {
return val.map(cloneDeep) as any
} else if (typeof val === 'object' && val !== null) {
const result: any = {}
for (const key in val) {
result[key] = cloneDeep(val[key])
}
return result
} else {
return val
}
}

0 comments on commit 0151192

Please sign in to comment.