Merged in feat/mobile-cards-pagination (pull request #362)
[WIP] Feat/mobile cards pagination Approved-by: Michael Zetterberg Approved-by: Simon.Emanuelsson
This commit is contained in:
@@ -2,7 +2,6 @@ import { homeHrefs } from "@/constants/homeHrefs"
|
|||||||
import { env } from "@/env/server"
|
import { env } from "@/env/server"
|
||||||
import { serverClient } from "@/lib/trpc/server"
|
import { serverClient } from "@/lib/trpc/server"
|
||||||
|
|
||||||
import { auth } from "@/auth"
|
|
||||||
import { BookingWidget } from "@/components/BookingWidget"
|
import { BookingWidget } from "@/components/BookingWidget"
|
||||||
import { getLang } from "@/i18n/serverContext"
|
import { getLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import NextImage from "next/image"
|
|||||||
import type { ImageLoaderProps, ImageProps } from "next/image"
|
import type { ImageLoaderProps, ImageProps } from "next/image"
|
||||||
|
|
||||||
function imageLoader({ quality, src, width }: ImageLoaderProps) {
|
function imageLoader({ quality, src, width }: ImageLoaderProps) {
|
||||||
return `${src}?w=${width}${quality ? "&q=" + quality : ""}`
|
const hasQS = src.indexOf("?") !== -1
|
||||||
|
return `${src}${hasQS ? "&" : "?"}w=${width}${quality ? "&q=" + quality : ""}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next/Image adds & instead of ? before the params
|
// Next/Image adds & instead of ? before the params
|
||||||
|
|||||||
@@ -19,9 +19,13 @@ export default function ClientPreviousStays({
|
|||||||
}: PreviousStaysClientProps) {
|
}: PreviousStaysClientProps) {
|
||||||
const { data, isFetching, fetchNextPage, hasNextPage, isLoading } =
|
const { data, isFetching, fetchNextPage, hasNextPage, isLoading } =
|
||||||
trpc.user.stays.previous.useInfiniteQuery(
|
trpc.user.stays.previous.useInfiniteQuery(
|
||||||
{},
|
|
||||||
{
|
{
|
||||||
getNextPageParam: (lastPage) => lastPage?.nextCursor,
|
limit: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
getNextPageParam: (lastPage) => {
|
||||||
|
return lastPage?.nextCursor
|
||||||
|
},
|
||||||
initialData: {
|
initialData: {
|
||||||
pageParams: [undefined, 1],
|
pageParams: [undefined, 1],
|
||||||
pages: [initialPreviousStays],
|
pages: [initialPreviousStays],
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import SectionHeader from "@/components/Section/Header"
|
|||||||
import SectionLink from "@/components/Section/Link"
|
import SectionLink from "@/components/Section/Link"
|
||||||
|
|
||||||
import ClientPreviousStays from "./Client"
|
import ClientPreviousStays from "./Client"
|
||||||
import EmptyPreviousStaysBlock from "./EmptyPreviousStays"
|
|
||||||
|
|
||||||
import type { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"
|
import type { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"
|
||||||
|
|
||||||
@@ -14,18 +13,18 @@ export default async function PreviousStays({
|
|||||||
subtitle,
|
subtitle,
|
||||||
link,
|
link,
|
||||||
}: AccountPageComponentProps) {
|
}: AccountPageComponentProps) {
|
||||||
const initialPreviousStays = await serverClient().user.stays.previous()
|
const initialPreviousStays = await serverClient().user.stays.previous({
|
||||||
if (!initialPreviousStays?.data) {
|
limit: 6,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!initialPreviousStays?.data.length) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SectionContainer>
|
<SectionContainer>
|
||||||
<SectionHeader title={title} subtitle={subtitle} link={link} />
|
<SectionHeader title={title} subtitle={subtitle} link={link} />
|
||||||
{initialPreviousStays.data.length ? (
|
<ClientPreviousStays initialPreviousStays={initialPreviousStays} />
|
||||||
<ClientPreviousStays initialPreviousStays={initialPreviousStays} />
|
|
||||||
) : (
|
|
||||||
<EmptyPreviousStaysBlock />
|
|
||||||
)}
|
|
||||||
<SectionLink link={link} variant="mobile" />
|
<SectionLink link={link} variant="mobile" />
|
||||||
</SectionContainer>
|
</SectionContainer>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ export default function ShowMoreButton({
|
|||||||
onClick={loadMoreData}
|
onClick={loadMoreData}
|
||||||
variant="icon"
|
variant="icon"
|
||||||
type="button"
|
type="button"
|
||||||
className={styles.button}
|
|
||||||
theme="base"
|
theme="base"
|
||||||
intent="text"
|
intent="text"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -19,9 +19,13 @@ export default function ClientUpcomingStays({
|
|||||||
}: UpcomingStaysClientProps) {
|
}: UpcomingStaysClientProps) {
|
||||||
const { data, isFetching, fetchNextPage, hasNextPage, isLoading } =
|
const { data, isFetching, fetchNextPage, hasNextPage, isLoading } =
|
||||||
trpc.user.stays.upcoming.useInfiniteQuery(
|
trpc.user.stays.upcoming.useInfiniteQuery(
|
||||||
{},
|
|
||||||
{
|
{
|
||||||
getNextPageParam: (lastPage) => lastPage?.nextCursor,
|
limit: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
getNextPageParam: (lastPage) => {
|
||||||
|
return lastPage?.nextCursor
|
||||||
|
},
|
||||||
initialData: {
|
initialData: {
|
||||||
pageParams: [undefined, 1],
|
pageParams: [undefined, 1],
|
||||||
pages: [initialUpcomingStays],
|
pages: [initialUpcomingStays],
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import SectionLink from "@/components/Section/Link"
|
|||||||
import ClientUpcomingStays from "./Client"
|
import ClientUpcomingStays from "./Client"
|
||||||
import EmptyUpcomingStaysBlock from "./EmptyUpcomingStays"
|
import EmptyUpcomingStaysBlock from "./EmptyUpcomingStays"
|
||||||
|
|
||||||
|
import styles from "./upcoming.module.css"
|
||||||
|
|
||||||
import type { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"
|
import type { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"
|
||||||
|
|
||||||
export default async function UpcomingStays({
|
export default async function UpcomingStays({
|
||||||
@@ -14,14 +16,14 @@ export default async function UpcomingStays({
|
|||||||
subtitle,
|
subtitle,
|
||||||
link,
|
link,
|
||||||
}: AccountPageComponentProps) {
|
}: AccountPageComponentProps) {
|
||||||
const initialUpcomingStays = await serverClient().user.stays.upcoming()
|
const initialUpcomingStays = await serverClient().user.stays.upcoming({
|
||||||
if (!initialUpcomingStays?.data) {
|
limit: 6,
|
||||||
return null
|
})
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<SectionContainer>
|
<SectionContainer className={styles.container}>
|
||||||
<SectionHeader title={title} subtitle={subtitle} link={link} />
|
<SectionHeader title={title} subtitle={subtitle} link={link} />
|
||||||
{initialUpcomingStays.data.length ? (
|
{initialUpcomingStays?.data.length ? (
|
||||||
<ClientUpcomingStays initialUpcomingStays={initialUpcomingStays} />
|
<ClientUpcomingStays initialUpcomingStays={initialUpcomingStays} />
|
||||||
) : (
|
) : (
|
||||||
<EmptyUpcomingStaysBlock />
|
<EmptyUpcomingStaysBlock />
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.container {
|
||||||
|
display: inline-grid;
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ import type {
|
|||||||
RequestOptionsWithJSONBody,
|
RequestOptionsWithJSONBody,
|
||||||
RequestOptionsWithOutBody,
|
RequestOptionsWithOutBody,
|
||||||
} from "@/types/fetch"
|
} from "@/types/fetch"
|
||||||
import type { Endpoint, endpoints } from "./endpoints"
|
import type { Endpoint } from "./endpoints"
|
||||||
|
|
||||||
export { endpoints } from "./endpoints"
|
export { endpoints } from "./endpoints"
|
||||||
|
|
||||||
@@ -26,13 +26,13 @@ const fetch = fetchRetry(global.fetch, {
|
|||||||
return Math.pow(2, attempt) * 150 // 150, 300, 600
|
return Math.pow(2, attempt) * 150 // 150, 300, 600
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
const url = new URL(env.API_BASEURL)
|
|
||||||
|
|
||||||
export async function get(
|
export async function get(
|
||||||
endpoint: Endpoint | `${Endpoint}/${string}`,
|
endpoint: Endpoint | `${Endpoint}/${string}`,
|
||||||
options: RequestOptionsWithOutBody,
|
options: RequestOptionsWithOutBody,
|
||||||
params = {}
|
params = {}
|
||||||
) {
|
) {
|
||||||
|
const url = new URL(env.API_BASEURL)
|
||||||
url.pathname = endpoint
|
url.pathname = endpoint
|
||||||
const searchParams = new URLSearchParams(params)
|
const searchParams = new URLSearchParams(params)
|
||||||
if (searchParams.size) {
|
if (searchParams.size) {
|
||||||
@@ -50,6 +50,7 @@ export async function patch(
|
|||||||
params = {}
|
params = {}
|
||||||
) {
|
) {
|
||||||
const { body, ...requestOptions } = options
|
const { body, ...requestOptions } = options
|
||||||
|
const url = new URL(env.API_BASEURL)
|
||||||
url.pathname = endpoint
|
url.pathname = endpoint
|
||||||
const searchParams = new URLSearchParams(params)
|
const searchParams = new URLSearchParams(params)
|
||||||
if (searchParams.size) {
|
if (searchParams.size) {
|
||||||
@@ -71,9 +72,10 @@ export async function patch(
|
|||||||
export async function post(
|
export async function post(
|
||||||
endpoint: Endpoint | `${Endpoint}/${string}`,
|
endpoint: Endpoint | `${Endpoint}/${string}`,
|
||||||
options: RequestOptionsWithJSONBody,
|
options: RequestOptionsWithJSONBody,
|
||||||
params = {},
|
params = {}
|
||||||
) {
|
) {
|
||||||
const { body, ...requestOptions } = options
|
const { body, ...requestOptions } = options
|
||||||
|
const url = new URL(env.API_BASEURL)
|
||||||
url.pathname = endpoint
|
url.pathname = endpoint
|
||||||
const searchParams = new URLSearchParams(params)
|
const searchParams = new URLSearchParams(params)
|
||||||
if (searchParams.size) {
|
if (searchParams.size) {
|
||||||
@@ -95,8 +97,9 @@ export async function post(
|
|||||||
export async function remove(
|
export async function remove(
|
||||||
endpoint: Endpoint | `${Endpoint}/${string}`,
|
endpoint: Endpoint | `${Endpoint}/${string}`,
|
||||||
options: RequestOptionsWithOutBody,
|
options: RequestOptionsWithOutBody,
|
||||||
params = {},
|
params = {}
|
||||||
) {
|
) {
|
||||||
|
const url = new URL(env.API_BASEURL)
|
||||||
url.pathname = endpoint
|
url.pathname = endpoint
|
||||||
const searchParams = new URLSearchParams(params)
|
const searchParams = new URLSearchParams(params)
|
||||||
if (searchParams.size) {
|
if (searchParams.size) {
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ export const friendTransactionsInput = z
|
|||||||
})
|
})
|
||||||
.default({ limit: 5, page: 1 })
|
.default({ limit: 5, page: 1 })
|
||||||
|
|
||||||
|
|
||||||
// Mutation
|
// Mutation
|
||||||
export const addCreditCardInput = z.object({
|
export const addCreditCardInput = z.object({
|
||||||
language: z.string(),
|
language: z.string(),
|
||||||
|
|||||||
@@ -379,16 +379,6 @@ export const userQueryRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
// switch (apiResponse.status) {
|
|
||||||
// case 400:
|
|
||||||
// throw badRequestError(apiResponse)
|
|
||||||
// case 401:
|
|
||||||
// throw unauthorizedError(apiResponse)
|
|
||||||
// case 403:
|
|
||||||
// throw forbiddenError(apiResponse)
|
|
||||||
// default:
|
|
||||||
// throw internalServerError(apiResponse)
|
|
||||||
// }
|
|
||||||
const text = await apiResponse.text()
|
const text = await apiResponse.text()
|
||||||
console.error(
|
console.error(
|
||||||
"api.booking.stays.past error ",
|
"api.booking.stays.past error ",
|
||||||
@@ -464,16 +454,6 @@ export const userQueryRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
// switch (apiResponse.status) {
|
|
||||||
// case 400:
|
|
||||||
// throw badRequestError(apiResponse)
|
|
||||||
// case 401:
|
|
||||||
// throw unauthorizedError(apiResponse)
|
|
||||||
// case 403:
|
|
||||||
// throw forbiddenError(apiResponse)
|
|
||||||
// default:
|
|
||||||
// throw internalServerError(apiResponse)
|
|
||||||
// }
|
|
||||||
const text = await apiResponse.text()
|
const text = await apiResponse.text()
|
||||||
console.error(
|
console.error(
|
||||||
"api.booking.stays.future error ",
|
"api.booking.stays.future error ",
|
||||||
|
|||||||
Reference in New Issue
Block a user