add notFound function to SSR HOF, 404 inactive jobs
This commit is contained in:
parent
208f1b8da9
commit
ae916ecb97
|
@ -31,7 +31,7 @@ export default async function getSSRApolloClient (req, me = null) {
|
|||
})
|
||||
}
|
||||
|
||||
export function getGetServerSideProps (query, variables = null, foundField, requireVar) {
|
||||
export function getGetServerSideProps (query, variables = null, notFoundFunc, requireVar) {
|
||||
return async function ({ req, query: params }) {
|
||||
const client = await getSSRApolloClient(req)
|
||||
const vars = { ...params, ...variables }
|
||||
|
@ -47,7 +47,7 @@ export function getGetServerSideProps (query, variables = null, foundField, requ
|
|||
variables: vars
|
||||
})
|
||||
|
||||
if (error || !data || (foundField && !data[foundField])) {
|
||||
if (error || !data || (notFoundFunc && notFoundFunc(data))) {
|
||||
return {
|
||||
notFound: true
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@ import { USER_FULL } from '../../fragments/users'
|
|||
import { ITEM_FIELDS } from '../../fragments/items'
|
||||
import { getGetServerSideProps } from '../../api/ssrApollo'
|
||||
|
||||
export const getServerSideProps = getGetServerSideProps(USER_FULL, null, 'user')
|
||||
export const getServerSideProps = getGetServerSideProps(USER_FULL, null,
|
||||
data => !data.user)
|
||||
|
||||
const BioSchema = Yup.object({
|
||||
bio: Yup.string().required('required').trim()
|
||||
|
|
|
@ -5,7 +5,8 @@ import { LinkForm } from '../../../components/link-form'
|
|||
import LayoutCenter from '../../../components/layout-center'
|
||||
import JobForm from '../../../components/job-form'
|
||||
|
||||
export const getServerSideProps = getGetServerSideProps(ITEM, null, 'item')
|
||||
export const getServerSideProps = getGetServerSideProps(ITEM, null,
|
||||
data => !data.item)
|
||||
|
||||
export default function PostEdit ({ data: { item } }) {
|
||||
const editThreshold = new Date(item.createdAt).getTime() + 10 * 60000
|
||||
|
|
|
@ -5,7 +5,8 @@ import ItemFull from '../../../components/item-full'
|
|||
import { getGetServerSideProps } from '../../../api/ssrApollo'
|
||||
import { useQuery } from '@apollo/client'
|
||||
|
||||
export const getServerSideProps = getGetServerSideProps(ITEM_FULL, null, 'item')
|
||||
export const getServerSideProps = getGetServerSideProps(ITEM_FULL, null,
|
||||
data => !data.item || data.item.status !== 'ACTIVE')
|
||||
|
||||
export default function AnItem ({ data: { item } }) {
|
||||
const { data } = useQuery(ITEM_FULL, {
|
||||
|
|
|
@ -3,7 +3,8 @@ import Items from '../../../components/items'
|
|||
import Layout from '../../../components/layout'
|
||||
import { SUB_ITEMS } from '../../../fragments/subs'
|
||||
|
||||
export const getServerSideProps = getGetServerSideProps(SUB_ITEMS, null, 'sub')
|
||||
export const getServerSideProps = getGetServerSideProps(SUB_ITEMS, null,
|
||||
data => !data.sub)
|
||||
|
||||
export default function Sub ({ data: { sub: { name }, items: { items, cursor } } }) {
|
||||
return (
|
||||
|
|
|
@ -3,7 +3,8 @@ import { SUB } from '../../../fragments/subs'
|
|||
import LayoutCenter from '../../../components/layout-center'
|
||||
import JobForm from '../../../components/job-form'
|
||||
|
||||
export const getServerSideProps = getGetServerSideProps(SUB, null, 'sub')
|
||||
export const getServerSideProps = getGetServerSideProps(SUB, null,
|
||||
data => !data.sub)
|
||||
|
||||
// need to recent list items
|
||||
export default function Post ({ data: { sub } }) {
|
||||
|
|
|
@ -4,7 +4,8 @@ import Layout from '../../../components/layout'
|
|||
import { SUB_ITEMS } from '../../../fragments/subs'
|
||||
|
||||
const variables = { sort: 'recent' }
|
||||
export const getServerSideProps = getGetServerSideProps(SUB_ITEMS, variables, 'sub')
|
||||
export const getServerSideProps = getGetServerSideProps(SUB_ITEMS, variables,
|
||||
data => !data.sub)
|
||||
|
||||
// need to recent list items
|
||||
export default function Sub ({ data: { sub: { name }, items: { items, cursor } } }) {
|
||||
|
|
|
@ -5,7 +5,8 @@ import { useRouter } from 'next/router'
|
|||
import { SeoSearch } from '../../../components/seo'
|
||||
import { SUB_SEARCH } from '../../../fragments/subs'
|
||||
|
||||
export const getServerSideProps = getGetServerSideProps(SUB_SEARCH, null, 'sub', 'q')
|
||||
export const getServerSideProps = getGetServerSideProps(SUB_SEARCH, null,
|
||||
data => !data.sub, 'q')
|
||||
|
||||
export default function Index ({ data: { sub: { name }, search: { items, cursor } } }) {
|
||||
const router = useRouter()
|
||||
|
|
Loading…
Reference in New Issue