notea/pages/index.tsx

69 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-03-22 16:32:59 +03:00
import LayoutMain from 'components/layout/layout-main'
2021-05-08 09:13:55 +03:00
import { NextPage } from 'next'
import { applyUA } from 'libs/server/middlewares/ua'
2021-03-22 16:32:59 +03:00
import { TreeModel } from 'libs/shared/tree'
2021-05-08 09:13:55 +03:00
import { useSession } from 'libs/server/middlewares/session'
import { applySettings } from 'libs/server/middlewares/settings'
import { applyAuth, applyRedirectLogin } from 'libs/server/middlewares/auth'
2021-03-22 16:32:59 +03:00
import Link from 'next/link'
2021-04-21 14:01:49 +03:00
import UIState from 'libs/web/state/ui'
import Router from 'next/router'
import { useEffect } from 'react'
2021-05-08 09:13:55 +03:00
import { applyCsrf } from 'libs/server/middlewares/csrf'
import { SSRContext, ssr } from 'libs/server/connect'
2021-05-20 17:20:22 +03:00
import { applyReset } from 'libs/server/middlewares/reset'
2021-03-22 16:32:59 +03:00
const EditNotePage: NextPage<{ tree: TreeModel }> = ({ tree }) => {
2021-04-21 14:01:49 +03:00
const { ua } = UIState.useContainer()
useEffect(() => {
if (ua.isMobileOnly) {
Router.push('/new')
}
}, [ua.isMobileOnly])
2021-03-22 16:32:59 +03:00
return (
<LayoutMain tree={tree}>
2021-04-21 14:01:49 +03:00
<div className="flex flex-col h-screen">
<div className="m-auto text-center flex flex-col items-center">
<Link href="//github.com/qingwei-li/notea">
<a target="_blank">
<img className="w-60 h-60 opacity-10 -mt-40" src="/logo.svg" />
</a>
</Link>
</div>
2021-03-22 16:32:59 +03:00
</div>
</LayoutMain>
)
}
export default EditNotePage
2021-05-08 09:13:55 +03:00
export const getServerSideProps = async (ctx: SSRContext) => {
await ssr()
.use(useSession)
.use(applyAuth)
.use(applyRedirectLogin(ctx.resolvedUrl))
2021-05-20 17:20:22 +03:00
.use(applyReset)
2021-05-08 09:13:55 +03:00
.use(applySettings)
.use(applyCsrf)
.use(applyUA)
.run(ctx.req, ctx.res)
2021-03-26 15:43:07 +03:00
2021-05-08 09:13:55 +03:00
const lastVisit = ctx.req.props?.settings?.last_visit
if (lastVisit) {
return {
redirect: {
2021-03-26 15:43:07 +03:00
destination: lastVisit,
permanent: false,
2021-05-08 09:13:55 +03:00
},
2021-03-26 15:43:07 +03:00
}
2021-05-08 09:13:55 +03:00
}
2021-03-26 15:43:07 +03:00
2021-05-08 09:13:55 +03:00
return {
props: ctx.req.props,
redirect: ctx.req.redirect,
2021-03-26 15:43:07 +03:00
}
}