notea/pages/index.tsx

62 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-03-26 15:43:07 +03:00
import { GetServerSideProps, GetServerSidePropsContext, NextPage } from 'next'
import { withTree } from 'libs/server/middlewares/tree'
import { withUA } from 'libs/server/middlewares/ua'
2021-03-22 16:32:59 +03:00
import { TreeModel } from 'libs/shared/tree'
import { withSession } from 'libs/server/middlewares/session'
import { withStore } from 'libs/server/middlewares/store'
import { withSettings } from 'libs/server/middlewares/settings'
import { withAuth } 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-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-03-26 15:43:07 +03:00
function withIndex(wrapperHandler: any) {
return async function handler(ctx: GetServerSidePropsContext) {
const res = await wrapperHandler(ctx)
const lastVisit = res.props?.settings?.last_visit
if (lastVisit && !res.redirect) {
res.redirect = {
destination: lastVisit,
permanent: false,
}
}
return res
}
}
2021-03-22 16:32:59 +03:00
export const getServerSideProps: GetServerSideProps = withUA(
withSession(
2021-03-26 15:43:07 +03:00
withStore(withAuth(withTree(withIndex(withSettings(() => ({}))))))
2021-03-22 16:32:59 +03:00
)
)