fix closure stacker bug
This commit is contained in:
parent
b3eb1fbd96
commit
68e9dfd69c
|
@ -61,15 +61,16 @@ export default async function getSSRApolloClient ({ req, res, me = null }) {
|
|||
* @param opts.notFound function that tests data to determine if 404
|
||||
* @param opts.authRequired boolean that determines if auth is required
|
||||
*/
|
||||
export function getGetServerSideProps ({ query, variables, notFound, authRequired }) {
|
||||
export function getGetServerSideProps (
|
||||
{ query: queryOrFunc, variables: varsOrFunc, notFound, authRequired }) {
|
||||
return async function ({ req, res, query: params }) {
|
||||
const { nodata, ...realParams } = params
|
||||
// we want to use client-side cache
|
||||
if (nodata) return { props: { } }
|
||||
|
||||
variables = typeof variables === 'function' ? variables(realParams) : variables
|
||||
const variables = typeof varsOrFunc === 'function' ? varsOrFunc(realParams) : varsOrFunc
|
||||
const vars = { ...realParams, ...variables }
|
||||
query = typeof query === 'function' ? query(vars) : query
|
||||
const query = typeof queryOrFunc === 'function' ? queryOrFunc(vars) : queryOrFunc
|
||||
|
||||
const client = await getSSRApolloClient({ req, res })
|
||||
|
||||
|
|
|
@ -195,6 +195,14 @@ export const USER_FULL = gql`
|
|||
}
|
||||
}`
|
||||
|
||||
export const USER = gql`
|
||||
${USER_FIELDS}
|
||||
query User($name: String!) {
|
||||
user(name: $name) {
|
||||
...UserFields
|
||||
}
|
||||
}`
|
||||
|
||||
export const USER_WITH_ITEMS = gql`
|
||||
${USER_FIELDS}
|
||||
${ITEM_FIELDS}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { getGetServerSideProps } from '../../api/ssrApollo'
|
||||
import Items from '../../components/items'
|
||||
import { useRouter } from 'next/router'
|
||||
import { USER_WITH_ITEMS } from '../../fragments/users'
|
||||
import { USER, USER_WITH_ITEMS } from '../../fragments/users'
|
||||
import { useQuery } from '@apollo/client'
|
||||
import { COMMENT_TYPE_QUERY, ITEM_SORTS, ITEM_TYPES, WHENS } from '../../lib/constants'
|
||||
import PageLoading from '../../components/page-loading'
|
||||
|
@ -9,12 +9,11 @@ import { UserLayout } from '.'
|
|||
import { Form, Select } from '../../components/form'
|
||||
|
||||
const staticVariables = { sort: 'user' }
|
||||
const variablesFunc = vars =>
|
||||
({
|
||||
const variablesFunc = vars => ({
|
||||
includeComments: COMMENT_TYPE_QUERY.includes(vars.type),
|
||||
...staticVariables,
|
||||
...vars
|
||||
})
|
||||
})
|
||||
export const getServerSideProps = getGetServerSideProps(
|
||||
{ query: USER_WITH_ITEMS, variables: variablesFunc, notFound: data => !data.user })
|
||||
|
||||
|
@ -22,7 +21,7 @@ export default function UserItems ({ ssrData }) {
|
|||
const router = useRouter()
|
||||
const variables = variablesFunc(router.query)
|
||||
|
||||
const { data } = useQuery(USER_WITH_ITEMS, { variables })
|
||||
const { data } = useQuery(USER, { variables })
|
||||
if (!data && !ssrData) return <PageLoading />
|
||||
|
||||
const { user } = data || ssrData
|
||||
|
@ -43,7 +42,6 @@ export default function UserItems ({ ssrData }) {
|
|||
|
||||
function UserItemsHeader ({ type, name }) {
|
||||
const router = useRouter()
|
||||
|
||||
async function select (values) {
|
||||
let { type, ...query } = values
|
||||
if (!type || type === 'all' || !ITEM_TYPES('user').includes(type)) type = 'all'
|
||||
|
|
Loading…
Reference in New Issue