feat(private-room): migrate to album APIs
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
buildPrivateAlbumGalleryUrl,
|
||||
buildPrivateRoomWithoutGalleryUrl,
|
||||
getPrivateAlbumGalleryState,
|
||||
} from "../private-album-gallery-url";
|
||||
|
||||
describe("private album gallery URL", () => {
|
||||
it("builds and parses an album image URL", () => {
|
||||
const url = buildPrivateAlbumGalleryUrl("album:91", 3);
|
||||
const params = new URL(url, "https://cozsweet.test").searchParams;
|
||||
|
||||
expect(url).toBe("/private-room?album=album%3A91&image=3");
|
||||
expect(getPrivateAlbumGalleryState(params)).toEqual({
|
||||
albumId: "album:91",
|
||||
imageIndex: 3,
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects missing albums and invalid image indexes", () => {
|
||||
expect(getPrivateAlbumGalleryState(new URLSearchParams("image=0"))).toBeNull();
|
||||
expect(
|
||||
getPrivateAlbumGalleryState(
|
||||
new URLSearchParams("album=album-1&image=-1"),
|
||||
),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("removes gallery params without dropping other query values", () => {
|
||||
expect(
|
||||
buildPrivateRoomWithoutGalleryUrl(
|
||||
new URLSearchParams("album=album-1&image=2&source=external"),
|
||||
),
|
||||
).toBe("/private-room?source=external");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,91 @@
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { PrivateAlbum } from "@/data/dto/private-room";
|
||||
|
||||
import { PrivateAlbumCard } from "../private-album-card";
|
||||
|
||||
const COVER_URL = "/images/private-room/banner.png";
|
||||
|
||||
function makeAlbum(
|
||||
overrides: Partial<Parameters<typeof PrivateAlbum.from>[0]> = {},
|
||||
): PrivateAlbum {
|
||||
return PrivateAlbum.from({
|
||||
albumId: "album-1",
|
||||
title: "Private morning",
|
||||
content: "A quiet morning by the water.",
|
||||
previewText: "Only for you.",
|
||||
imageCount: 8,
|
||||
images: [],
|
||||
locked: false,
|
||||
unlocked: true,
|
||||
unlockCost: 320,
|
||||
publishedAt: "2026-07-01T08:11:35+00:00",
|
||||
lockDetail: { locked: false },
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
function renderCard(album: PrivateAlbum): string {
|
||||
return renderToStaticMarkup(
|
||||
<PrivateAlbumCard
|
||||
album={album}
|
||||
displayName="Elio Silvestri"
|
||||
avatarUrl="/images/chat/pic-chat-elio.png"
|
||||
index={0}
|
||||
isUnlocking={false}
|
||||
onOpenGallery={() => undefined}
|
||||
onUnlock={() => undefined}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("PrivateAlbumCard", () => {
|
||||
it("renders only the first unlocked image and its photo count", () => {
|
||||
const html = renderCard(
|
||||
makeAlbum({
|
||||
imageCount: 8,
|
||||
images: [
|
||||
{ url: COVER_URL, locked: false, index: 0 },
|
||||
{
|
||||
url: "/images/splash/pic-bg-home.png",
|
||||
locked: false,
|
||||
index: 1,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(html).toContain("banner.png");
|
||||
expect(html).not.toContain("pic-bg-home.png");
|
||||
expect(html).toContain("8 photos");
|
||||
expect(html).toContain("A quiet morning by the water.");
|
||||
expect(html).toContain('aria-label="Open 8 private album photos"');
|
||||
});
|
||||
|
||||
it("uses the backend first image as the locked cover", () => {
|
||||
const html = renderCard(
|
||||
makeAlbum({
|
||||
content: null,
|
||||
locked: true,
|
||||
unlocked: false,
|
||||
lockDetail: { locked: true },
|
||||
images: [{ url: COVER_URL, locked: true, index: 0 }],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(html).toContain("banner.png");
|
||||
expect(html).toContain(
|
||||
'aria-label="Unlock 8 private room photos from Elio Silvestri"',
|
||||
);
|
||||
expect(html).toContain("Only for you.");
|
||||
expect(html).toContain("320 credits");
|
||||
});
|
||||
|
||||
it("renders an empty cover when an unlocked album has no image", () => {
|
||||
const html = renderCard(makeAlbum());
|
||||
|
||||
expect(html).toContain('aria-label="No private album photo available"');
|
||||
expect(html).toContain("No photo available");
|
||||
});
|
||||
});
|
||||
@@ -1,106 +0,0 @@
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { PrivateRoomMoment } from "@/data/dto/private-room";
|
||||
|
||||
import { PrivateRoomPostCard } from "../private-room-post-card";
|
||||
|
||||
function makeMoment(
|
||||
overrides: Partial<Parameters<typeof PrivateRoomMoment.from>[0]> = {},
|
||||
): PrivateRoomMoment {
|
||||
return PrivateRoomMoment.from({
|
||||
momentId: "schedule:91",
|
||||
author: {
|
||||
id: "elio",
|
||||
name: "Elio Silvestri",
|
||||
avatarUrl: null,
|
||||
},
|
||||
publishedAt: "2026-07-01T08:11:35+00:00",
|
||||
timeText: "7 days ago",
|
||||
title: "Private morning",
|
||||
content: "A quiet morning by the water.",
|
||||
text: "A quiet morning by the water.",
|
||||
textPreview: "Unlock to view private room photos",
|
||||
mediaCount: 1,
|
||||
images: [],
|
||||
locked: false,
|
||||
unlockCost: 40,
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
function renderCard(moment: PrivateRoomMoment): string {
|
||||
return renderToStaticMarkup(
|
||||
<PrivateRoomPostCard
|
||||
moment={moment}
|
||||
displayName="Elio Silvestri"
|
||||
avatarUrl="/images/chat/pic-chat-elio.png"
|
||||
index={0}
|
||||
isUnlocking={false}
|
||||
onUnlock={() => undefined}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("PrivateRoomPostCard", () => {
|
||||
it("renders only the first unlocked image and a multi-photo badge", () => {
|
||||
const html = renderCard(
|
||||
makeMoment({
|
||||
mediaCount: 3,
|
||||
images: [
|
||||
{
|
||||
url: "/images/private-room/banner.png",
|
||||
type: "image",
|
||||
locked: false,
|
||||
index: 0,
|
||||
},
|
||||
{
|
||||
url: "/images/splash/pic-bg-home.png",
|
||||
type: "image",
|
||||
locked: false,
|
||||
index: 1,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(html).toContain("banner.png");
|
||||
expect(html).not.toContain("pic-bg-home.png");
|
||||
expect(html).toContain("3 photos");
|
||||
expect(html).toContain("A quiet morning by the water.");
|
||||
});
|
||||
|
||||
it("renders a locked cover without attempting to render a missing URL", () => {
|
||||
const html = renderCard(
|
||||
makeMoment({
|
||||
locked: true,
|
||||
mediaCount: 2,
|
||||
content: null,
|
||||
text: null,
|
||||
images: [
|
||||
{
|
||||
url: null,
|
||||
type: "image",
|
||||
locked: true,
|
||||
index: 0,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(html).toContain(
|
||||
'aria-label="Unlock 2 private room photos from Elio Silvestri"',
|
||||
);
|
||||
expect(html).toContain("Unlock to view private room photos");
|
||||
expect(html).toContain("40 credits");
|
||||
expect(html).toContain("2 photos");
|
||||
expect(html).not.toContain("No photo available");
|
||||
});
|
||||
|
||||
it("renders an empty cover when an unlocked moment has no first image", () => {
|
||||
const html = renderCard(makeMoment());
|
||||
|
||||
expect(html).toContain('aria-label="No private moment photo available"');
|
||||
expect(html).toContain("No photo available");
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./private-room-post-card";
|
||||
export * from "./private-album-card";
|
||||
export * from "./private-album-gallery";
|
||||
export * from "./status-card";
|
||||
export * from "./unlock-confirm-dialog";
|
||||
|
||||
+39
-23
@@ -3,33 +3,34 @@ import Image from "next/image";
|
||||
import { ImageIcon, LockKeyhole } from "lucide-react";
|
||||
|
||||
import { CharacterAvatar } from "@/app/_components";
|
||||
import type { PrivateRoomMoment } from "@/data/dto/private-room";
|
||||
import type { PrivateAlbum } from "@/data/dto/private-room";
|
||||
import { isPrivateAlbumLocked } from "@/lib/private-room/private_album";
|
||||
|
||||
import styles from "../private-room-screen.module.css";
|
||||
|
||||
export interface PrivateRoomPostCardProps {
|
||||
moment: PrivateRoomMoment;
|
||||
export interface PrivateAlbumCardProps {
|
||||
album: PrivateAlbum;
|
||||
displayName: string;
|
||||
avatarUrl: string;
|
||||
index: number;
|
||||
isUnlocking: boolean;
|
||||
onOpenGallery: () => void;
|
||||
onUnlock: () => void;
|
||||
}
|
||||
|
||||
export function PrivateRoomPostCard({
|
||||
moment,
|
||||
export function PrivateAlbumCard({
|
||||
album,
|
||||
displayName,
|
||||
avatarUrl,
|
||||
index,
|
||||
isUnlocking,
|
||||
onOpenGallery,
|
||||
onUnlock,
|
||||
}: PrivateRoomPostCardProps) {
|
||||
const isLocked = moment.locked;
|
||||
const firstImage = moment.images[0];
|
||||
const firstImageUrl =
|
||||
!isLocked && firstImage?.locked !== true ? firstImage?.url : null;
|
||||
const photoCount = moment.mediaCount || moment.images.length || 1;
|
||||
const postText = moment.text || moment.content;
|
||||
}: PrivateAlbumCardProps) {
|
||||
const isLocked = isPrivateAlbumLocked(album);
|
||||
const firstImage = album.images[0];
|
||||
const firstImageUrl = firstImage?.url || null;
|
||||
const photoCount = album.imageCount || album.images.length;
|
||||
|
||||
return (
|
||||
<article
|
||||
@@ -46,14 +47,14 @@ export function PrivateRoomPostCard({
|
||||
className={styles.postAvatar}
|
||||
/>
|
||||
<div>
|
||||
<p className={styles.authorName}>{moment.author.name || displayName}</p>
|
||||
<p className={styles.authorName}>{displayName}</p>
|
||||
<p className={styles.authorSubline}>
|
||||
{moment.title || "Private room drop"}
|
||||
{album.title || "Private album"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<time className={styles.postTime}>
|
||||
{moment.timeText || formatMomentTime(moment.publishedAt)}
|
||||
{formatAlbumTime(album.publishedAt)}
|
||||
</time>
|
||||
</header>
|
||||
|
||||
@@ -65,13 +66,23 @@ export function PrivateRoomPostCard({
|
||||
onClick={onUnlock}
|
||||
aria-label={`Unlock ${photoCount} private room photos from ${displayName}`}
|
||||
>
|
||||
{firstImageUrl ? (
|
||||
<Image
|
||||
src={firstImageUrl}
|
||||
alt=""
|
||||
fill
|
||||
sizes="(max-width: 540px) calc(100vw - 36px), 484px"
|
||||
className={styles.lockedCoverImage}
|
||||
/>
|
||||
) : null}
|
||||
<span className={styles.lockedPreviewScrim} aria-hidden="true" />
|
||||
<div className={styles.lockedPreviewContent}>
|
||||
<div className={styles.previewIcon}>
|
||||
<LockKeyhole size={22} aria-hidden="true" />
|
||||
</div>
|
||||
<div className={styles.previewText}>
|
||||
<span>{moment.textPreview || "Unlock to view"}</span>
|
||||
<strong>{moment.unlockCost} credits</strong>
|
||||
<span>{album.previewText || "Unlock to view"}</span>
|
||||
<strong>{album.unlockCost} credits</strong>
|
||||
<small>
|
||||
<ImageIcon size={13} aria-hidden="true" />
|
||||
{photoCount} {photoCount === 1 ? "photo" : "photos"}
|
||||
@@ -80,10 +91,15 @@ export function PrivateRoomPostCard({
|
||||
</div>
|
||||
</button>
|
||||
) : firstImageUrl ? (
|
||||
<div className={styles.mediaCover}>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.mediaCover}
|
||||
onClick={onOpenGallery}
|
||||
aria-label={`Open ${photoCount} private album photos`}
|
||||
>
|
||||
<Image
|
||||
src={firstImageUrl}
|
||||
alt={`${moment.title || displayName} private moment`}
|
||||
alt={`${album.title || displayName} private album`}
|
||||
width={720}
|
||||
height={900}
|
||||
className={styles.momentCoverImage}
|
||||
@@ -95,24 +111,24 @@ export function PrivateRoomPostCard({
|
||||
{photoCount} photos
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</button>
|
||||
) : (
|
||||
<div
|
||||
className={styles.emptyMediaCover}
|
||||
role="img"
|
||||
aria-label="No private moment photo available"
|
||||
aria-label="No private album photo available"
|
||||
>
|
||||
<ImageIcon size={32} aria-hidden="true" />
|
||||
<span>No photo available</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{postText ? <p className={styles.postText}>{postText}</p> : null}
|
||||
{album.content ? <p className={styles.postText}>{album.content}</p> : null}
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
function formatMomentTime(value: string | null): string {
|
||||
function formatAlbumTime(value: string | null): string {
|
||||
if (!value) return "";
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return "";
|
||||
@@ -0,0 +1,113 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import Image from "next/image";
|
||||
import { ChevronLeft, ChevronRight, X } from "lucide-react";
|
||||
|
||||
import type { PrivateAlbum } from "@/data/dto/private-room";
|
||||
|
||||
import styles from "../private-room-screen.module.css";
|
||||
|
||||
export interface PrivateAlbumGalleryProps {
|
||||
album: PrivateAlbum;
|
||||
imageIndex: number;
|
||||
onClose: () => void;
|
||||
onImageIndexChange: (index: number) => void;
|
||||
}
|
||||
|
||||
export function PrivateAlbumGallery({
|
||||
album,
|
||||
imageIndex,
|
||||
onClose,
|
||||
onImageIndexChange,
|
||||
}: PrivateAlbumGalleryProps) {
|
||||
const touchStartXRef = useRef<number | null>(null);
|
||||
const currentImage = album.images[imageIndex];
|
||||
const hasPrevious = imageIndex > 0;
|
||||
const hasNext = imageIndex < album.images.length - 1;
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") onClose();
|
||||
if (event.key === "ArrowLeft" && hasPrevious) {
|
||||
onImageIndexChange(imageIndex - 1);
|
||||
}
|
||||
if (event.key === "ArrowRight" && hasNext) {
|
||||
onImageIndexChange(imageIndex + 1);
|
||||
}
|
||||
};
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
return () => document.removeEventListener("keydown", handleKeyDown);
|
||||
}, [hasNext, hasPrevious, imageIndex, onClose, onImageIndexChange]);
|
||||
|
||||
if (!currentImage?.url) return null;
|
||||
|
||||
const handleTouchEnd = (event: React.TouchEvent) => {
|
||||
const touchStartX = touchStartXRef.current;
|
||||
touchStartXRef.current = null;
|
||||
if (touchStartX === null) return;
|
||||
const delta = event.changedTouches[0]?.clientX ?? touchStartX;
|
||||
const distance = delta - touchStartX;
|
||||
if (distance > 48 && hasPrevious) onImageIndexChange(imageIndex - 1);
|
||||
if (distance < -48 && hasNext) onImageIndexChange(imageIndex + 1);
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={styles.galleryOverlay}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={album.title || "Private album gallery"}
|
||||
onTouchStart={(event) => {
|
||||
touchStartXRef.current = event.touches[0]?.clientX ?? null;
|
||||
}}
|
||||
onTouchEnd={handleTouchEnd}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.galleryClose}
|
||||
onClick={onClose}
|
||||
aria-label="Close private album gallery"
|
||||
>
|
||||
<X size={24} aria-hidden="true" />
|
||||
</button>
|
||||
|
||||
<div className={styles.galleryImageFrame}>
|
||||
<Image
|
||||
src={currentImage.url}
|
||||
alt={`${album.title || "Private album"} photo ${imageIndex + 1}`}
|
||||
fill
|
||||
priority
|
||||
draggable={false}
|
||||
sizes="(max-width: 540px) 100vw, 540px"
|
||||
className={styles.galleryImage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<span className={styles.galleryCounter}>
|
||||
{imageIndex + 1} / {album.images.length}
|
||||
</span>
|
||||
|
||||
{hasPrevious ? (
|
||||
<button
|
||||
type="button"
|
||||
className={`${styles.galleryNav} ${styles.galleryPrevious}`}
|
||||
onClick={() => onImageIndexChange(imageIndex - 1)}
|
||||
aria-label="Previous photo"
|
||||
>
|
||||
<ChevronLeft size={30} aria-hidden="true" />
|
||||
</button>
|
||||
) : null}
|
||||
{hasNext ? (
|
||||
<button
|
||||
type="button"
|
||||
className={`${styles.galleryNav} ${styles.galleryNext}`}
|
||||
onClick={() => onImageIndexChange(imageIndex + 1)}
|
||||
aria-label="Next photo"
|
||||
>
|
||||
<ChevronRight size={30} aria-hidden="true" />
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { PrivateRoomMoment } from "@/data/dto/private-room";
|
||||
import type { PrivateAlbum } from "@/data/dto/private-room";
|
||||
|
||||
import styles from "../private-room-screen.module.css";
|
||||
|
||||
export interface UnlockConfirmDialogProps {
|
||||
moment: PrivateRoomMoment;
|
||||
album: PrivateAlbum;
|
||||
isUnlocking: boolean;
|
||||
errorMessage: string | null;
|
||||
onCancel: () => void;
|
||||
@@ -11,7 +11,7 @@ export interface UnlockConfirmDialogProps {
|
||||
}
|
||||
|
||||
export function UnlockConfirmDialog({
|
||||
moment,
|
||||
album,
|
||||
isUnlocking,
|
||||
errorMessage,
|
||||
onCancel,
|
||||
@@ -20,9 +20,9 @@ export function UnlockConfirmDialog({
|
||||
return (
|
||||
<div className={styles.dialogOverlay} role="alertdialog" aria-modal="true">
|
||||
<div className={styles.dialog}>
|
||||
<h2 className={styles.dialogTitle}>Unlock private moment?</h2>
|
||||
<h2 className={styles.dialogTitle}>Unlock private album?</h2>
|
||||
<p className={styles.dialogCopy}>
|
||||
This will use {moment.unlockCost} credits.
|
||||
Unlock {album.imageCount} photos for {album.unlockCost} credits.
|
||||
</p>
|
||||
{errorMessage ? (
|
||||
<p className={styles.dialogError}>{errorMessage}</p>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { ROUTES } from "@/router/routes";
|
||||
|
||||
export const PRIVATE_ALBUM_QUERY_PARAM = "album";
|
||||
export const PRIVATE_ALBUM_IMAGE_QUERY_PARAM = "image";
|
||||
|
||||
export function getPrivateAlbumGalleryState(input: {
|
||||
get: (key: string) => string | null;
|
||||
}): { albumId: string; imageIndex: number } | null {
|
||||
const albumId = input.get(PRIVATE_ALBUM_QUERY_PARAM)?.trim();
|
||||
const imageIndex = Number(input.get(PRIVATE_ALBUM_IMAGE_QUERY_PARAM) ?? "0");
|
||||
if (!albumId || !Number.isInteger(imageIndex) || imageIndex < 0) return null;
|
||||
return { albumId, imageIndex };
|
||||
}
|
||||
|
||||
export function buildPrivateAlbumGalleryUrl(
|
||||
albumId: string,
|
||||
imageIndex: number,
|
||||
): `/private-room?${string}` {
|
||||
const params = new URLSearchParams({
|
||||
[PRIVATE_ALBUM_QUERY_PARAM]: albumId,
|
||||
[PRIVATE_ALBUM_IMAGE_QUERY_PARAM]: String(imageIndex),
|
||||
});
|
||||
return `${ROUTES.privateRoom}?${params.toString()}` as const;
|
||||
}
|
||||
|
||||
export function buildPrivateRoomWithoutGalleryUrl(input: {
|
||||
toString: () => string;
|
||||
}): string {
|
||||
const params = new URLSearchParams(input.toString());
|
||||
params.delete(PRIVATE_ALBUM_QUERY_PARAM);
|
||||
params.delete(PRIVATE_ALBUM_IMAGE_QUERY_PARAM);
|
||||
const query = params.toString();
|
||||
return query ? `${ROUTES.privateRoom}?${query}` : ROUTES.privateRoom;
|
||||
}
|
||||
@@ -121,8 +121,7 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.primaryCta,
|
||||
.loadMoreButton {
|
||||
.primaryCta {
|
||||
display: inline-flex;
|
||||
min-height: 48px;
|
||||
align-items: center;
|
||||
@@ -320,7 +319,7 @@
|
||||
|
||||
.lockedPreviewContent {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
max-width: 260px;
|
||||
flex-direction: column;
|
||||
@@ -328,6 +327,19 @@
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.lockedCoverImage {
|
||||
object-fit: cover;
|
||||
filter: blur(18px);
|
||||
transform: scale(1.08);
|
||||
}
|
||||
|
||||
.lockedPreviewScrim {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 1;
|
||||
background: rgba(28, 19, 23, 0.46);
|
||||
}
|
||||
|
||||
.previewIcon {
|
||||
display: grid;
|
||||
width: 58px;
|
||||
@@ -374,10 +386,17 @@
|
||||
|
||||
.mediaCover {
|
||||
position: relative;
|
||||
display: block;
|
||||
width: 100%;
|
||||
margin-top: 14px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
overflow: hidden;
|
||||
border-radius: clamp(20px, 5.185vw, 28px);
|
||||
background: #f3eef0;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
text-align: inherit;
|
||||
box-shadow: 0 14px 32px rgba(131, 72, 85, 0.14);
|
||||
}
|
||||
|
||||
@@ -439,16 +458,87 @@
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.statusCard button,
|
||||
.loadMoreButton {
|
||||
.statusCard button {
|
||||
padding: 0 18px;
|
||||
background: rgba(255, 93, 149, 0.12);
|
||||
color: #a94c64;
|
||||
}
|
||||
|
||||
.loadMoreButton {
|
||||
width: 100%;
|
||||
margin-top: 16px;
|
||||
.galleryOverlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 80;
|
||||
width: min(100vw, var(--app-max-width, 540px));
|
||||
height: var(--app-viewport-height, 100dvh);
|
||||
margin-inline: auto;
|
||||
overflow: hidden;
|
||||
background: #090909;
|
||||
color: #ffffff;
|
||||
touch-action: pan-y;
|
||||
}
|
||||
|
||||
.galleryImageFrame {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
}
|
||||
|
||||
.galleryImage {
|
||||
object-fit: contain;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.galleryClose,
|
||||
.galleryNav {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 0;
|
||||
border: 1px solid rgba(255, 255, 255, 0.18);
|
||||
border-radius: 999px;
|
||||
background: rgba(16, 16, 16, 0.58);
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
backdrop-filter: blur(12px);
|
||||
transition: background 0.18s ease, transform 0.18s ease;
|
||||
}
|
||||
|
||||
.galleryClose {
|
||||
top: calc(var(--app-safe-top, 0px) + 14px);
|
||||
right: calc(var(--app-safe-right, 0px) + 14px);
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
}
|
||||
|
||||
.galleryNav {
|
||||
top: 50%;
|
||||
width: 46px;
|
||||
height: 46px;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
.galleryPrevious {
|
||||
left: calc(var(--app-safe-left, 0px) + 10px);
|
||||
}
|
||||
|
||||
.galleryNext {
|
||||
right: calc(var(--app-safe-right, 0px) + 10px);
|
||||
}
|
||||
|
||||
.galleryCounter {
|
||||
position: absolute;
|
||||
bottom: calc(var(--app-safe-bottom, 0px) + 18px);
|
||||
left: 50%;
|
||||
z-index: 2;
|
||||
min-width: 62px;
|
||||
padding: 8px 12px;
|
||||
border-radius: 999px;
|
||||
background: rgba(16, 16, 16, 0.62);
|
||||
font-size: 13px;
|
||||
font-weight: 800;
|
||||
text-align: center;
|
||||
transform: translateX(-50%);
|
||||
backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
.dialogOverlay {
|
||||
@@ -535,21 +625,42 @@
|
||||
}
|
||||
|
||||
.primaryCta:hover,
|
||||
.lockedPreview:hover,
|
||||
.loadMoreButton:hover {
|
||||
.lockedPreview:hover {
|
||||
filter: brightness(1.04);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.mediaCover:hover {
|
||||
filter: brightness(1.02);
|
||||
}
|
||||
|
||||
.galleryClose:hover,
|
||||
.galleryNav:hover {
|
||||
background: rgba(38, 38, 38, 0.82);
|
||||
}
|
||||
|
||||
.primaryCta:active,
|
||||
.lockedPreview:active,
|
||||
.loadMoreButton:active {
|
||||
.lockedPreview:active {
|
||||
transform: translateY(1px) scale(0.99);
|
||||
}
|
||||
|
||||
.mediaCover:active {
|
||||
transform: scale(0.995);
|
||||
}
|
||||
|
||||
.galleryClose:active {
|
||||
transform: scale(0.94);
|
||||
}
|
||||
|
||||
.galleryNav:active {
|
||||
transform: translateY(-50%) scale(0.94);
|
||||
}
|
||||
|
||||
.primaryCta:focus-visible,
|
||||
.lockedPreview:focus-visible,
|
||||
.loadMoreButton:focus-visible,
|
||||
.mediaCover:focus-visible,
|
||||
.galleryClose:focus-visible,
|
||||
.galleryNav:focus-visible,
|
||||
.dialogPrimary:focus-visible,
|
||||
.dialogSecondary:focus-visible {
|
||||
outline: 2px solid #ff5d95;
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
import { useEffect, useMemo, useRef } from "react";
|
||||
import Image from "next/image";
|
||||
import { RefreshCw } from "lucide-react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
|
||||
import { CharacterAvatar } from "@/app/_components";
|
||||
import { AppBottomNav, MobileShell } from "@/app/_components/core";
|
||||
import { ROUTES } from "@/router/routes";
|
||||
import { useAppNavigator } from "@/router/use-app-navigator";
|
||||
import { isPrivateAlbumLocked } from "@/lib/private-room/private_album";
|
||||
import { useAuthDispatch, useAuthState } from "@/stores/auth/auth-context";
|
||||
import {
|
||||
usePrivateRoomDispatch,
|
||||
@@ -15,7 +16,8 @@ import {
|
||||
} from "@/stores/private-room";
|
||||
|
||||
import {
|
||||
PrivateRoomPostCard,
|
||||
PrivateAlbumCard,
|
||||
PrivateAlbumGallery,
|
||||
StatusCard,
|
||||
UnlockConfirmDialog,
|
||||
} from "./components";
|
||||
@@ -26,21 +28,32 @@ import {
|
||||
usePrivateRoomUnlockPaywallNavigation,
|
||||
usePrivateRoomUnlockSuccessRefresh,
|
||||
} from "./use-private-room-flow";
|
||||
import {
|
||||
buildPrivateAlbumGalleryUrl,
|
||||
buildPrivateRoomWithoutGalleryUrl,
|
||||
getPrivateAlbumGalleryState,
|
||||
} from "./private-album-gallery-url";
|
||||
|
||||
const FALLBACK_PROFILE = {
|
||||
name: "Elio Silvestri",
|
||||
handle: "@elio.private",
|
||||
avatar: "/images/chat/pic-chat-elio.png",
|
||||
title: "Elio Private room",
|
||||
subtitle: "Join me, unlock my private room",
|
||||
} as const;
|
||||
|
||||
export function PrivateRoomScreen() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const navigator = useAppNavigator();
|
||||
const authState = useAuthState();
|
||||
const authDispatch = useAuthDispatch();
|
||||
const state = usePrivateRoomState();
|
||||
const dispatch = usePrivateRoomDispatch();
|
||||
const openedGalleryInPageRef = useRef(false);
|
||||
const galleryState = useMemo(
|
||||
() => getPrivateAlbumGalleryState(searchParams),
|
||||
[searchParams],
|
||||
);
|
||||
|
||||
usePrivateRoomBootstrapFlow({
|
||||
authDispatch,
|
||||
@@ -57,19 +70,39 @@ export function PrivateRoomScreen() {
|
||||
});
|
||||
usePrivateRoomUnlockSuccessRefresh(state.unlockSuccessNonce);
|
||||
|
||||
const profile = state.profile;
|
||||
const displayName =
|
||||
profile?.displayName || profile?.authorName || FALLBACK_PROFILE.name;
|
||||
const avatarUrl = profile?.avatarUrl || FALLBACK_PROFILE.avatar;
|
||||
const title = profile?.title || FALLBACK_PROFILE.title;
|
||||
const subtitle = profile?.subtitle || FALLBACK_PROFILE.subtitle;
|
||||
const pendingMoment = useMemo(
|
||||
const displayName = FALLBACK_PROFILE.name;
|
||||
const avatarUrl = FALLBACK_PROFILE.avatar;
|
||||
const title = FALLBACK_PROFILE.title;
|
||||
const subtitle = FALLBACK_PROFILE.subtitle;
|
||||
const pendingAlbum = useMemo(
|
||||
() =>
|
||||
state.items.find(
|
||||
(item) => item.momentId === state.pendingConfirmMomentId,
|
||||
(album) => album.albumId === state.pendingConfirmAlbumId,
|
||||
) ?? null,
|
||||
[state.items, state.pendingConfirmMomentId],
|
||||
[state.items, state.pendingConfirmAlbumId],
|
||||
);
|
||||
const galleryAlbum = useMemo(
|
||||
() =>
|
||||
galleryState
|
||||
? state.items.find((album) => album.albumId === galleryState.albumId) ??
|
||||
null
|
||||
: null,
|
||||
[galleryState, state.items],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!galleryState || state.isLoading) return;
|
||||
const image = galleryAlbum?.images[galleryState.imageIndex];
|
||||
if (
|
||||
!galleryAlbum ||
|
||||
isPrivateAlbumLocked(galleryAlbum) ||
|
||||
!image?.url
|
||||
) {
|
||||
router.replace(buildPrivateRoomWithoutGalleryUrl(searchParams), {
|
||||
scroll: false,
|
||||
});
|
||||
}
|
||||
}, [galleryAlbum, galleryState, router, searchParams, state.isLoading]);
|
||||
|
||||
const handleTopUpClick = () => {
|
||||
if (isPrivateRoomAuthRequired(authState.loginStatus)) {
|
||||
@@ -79,6 +112,30 @@ export function PrivateRoomScreen() {
|
||||
navigator.openSubscription({ type: "topup" });
|
||||
};
|
||||
|
||||
const handleOpenGallery = (albumId: string) => {
|
||||
openedGalleryInPageRef.current = true;
|
||||
router.push(buildPrivateAlbumGalleryUrl(albumId, 0), { scroll: false });
|
||||
};
|
||||
|
||||
const handleCloseGallery = () => {
|
||||
if (openedGalleryInPageRef.current) {
|
||||
openedGalleryInPageRef.current = false;
|
||||
router.back();
|
||||
return;
|
||||
}
|
||||
router.replace(buildPrivateRoomWithoutGalleryUrl(searchParams), {
|
||||
scroll: false,
|
||||
});
|
||||
};
|
||||
|
||||
const handleGalleryIndexChange = (imageIndex: number) => {
|
||||
if (!galleryAlbum) return;
|
||||
router.replace(
|
||||
buildPrivateAlbumGalleryUrl(galleryAlbum.albumId, imageIndex),
|
||||
{ scroll: false },
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<MobileShell background="#f3f4f2">
|
||||
<main className={styles.shell}>
|
||||
@@ -124,9 +181,9 @@ export function PrivateRoomScreen() {
|
||||
<section className={styles.postsSection} aria-labelledby="posts-title">
|
||||
<div className={styles.sectionHeader}>
|
||||
<div>
|
||||
<p className={styles.kicker}>Posts</p>
|
||||
<p className={styles.kicker}>Albums</p>
|
||||
<h2 id="posts-title" className={styles.sectionTitle}>
|
||||
Private moments
|
||||
Private albums
|
||||
</h2>
|
||||
</div>
|
||||
<span className={styles.postCount}>{state.items.length}</span>
|
||||
@@ -141,47 +198,36 @@ export function PrivateRoomScreen() {
|
||||
) : null}
|
||||
|
||||
{state.isLoading && state.items.length === 0 ? (
|
||||
<StatusCard message="Loading private moments..." />
|
||||
<StatusCard message="Loading private albums..." />
|
||||
) : null}
|
||||
|
||||
{!state.isLoading && state.items.length === 0 && !state.errorMessage ? (
|
||||
<StatusCard
|
||||
message="No private moments yet."
|
||||
message="No private albums yet."
|
||||
actionLabel="Refresh"
|
||||
onAction={() => dispatch({ type: "PrivateRoomRefresh" })}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<div className={styles.timeline}>
|
||||
{state.items.map((moment, index) => (
|
||||
<PrivateRoomPostCard
|
||||
key={moment.momentId}
|
||||
moment={moment}
|
||||
{state.items.map((album, index) => (
|
||||
<PrivateAlbumCard
|
||||
key={album.albumId}
|
||||
album={album}
|
||||
displayName={displayName}
|
||||
avatarUrl={avatarUrl}
|
||||
index={index}
|
||||
isUnlocking={state.unlockingMomentId === moment.momentId}
|
||||
isUnlocking={state.unlockingAlbumId === album.albumId}
|
||||
onOpenGallery={() => handleOpenGallery(album.albumId)}
|
||||
onUnlock={() =>
|
||||
dispatch({
|
||||
type: "PrivateRoomUnlockRequested",
|
||||
momentId: moment.momentId,
|
||||
albumId: album.albumId,
|
||||
})
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{state.hasMore ? (
|
||||
<button
|
||||
type="button"
|
||||
className={styles.loadMoreButton}
|
||||
disabled={state.isLoadingMore}
|
||||
onClick={() => dispatch({ type: "PrivateRoomLoadMore" })}
|
||||
>
|
||||
<RefreshCw size={15} aria-hidden="true" />
|
||||
{state.isLoadingMore ? "Loading..." : "Load more"}
|
||||
</button>
|
||||
) : null}
|
||||
</section>
|
||||
|
||||
<AppBottomNav
|
||||
@@ -190,9 +236,9 @@ export function PrivateRoomScreen() {
|
||||
onPrivateRoomClick={() => undefined}
|
||||
/>
|
||||
|
||||
{pendingMoment ? (
|
||||
{pendingAlbum ? (
|
||||
<UnlockConfirmDialog
|
||||
moment={pendingMoment}
|
||||
album={pendingAlbum}
|
||||
isUnlocking={state.isUnlocking}
|
||||
errorMessage={state.unlockErrorMessage}
|
||||
onCancel={() => dispatch({ type: "PrivateRoomUnlockCancelled" })}
|
||||
@@ -203,6 +249,18 @@ export function PrivateRoomScreen() {
|
||||
{state.unlockErrorMessage}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{galleryAlbum &&
|
||||
galleryState &&
|
||||
!isPrivateAlbumLocked(galleryAlbum) &&
|
||||
galleryAlbum.images[galleryState.imageIndex]?.url ? (
|
||||
<PrivateAlbumGallery
|
||||
album={galleryAlbum}
|
||||
imageIndex={galleryState.imageIndex}
|
||||
onClose={handleCloseGallery}
|
||||
onImageIndexChange={handleGalleryIndexChange}
|
||||
/>
|
||||
) : null}
|
||||
</main>
|
||||
</MobileShell>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
PrivateAlbumsResponse,
|
||||
PrivateAlbumUnlockResponse,
|
||||
UnlockPrivateAlbumRequest,
|
||||
} from "@/data/dto/private-room";
|
||||
import { ApiPath } from "@/data/services/api";
|
||||
|
||||
const ALBUM_ID = "a1b2c3d4-0000-0000-0000-000000000000";
|
||||
const COVER_URL =
|
||||
"https://dbapi.banlv-ai.com/storage/v1/object/public/elio-schedules/01.jpg";
|
||||
|
||||
const lockedAlbum = {
|
||||
albumId: ALBUM_ID,
|
||||
momentId: `album:${ALBUM_ID}`,
|
||||
characterId: "elio",
|
||||
collectionKey: "manila_202607",
|
||||
title: "Private Manila set",
|
||||
content: null,
|
||||
previewText: "Only for you.",
|
||||
imageCount: 8,
|
||||
mediaCount: 8,
|
||||
images: [{ url: COVER_URL, type: "image", locked: true, index: 0 }],
|
||||
locked: true,
|
||||
unlocked: false,
|
||||
unlockCost: 320,
|
||||
requiredCredits: 320,
|
||||
creditCostPerImage: 40,
|
||||
currency: "credits",
|
||||
canUnlockWithCredits: false,
|
||||
publishedAt: "2026-07-13T00:00:00+00:00",
|
||||
lockDetail: {
|
||||
locked: true,
|
||||
showContent: false,
|
||||
showUpgrade: true,
|
||||
reason: "private_album",
|
||||
},
|
||||
};
|
||||
|
||||
describe("Private Album DTOs", () => {
|
||||
it("keeps a locked album cover URL while preserving the lock state", () => {
|
||||
const response = PrivateAlbumsResponse.fromJson({
|
||||
items: [lockedAlbum],
|
||||
creditBalance: 100,
|
||||
nextCursor: null,
|
||||
hasMore: false,
|
||||
});
|
||||
|
||||
expect(response.items[0]?.locked).toBe(true);
|
||||
expect(response.items[0]?.unlocked).toBe(false);
|
||||
expect(response.items[0]?.images[0]?.url).toBe(COVER_URL);
|
||||
expect(response.items[0]?.lockDetail).toEqual({ locked: true });
|
||||
});
|
||||
|
||||
it("strips response fields that are not used by the frontend", () => {
|
||||
const response = PrivateAlbumsResponse.fromJson({
|
||||
items: [lockedAlbum],
|
||||
creditBalance: 100,
|
||||
packageOptions: [{ imageCount: 8, creditCost: 320 }],
|
||||
});
|
||||
const albumJson = response.items[0]?.toJson();
|
||||
|
||||
expect(albumJson).not.toHaveProperty("momentId");
|
||||
expect(albumJson).not.toHaveProperty("characterId");
|
||||
expect(albumJson).not.toHaveProperty("collectionKey");
|
||||
expect(response.toJson()).not.toHaveProperty("packageOptions");
|
||||
});
|
||||
|
||||
it("parses an unlock response with all album images", () => {
|
||||
const response = PrivateAlbumUnlockResponse.fromJson({
|
||||
albumId: ALBUM_ID,
|
||||
locked: false,
|
||||
unlocked: true,
|
||||
reason: "ok",
|
||||
unlockCost: 320,
|
||||
creditBalance: 180,
|
||||
images: Array.from({ length: 8 }, (_, index) => ({
|
||||
url: `${COVER_URL}?image=${index}`,
|
||||
locked: false,
|
||||
index,
|
||||
})),
|
||||
creditsCharged: 320,
|
||||
});
|
||||
|
||||
expect(response.unlocked).toBe(true);
|
||||
expect(response.images).toHaveLength(8);
|
||||
expect(response.creditBalance).toBe(180);
|
||||
expect(response.toJson()).not.toHaveProperty("creditsCharged");
|
||||
});
|
||||
|
||||
it("serializes the expected unlock cost", () => {
|
||||
expect(
|
||||
UnlockPrivateAlbumRequest.from({ expectedCost: 320 }).toJson(),
|
||||
).toEqual({ expectedCost: 320 });
|
||||
});
|
||||
|
||||
it("encodes the album id in the unlock path", () => {
|
||||
expect(ApiPath.privateRoomAlbumUnlock("album:91")).toBe(
|
||||
"/api/private-room/albums/album%3A91/unlock",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,133 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
PrivateRoomMomentsResponse,
|
||||
PrivateRoomUnlockResponse,
|
||||
} from "@/data/dto/private-room";
|
||||
import { ApiPath } from "@/data/services/api";
|
||||
|
||||
const lockedMoment = {
|
||||
momentId: "schedule:91",
|
||||
source: "elio_schedules",
|
||||
sourceId: "91",
|
||||
characterId: "elio",
|
||||
author: {
|
||||
id: "elio",
|
||||
name: "Elio Silvestri",
|
||||
avatarUrl: null,
|
||||
},
|
||||
createdAt: "2026-07-01T08:11:35+00:00",
|
||||
publishedAt: "2026-07-01T08:11:35+00:00",
|
||||
timeText: "7 days ago",
|
||||
title: "Paris morning",
|
||||
content: null,
|
||||
text: null,
|
||||
textPreview: "Unlock to view private room photos",
|
||||
mediaCount: 1,
|
||||
images: [
|
||||
{
|
||||
url: null,
|
||||
type: "image",
|
||||
locked: true,
|
||||
index: 0,
|
||||
},
|
||||
],
|
||||
locked: true,
|
||||
unlocked: false,
|
||||
unlockCost: 40,
|
||||
unlockCostPerImage: 40,
|
||||
requiredCredits: 40,
|
||||
currency: "credits",
|
||||
lockDetail: {
|
||||
locked: true,
|
||||
showContent: false,
|
||||
showUpgrade: true,
|
||||
reason: "private_room_moment",
|
||||
hint: "40 credits · Unlock photo",
|
||||
actionLabel: "Unlock",
|
||||
type: "private_room_moment",
|
||||
requiredCredits: 40,
|
||||
currentCredits: 100,
|
||||
shortfallCredits: 0,
|
||||
mediaCount: 1,
|
||||
unlockCostPerImage: 40,
|
||||
},
|
||||
};
|
||||
|
||||
describe("PrivateRoom DTOs", () => {
|
||||
it("parses locked moments without image URLs", () => {
|
||||
const response = PrivateRoomMomentsResponse.from({
|
||||
profile: {
|
||||
characterId: "elio",
|
||||
displayName: "Elio Silvestri",
|
||||
authorName: "Elio Silvestri",
|
||||
avatarUrl: null,
|
||||
coverUrl: null,
|
||||
title: "Elio Private room",
|
||||
subtitle: "Join me, unlock my private room",
|
||||
},
|
||||
items: [lockedMoment],
|
||||
nextCursor: null,
|
||||
hasMore: false,
|
||||
creditBalance: 100,
|
||||
unlockCostDefault: 40,
|
||||
unlockCostPerImage: 40,
|
||||
currency: "credits",
|
||||
source: "elio_schedules",
|
||||
});
|
||||
|
||||
expect(response.items[0]?.locked).toBe(true);
|
||||
expect(response.items[0]?.images[0]?.url).toBeNull();
|
||||
expect(response.items[0]?.unlockCost).toBe(40);
|
||||
expect(response.profile.displayName).toBe("Elio Silvestri");
|
||||
});
|
||||
|
||||
it("parses unlock success with real image URLs", () => {
|
||||
const response = PrivateRoomUnlockResponse.from({
|
||||
...lockedMoment,
|
||||
locked: false,
|
||||
unlocked: true,
|
||||
content: "A quiet morning in Paris.",
|
||||
text: "A quiet morning in Paris.",
|
||||
images: [
|
||||
{
|
||||
url: "https://lehwkihwnlqkavhcspel.supabase.co/storage/v1/object/public/elio-schedules/schedules/91/photo.jpg",
|
||||
type: "image",
|
||||
locked: false,
|
||||
index: 0,
|
||||
},
|
||||
],
|
||||
reason: "ok",
|
||||
creditsCharged: 40,
|
||||
creditBalance: 60,
|
||||
previousCreditBalance: 100,
|
||||
persisted: true,
|
||||
});
|
||||
|
||||
expect(response.unlocked).toBe(true);
|
||||
expect(response.reason).toBe("ok");
|
||||
expect(response.images[0]?.url).toContain("https://");
|
||||
expect(response.creditBalance).toBe(60);
|
||||
});
|
||||
|
||||
it("parses insufficient credits as business data", () => {
|
||||
const response = PrivateRoomUnlockResponse.from({
|
||||
...lockedMoment,
|
||||
reason: "insufficient_credits",
|
||||
currentCredits: 10,
|
||||
shortfallCredits: 30,
|
||||
creditBalance: 10,
|
||||
});
|
||||
|
||||
expect(response.unlocked).toBe(false);
|
||||
expect(response.locked).toBe(true);
|
||||
expect(response.reason).toBe("insufficient_credits");
|
||||
expect(response.images[0]?.url).toBeNull();
|
||||
});
|
||||
|
||||
it("encodes moment id in the unlock path", () => {
|
||||
expect(ApiPath.privateRoomMomentUnlock("schedule:91")).toBe(
|
||||
"/api/private-room/moments/schedule%3A91/unlock",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from "./private_room_moment";
|
||||
export * from "./private_album";
|
||||
export * from "./request";
|
||||
export * from "./response";
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import {
|
||||
PrivateAlbumSchema,
|
||||
type PrivateAlbumData,
|
||||
type PrivateAlbumInput,
|
||||
} from "@/data/schemas/private-room";
|
||||
|
||||
export class PrivateAlbum {
|
||||
declare readonly albumId: string;
|
||||
declare readonly title: string;
|
||||
declare readonly content: string | null;
|
||||
declare readonly previewText: string;
|
||||
declare readonly imageCount: number;
|
||||
declare readonly images: PrivateAlbumData["images"];
|
||||
declare readonly locked: boolean;
|
||||
declare readonly unlocked: boolean;
|
||||
declare readonly unlockCost: number;
|
||||
declare readonly publishedAt: string | null;
|
||||
declare readonly lockDetail: PrivateAlbumData["lockDetail"];
|
||||
|
||||
private constructor(input: PrivateAlbumInput) {
|
||||
const data = PrivateAlbumSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: PrivateAlbumInput): PrivateAlbum {
|
||||
return new PrivateAlbum(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): PrivateAlbum {
|
||||
return PrivateAlbum.from(json as PrivateAlbumInput);
|
||||
}
|
||||
|
||||
toJson(): PrivateAlbumData {
|
||||
return PrivateAlbumSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import {
|
||||
PrivateRoomMomentSchema,
|
||||
type PrivateRoomMomentData,
|
||||
type PrivateRoomMomentInput,
|
||||
} from "@/data/schemas/private-room";
|
||||
|
||||
export class PrivateRoomMoment {
|
||||
declare readonly momentId: string;
|
||||
declare readonly author: PrivateRoomMomentData["author"];
|
||||
declare readonly publishedAt: string | null;
|
||||
declare readonly timeText: string;
|
||||
declare readonly title: string;
|
||||
declare readonly content: string | null;
|
||||
declare readonly text: string | null;
|
||||
declare readonly textPreview: string;
|
||||
declare readonly mediaCount: number;
|
||||
declare readonly images: PrivateRoomMomentData["images"];
|
||||
declare readonly locked: boolean;
|
||||
declare readonly unlockCost: number;
|
||||
|
||||
protected constructor(input: PrivateRoomMomentInput, freeze = true) {
|
||||
const data = PrivateRoomMomentSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
if (freeze) Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: PrivateRoomMomentInput): PrivateRoomMoment {
|
||||
return new PrivateRoomMoment(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): PrivateRoomMoment {
|
||||
return PrivateRoomMoment.from(json as PrivateRoomMomentInput);
|
||||
}
|
||||
|
||||
toJson(): PrivateRoomMomentData {
|
||||
return PrivateRoomMomentSchema.parse(this);
|
||||
}
|
||||
}
|
||||
|
||||
export type PrivateRoomProfile = import("@/data/schemas/private-room").PrivateRoomProfileData;
|
||||
@@ -1 +1 @@
|
||||
export * from "./unlock_private_room_moment_request";
|
||||
export * from "./unlock_private_album_request";
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import {
|
||||
UnlockPrivateAlbumRequestSchema,
|
||||
type UnlockPrivateAlbumRequestData,
|
||||
type UnlockPrivateAlbumRequestInput,
|
||||
} from "@/data/schemas/private-room";
|
||||
|
||||
export class UnlockPrivateAlbumRequest {
|
||||
private constructor(input: UnlockPrivateAlbumRequestInput) {
|
||||
const data = UnlockPrivateAlbumRequestSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: UnlockPrivateAlbumRequestInput): UnlockPrivateAlbumRequest {
|
||||
return new UnlockPrivateAlbumRequest(input);
|
||||
}
|
||||
|
||||
toJson(): UnlockPrivateAlbumRequestData {
|
||||
return UnlockPrivateAlbumRequestSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import {
|
||||
UnlockPrivateRoomMomentRequestSchema,
|
||||
type UnlockPrivateRoomMomentRequestData,
|
||||
type UnlockPrivateRoomMomentRequestInput,
|
||||
} from "@/data/schemas/private-room";
|
||||
|
||||
export class UnlockPrivateRoomMomentRequest {
|
||||
declare readonly expectedCost: number;
|
||||
|
||||
private constructor(input: UnlockPrivateRoomMomentRequestInput) {
|
||||
const data = UnlockPrivateRoomMomentRequestSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(
|
||||
input: UnlockPrivateRoomMomentRequestInput,
|
||||
): UnlockPrivateRoomMomentRequest {
|
||||
return new UnlockPrivateRoomMomentRequest(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): UnlockPrivateRoomMomentRequest {
|
||||
return UnlockPrivateRoomMomentRequest.from(
|
||||
json as UnlockPrivateRoomMomentRequestInput,
|
||||
);
|
||||
}
|
||||
|
||||
toJson(): UnlockPrivateRoomMomentRequestData {
|
||||
return UnlockPrivateRoomMomentRequestSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from "./private_room_moments_response";
|
||||
export * from "./private_room_unlock_response";
|
||||
export * from "./private_albums_response";
|
||||
export * from "./private_album_unlock_response";
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import {
|
||||
PrivateAlbumUnlockResponseSchema,
|
||||
type PrivateAlbumUnlockReason,
|
||||
type PrivateAlbumUnlockResponseData,
|
||||
type PrivateAlbumUnlockResponseInput,
|
||||
} from "@/data/schemas/private-room";
|
||||
|
||||
export class PrivateAlbumUnlockResponse {
|
||||
declare readonly albumId: string;
|
||||
declare readonly locked: boolean;
|
||||
declare readonly unlocked: boolean;
|
||||
declare readonly reason: PrivateAlbumUnlockReason | string;
|
||||
declare readonly unlockCost: number;
|
||||
declare readonly requiredCredits: number;
|
||||
declare readonly creditBalance: number;
|
||||
declare readonly shortfallCredits: number;
|
||||
declare readonly images: PrivateAlbumUnlockResponseData["images"];
|
||||
|
||||
private constructor(input: PrivateAlbumUnlockResponseInput) {
|
||||
const data = PrivateAlbumUnlockResponseSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: PrivateAlbumUnlockResponseInput): PrivateAlbumUnlockResponse {
|
||||
return new PrivateAlbumUnlockResponse(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): PrivateAlbumUnlockResponse {
|
||||
return PrivateAlbumUnlockResponse.from(
|
||||
json as PrivateAlbumUnlockResponseInput,
|
||||
);
|
||||
}
|
||||
|
||||
toJson(): PrivateAlbumUnlockResponseData {
|
||||
return PrivateAlbumUnlockResponseSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import {
|
||||
PrivateAlbumsResponseSchema,
|
||||
type PrivateAlbumsResponseData,
|
||||
type PrivateAlbumsResponseInput,
|
||||
} from "@/data/schemas/private-room";
|
||||
|
||||
import { PrivateAlbum } from "../private_album";
|
||||
|
||||
export class PrivateAlbumsResponse {
|
||||
declare readonly items: PrivateAlbum[];
|
||||
declare readonly creditBalance: number;
|
||||
|
||||
private constructor(input: PrivateAlbumsResponseInput) {
|
||||
const data = PrivateAlbumsResponseSchema.parse(input);
|
||||
Object.assign(this, {
|
||||
items: data.items.map((item) => PrivateAlbum.from(item)),
|
||||
creditBalance: data.creditBalance,
|
||||
});
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: PrivateAlbumsResponseInput): PrivateAlbumsResponse {
|
||||
return new PrivateAlbumsResponse(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): PrivateAlbumsResponse {
|
||||
return PrivateAlbumsResponse.from(json as PrivateAlbumsResponseInput);
|
||||
}
|
||||
|
||||
toJson(): PrivateAlbumsResponseData {
|
||||
return {
|
||||
items: this.items.map((item) => item.toJson()),
|
||||
creditBalance: this.creditBalance,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
import {
|
||||
PrivateRoomMomentsResponseSchema,
|
||||
type PrivateRoomMomentsResponseData,
|
||||
type PrivateRoomMomentsResponseInput,
|
||||
} from "@/data/schemas/private-room";
|
||||
|
||||
import { PrivateRoomMoment } from "../private_room_moment";
|
||||
|
||||
export class PrivateRoomMomentsResponse {
|
||||
declare readonly profile: PrivateRoomMomentsResponseData["profile"];
|
||||
declare readonly items: PrivateRoomMoment[];
|
||||
declare readonly nextCursor: string | null;
|
||||
declare readonly hasMore: boolean;
|
||||
declare readonly creditBalance: number;
|
||||
declare readonly unlockCostDefault: number;
|
||||
declare readonly unlockCostPerImage: number;
|
||||
declare readonly currency: string;
|
||||
declare readonly source: string;
|
||||
|
||||
private constructor(input: PrivateRoomMomentsResponseInput) {
|
||||
const data = PrivateRoomMomentsResponseSchema.parse(input);
|
||||
Object.assign(this, {
|
||||
...data,
|
||||
items: data.items.map((item) => PrivateRoomMoment.from(item)),
|
||||
});
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(
|
||||
input: PrivateRoomMomentsResponseInput,
|
||||
): PrivateRoomMomentsResponse {
|
||||
return new PrivateRoomMomentsResponse(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): PrivateRoomMomentsResponse {
|
||||
return PrivateRoomMomentsResponse.from(
|
||||
json as PrivateRoomMomentsResponseInput,
|
||||
);
|
||||
}
|
||||
|
||||
toJson(): PrivateRoomMomentsResponseData {
|
||||
return {
|
||||
profile: this.profile,
|
||||
items: this.items.map((item) => item.toJson()),
|
||||
nextCursor: this.nextCursor,
|
||||
hasMore: this.hasMore,
|
||||
creditBalance: this.creditBalance,
|
||||
unlockCostDefault: this.unlockCostDefault,
|
||||
unlockCostPerImage: this.unlockCostPerImage,
|
||||
currency: this.currency,
|
||||
source: this.source,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
import {
|
||||
PrivateRoomUnlockResponseSchema,
|
||||
type PrivateRoomUnlockReason,
|
||||
type PrivateRoomUnlockResponseData,
|
||||
type PrivateRoomUnlockResponseInput,
|
||||
} from "@/data/schemas/private-room";
|
||||
|
||||
import { PrivateRoomMoment } from "../private_room_moment";
|
||||
|
||||
export class PrivateRoomUnlockResponse extends PrivateRoomMoment {
|
||||
declare readonly unlocked: boolean;
|
||||
declare readonly requiredCredits: number;
|
||||
declare readonly reason: PrivateRoomUnlockReason | string;
|
||||
declare readonly creditsCharged: number;
|
||||
declare readonly creditBalance: number;
|
||||
declare readonly previousCreditBalance: number;
|
||||
declare readonly currentCredits: number;
|
||||
declare readonly shortfallCredits: number;
|
||||
declare readonly persisted: boolean;
|
||||
|
||||
private constructor(input: PrivateRoomUnlockResponseInput) {
|
||||
const data = PrivateRoomUnlockResponseSchema.parse(input);
|
||||
super(data, false);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static override from(
|
||||
input: PrivateRoomUnlockResponseInput,
|
||||
): PrivateRoomUnlockResponse {
|
||||
return new PrivateRoomUnlockResponse(input);
|
||||
}
|
||||
|
||||
static override fromJson(json: unknown): PrivateRoomUnlockResponse {
|
||||
return PrivateRoomUnlockResponse.from(
|
||||
json as PrivateRoomUnlockResponseInput,
|
||||
);
|
||||
}
|
||||
|
||||
override toJson(): PrivateRoomUnlockResponseData {
|
||||
return PrivateRoomUnlockResponseSchema.parse(this);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,21 @@
|
||||
import type {
|
||||
PrivateRoomMomentsResponse,
|
||||
PrivateRoomUnlockResponse,
|
||||
PrivateAlbumsResponse,
|
||||
PrivateAlbumUnlockResponse,
|
||||
} from "@/data/dto/private-room";
|
||||
import type { Result } from "@/utils/result";
|
||||
|
||||
export interface GetPrivateRoomMomentsInput {
|
||||
export interface GetPrivateAlbumsInput {
|
||||
character?: string;
|
||||
limit?: number;
|
||||
cursor?: string | null;
|
||||
}
|
||||
|
||||
export interface IPrivateRoomRepository {
|
||||
getMoments(
|
||||
input?: GetPrivateRoomMomentsInput,
|
||||
): Promise<Result<PrivateRoomMomentsResponse>>;
|
||||
getAlbums(
|
||||
input?: GetPrivateAlbumsInput,
|
||||
): Promise<Result<PrivateAlbumsResponse>>;
|
||||
|
||||
unlockMoment(
|
||||
momentId: string,
|
||||
unlockAlbum(
|
||||
albumId: string,
|
||||
expectedCost: number,
|
||||
): Promise<Result<PrivateRoomUnlockResponse>>;
|
||||
): Promise<Result<PrivateAlbumUnlockResponse>>;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
UnlockPrivateRoomMomentRequest,
|
||||
type PrivateRoomMomentsResponse,
|
||||
type PrivateRoomUnlockResponse,
|
||||
UnlockPrivateAlbumRequest,
|
||||
type PrivateAlbumsResponse,
|
||||
type PrivateAlbumUnlockResponse,
|
||||
} from "@/data/dto/private-room";
|
||||
import {
|
||||
PrivateRoomApi,
|
||||
privateRoomApi,
|
||||
} from "@/data/services/api/private_room_api";
|
||||
import type {
|
||||
GetPrivateRoomMomentsInput,
|
||||
GetPrivateAlbumsInput,
|
||||
IPrivateRoomRepository,
|
||||
} from "@/data/repositories/interfaces";
|
||||
import { Result } from "@/utils/result";
|
||||
@@ -20,20 +20,20 @@ import { createLazySingleton } from "./lazy_singleton";
|
||||
export class PrivateRoomRepository implements IPrivateRoomRepository {
|
||||
constructor(private readonly api: PrivateRoomApi) {}
|
||||
|
||||
getMoments(
|
||||
input: GetPrivateRoomMomentsInput = {},
|
||||
): Promise<Result<PrivateRoomMomentsResponse>> {
|
||||
return Result.wrap(() => this.api.getMoments(input));
|
||||
getAlbums(
|
||||
input: GetPrivateAlbumsInput = {},
|
||||
): Promise<Result<PrivateAlbumsResponse>> {
|
||||
return Result.wrap(() => this.api.getAlbums(input));
|
||||
}
|
||||
|
||||
unlockMoment(
|
||||
momentId: string,
|
||||
unlockAlbum(
|
||||
albumId: string,
|
||||
expectedCost: number,
|
||||
): Promise<Result<PrivateRoomUnlockResponse>> {
|
||||
): Promise<Result<PrivateAlbumUnlockResponse>> {
|
||||
return Result.wrap(() =>
|
||||
this.api.unlockMoment(
|
||||
momentId,
|
||||
UnlockPrivateRoomMomentRequest.from({ expectedCost }),
|
||||
this.api.unlockAlbum(
|
||||
albumId,
|
||||
UnlockPrivateAlbumRequest.from({ expectedCost }),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from "./private_room";
|
||||
export * from "./private_room_moments_response";
|
||||
export * from "./private_room_unlock_response";
|
||||
export * from "./unlock_private_room_moment_request";
|
||||
export * from "./private_album";
|
||||
export * from "./private_albums_response";
|
||||
export * from "./private_album_unlock_response";
|
||||
export * from "./unlock_private_album_request";
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
arrayOrEmpty,
|
||||
booleanOrFalse,
|
||||
numberOrZero,
|
||||
schemaOr,
|
||||
stringOrEmpty,
|
||||
stringOrNull,
|
||||
} from "../nullable-defaults";
|
||||
|
||||
export const PrivateAlbumImageSchema = z.object({
|
||||
url: stringOrEmpty,
|
||||
locked: booleanOrFalse,
|
||||
index: numberOrZero,
|
||||
});
|
||||
|
||||
export const PrivateAlbumLockDetailSchema = z.object({
|
||||
locked: booleanOrFalse,
|
||||
});
|
||||
|
||||
export const PrivateAlbumSchema = z.object({
|
||||
albumId: stringOrEmpty,
|
||||
title: stringOrEmpty,
|
||||
content: stringOrNull,
|
||||
previewText: stringOrEmpty,
|
||||
imageCount: numberOrZero,
|
||||
images: arrayOrEmpty(PrivateAlbumImageSchema),
|
||||
locked: booleanOrFalse,
|
||||
unlocked: booleanOrFalse,
|
||||
unlockCost: numberOrZero,
|
||||
publishedAt: stringOrNull,
|
||||
lockDetail: schemaOr(PrivateAlbumLockDetailSchema, { locked: false }),
|
||||
});
|
||||
|
||||
export type PrivateAlbumImageData = z.output<typeof PrivateAlbumImageSchema>;
|
||||
export type PrivateAlbumInput = z.input<typeof PrivateAlbumSchema>;
|
||||
export type PrivateAlbumData = z.output<typeof PrivateAlbumSchema>;
|
||||
@@ -0,0 +1,42 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
arrayOrEmpty,
|
||||
booleanOrFalse,
|
||||
numberOrZero,
|
||||
stringOrEmpty,
|
||||
} from "../nullable-defaults";
|
||||
import { PrivateAlbumImageSchema } from "./private_album";
|
||||
|
||||
export const PrivateAlbumUnlockReasonSchema = z.enum([
|
||||
"ok",
|
||||
"already_unlocked",
|
||||
"insufficient_credits",
|
||||
"cost_changed",
|
||||
"unlock_in_progress",
|
||||
"deduct_failed",
|
||||
"persist_failed_refunded",
|
||||
"not_found",
|
||||
]);
|
||||
|
||||
export const PrivateAlbumUnlockResponseSchema = z.object({
|
||||
albumId: stringOrEmpty,
|
||||
locked: booleanOrFalse,
|
||||
unlocked: booleanOrFalse,
|
||||
reason: PrivateAlbumUnlockReasonSchema.or(stringOrEmpty),
|
||||
unlockCost: numberOrZero,
|
||||
requiredCredits: numberOrZero,
|
||||
creditBalance: numberOrZero,
|
||||
shortfallCredits: numberOrZero,
|
||||
images: arrayOrEmpty(PrivateAlbumImageSchema),
|
||||
});
|
||||
|
||||
export type PrivateAlbumUnlockReason = z.output<
|
||||
typeof PrivateAlbumUnlockReasonSchema
|
||||
>;
|
||||
export type PrivateAlbumUnlockResponseInput = z.input<
|
||||
typeof PrivateAlbumUnlockResponseSchema
|
||||
>;
|
||||
export type PrivateAlbumUnlockResponseData = z.output<
|
||||
typeof PrivateAlbumUnlockResponseSchema
|
||||
>;
|
||||
@@ -0,0 +1,16 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { arrayOrEmpty, numberOrZero } from "../nullable-defaults";
|
||||
import { PrivateAlbumSchema } from "./private_album";
|
||||
|
||||
export const PrivateAlbumsResponseSchema = z.object({
|
||||
items: arrayOrEmpty(PrivateAlbumSchema),
|
||||
creditBalance: numberOrZero,
|
||||
});
|
||||
|
||||
export type PrivateAlbumsResponseInput = z.input<
|
||||
typeof PrivateAlbumsResponseSchema
|
||||
>;
|
||||
export type PrivateAlbumsResponseData = z.output<
|
||||
typeof PrivateAlbumsResponseSchema
|
||||
>;
|
||||
@@ -1,102 +0,0 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
arrayOrEmpty,
|
||||
booleanOrFalse,
|
||||
numberOrZero,
|
||||
schemaOr,
|
||||
stringOrEmpty,
|
||||
stringOrNull,
|
||||
} from "../nullable-defaults";
|
||||
|
||||
export const PrivateRoomProfileSchema = z.object({
|
||||
characterId: stringOrEmpty,
|
||||
displayName: stringOrEmpty,
|
||||
authorName: stringOrEmpty,
|
||||
avatarUrl: stringOrNull,
|
||||
coverUrl: stringOrNull,
|
||||
title: stringOrEmpty,
|
||||
subtitle: stringOrEmpty,
|
||||
});
|
||||
|
||||
export const PrivateRoomImageSchema = z.object({
|
||||
url: stringOrNull,
|
||||
type: stringOrEmpty,
|
||||
locked: booleanOrFalse,
|
||||
index: numberOrZero,
|
||||
});
|
||||
|
||||
export const PrivateRoomLockDetailSchema = z.object({
|
||||
locked: booleanOrFalse,
|
||||
showContent: booleanOrFalse,
|
||||
showUpgrade: booleanOrFalse,
|
||||
reason: stringOrNull,
|
||||
hint: stringOrNull,
|
||||
actionLabel: stringOrNull,
|
||||
type: stringOrNull,
|
||||
requiredCredits: numberOrZero,
|
||||
currentCredits: numberOrZero,
|
||||
shortfallCredits: numberOrZero,
|
||||
mediaCount: numberOrZero,
|
||||
unlockCostPerImage: numberOrZero,
|
||||
detail: z.unknown().nullable().default(null),
|
||||
});
|
||||
|
||||
export const PrivateRoomAuthorSchema = z.object({
|
||||
id: stringOrEmpty,
|
||||
name: stringOrEmpty,
|
||||
avatarUrl: stringOrNull,
|
||||
});
|
||||
|
||||
export const PrivateRoomMomentSchema = z.object({
|
||||
momentId: stringOrEmpty,
|
||||
source: stringOrEmpty,
|
||||
sourceId: stringOrEmpty,
|
||||
characterId: stringOrEmpty,
|
||||
author: schemaOr(PrivateRoomAuthorSchema, {
|
||||
id: "",
|
||||
name: "",
|
||||
avatarUrl: null,
|
||||
}),
|
||||
createdAt: stringOrNull,
|
||||
publishedAt: stringOrNull,
|
||||
timeText: stringOrEmpty,
|
||||
title: stringOrEmpty,
|
||||
content: stringOrNull,
|
||||
text: stringOrNull,
|
||||
textPreview: stringOrEmpty,
|
||||
mediaCount: numberOrZero,
|
||||
images: arrayOrEmpty(PrivateRoomImageSchema),
|
||||
locked: booleanOrFalse,
|
||||
unlocked: booleanOrFalse,
|
||||
unlockCost: numberOrZero,
|
||||
unlockCostPerImage: numberOrZero,
|
||||
requiredCredits: numberOrZero,
|
||||
currency: stringOrEmpty,
|
||||
lockDetail: schemaOr(PrivateRoomLockDetailSchema, {
|
||||
locked: false,
|
||||
showContent: false,
|
||||
showUpgrade: false,
|
||||
reason: null,
|
||||
hint: null,
|
||||
actionLabel: null,
|
||||
type: null,
|
||||
requiredCredits: 0,
|
||||
currentCredits: 0,
|
||||
shortfallCredits: 0,
|
||||
mediaCount: 0,
|
||||
unlockCostPerImage: 0,
|
||||
detail: null,
|
||||
}),
|
||||
});
|
||||
|
||||
export type PrivateRoomProfileData = z.output<
|
||||
typeof PrivateRoomProfileSchema
|
||||
>;
|
||||
export type PrivateRoomImageData = z.output<typeof PrivateRoomImageSchema>;
|
||||
export type PrivateRoomLockDetailData = z.output<
|
||||
typeof PrivateRoomLockDetailSchema
|
||||
>;
|
||||
export type PrivateRoomAuthorData = z.output<typeof PrivateRoomAuthorSchema>;
|
||||
export type PrivateRoomMomentInput = z.input<typeof PrivateRoomMomentSchema>;
|
||||
export type PrivateRoomMomentData = z.output<typeof PrivateRoomMomentSchema>;
|
||||
@@ -1,41 +0,0 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
arrayOrEmpty,
|
||||
booleanOrFalse,
|
||||
numberOrZero,
|
||||
schemaOr,
|
||||
stringOrEmpty,
|
||||
stringOrNull,
|
||||
} from "../nullable-defaults";
|
||||
import {
|
||||
PrivateRoomMomentSchema,
|
||||
PrivateRoomProfileSchema,
|
||||
} from "./private_room";
|
||||
|
||||
export const PrivateRoomMomentsResponseSchema = z.object({
|
||||
profile: schemaOr(PrivateRoomProfileSchema, {
|
||||
characterId: "elio",
|
||||
displayName: "Elio Silvestri",
|
||||
authorName: "Elio Silvestri",
|
||||
avatarUrl: null,
|
||||
coverUrl: null,
|
||||
title: "Elio Private room",
|
||||
subtitle: "Join me, unlock my private room",
|
||||
}),
|
||||
items: arrayOrEmpty(PrivateRoomMomentSchema),
|
||||
nextCursor: stringOrNull,
|
||||
hasMore: booleanOrFalse,
|
||||
creditBalance: numberOrZero,
|
||||
unlockCostDefault: numberOrZero,
|
||||
unlockCostPerImage: numberOrZero,
|
||||
currency: stringOrEmpty,
|
||||
source: stringOrEmpty,
|
||||
});
|
||||
|
||||
export type PrivateRoomMomentsResponseInput = z.input<
|
||||
typeof PrivateRoomMomentsResponseSchema
|
||||
>;
|
||||
export type PrivateRoomMomentsResponseData = z.output<
|
||||
typeof PrivateRoomMomentsResponseSchema
|
||||
>;
|
||||
@@ -1,36 +0,0 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { booleanOrFalse, numberOrZero, stringOrEmpty } from "../nullable-defaults";
|
||||
import { PrivateRoomMomentSchema } from "./private_room";
|
||||
|
||||
export const PrivateRoomUnlockReasonSchema = z.enum([
|
||||
"ok",
|
||||
"already_unlocked",
|
||||
"insufficient_credits",
|
||||
"cost_changed",
|
||||
"not_found",
|
||||
"no_media",
|
||||
"deduct_failed",
|
||||
"ok_persist_failed",
|
||||
]);
|
||||
|
||||
export const PrivateRoomUnlockResponseSchema =
|
||||
PrivateRoomMomentSchema.extend({
|
||||
reason: PrivateRoomUnlockReasonSchema.or(stringOrEmpty),
|
||||
creditsCharged: numberOrZero,
|
||||
creditBalance: numberOrZero,
|
||||
previousCreditBalance: numberOrZero,
|
||||
currentCredits: numberOrZero,
|
||||
shortfallCredits: numberOrZero,
|
||||
persisted: booleanOrFalse,
|
||||
});
|
||||
|
||||
export type PrivateRoomUnlockReason = z.output<
|
||||
typeof PrivateRoomUnlockReasonSchema
|
||||
>;
|
||||
export type PrivateRoomUnlockResponseInput = z.input<
|
||||
typeof PrivateRoomUnlockResponseSchema
|
||||
>;
|
||||
export type PrivateRoomUnlockResponseData = z.output<
|
||||
typeof PrivateRoomUnlockResponseSchema
|
||||
>;
|
||||
@@ -0,0 +1,14 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { numberOrZero } from "../nullable-defaults";
|
||||
|
||||
export const UnlockPrivateAlbumRequestSchema = z.object({
|
||||
expectedCost: numberOrZero,
|
||||
});
|
||||
|
||||
export type UnlockPrivateAlbumRequestInput = z.input<
|
||||
typeof UnlockPrivateAlbumRequestSchema
|
||||
>;
|
||||
export type UnlockPrivateAlbumRequestData = z.output<
|
||||
typeof UnlockPrivateAlbumRequestSchema
|
||||
>;
|
||||
@@ -1,14 +0,0 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { numberOrZero } from "../nullable-defaults";
|
||||
|
||||
export const UnlockPrivateRoomMomentRequestSchema = z.object({
|
||||
expectedCost: numberOrZero,
|
||||
});
|
||||
|
||||
export type UnlockPrivateRoomMomentRequestInput = z.input<
|
||||
typeof UnlockPrivateRoomMomentRequestSchema
|
||||
>;
|
||||
export type UnlockPrivateRoomMomentRequestData = z.output<
|
||||
typeof UnlockPrivateRoomMomentRequestSchema
|
||||
>;
|
||||
@@ -84,12 +84,12 @@ export class ApiPath {
|
||||
static readonly chatUnlockHistory = `${ApiPath._chat}/unlock-history`;
|
||||
|
||||
// ============ 私密空间相关 ============
|
||||
/** 获取私密空间动态列表 */
|
||||
static readonly privateRoomMoments = `${ApiPath._privateRoom}/moments`;
|
||||
/** 获取私密图片包列表 */
|
||||
static readonly privateRoomAlbums = `${ApiPath._privateRoom}/albums`;
|
||||
|
||||
/** 解锁私密空间动态 */
|
||||
static privateRoomMomentUnlock(momentId: string): string {
|
||||
return `${ApiPath.privateRoomMoments}/${encodeURIComponent(momentId)}/unlock`;
|
||||
/** 解锁私密图片包 */
|
||||
static privateRoomAlbumUnlock(albumId: string): string {
|
||||
return `${ApiPath.privateRoomAlbums}/${encodeURIComponent(albumId)}/unlock`;
|
||||
}
|
||||
|
||||
// ============ 数据看板相关 ============
|
||||
|
||||
@@ -1,48 +1,46 @@
|
||||
import {
|
||||
PrivateRoomMomentsResponse,
|
||||
PrivateRoomUnlockResponse,
|
||||
UnlockPrivateRoomMomentRequest,
|
||||
PrivateAlbumsResponse,
|
||||
PrivateAlbumUnlockResponse,
|
||||
UnlockPrivateAlbumRequest,
|
||||
} from "@/data/dto/private-room";
|
||||
|
||||
import { ApiPath } from "./api_path";
|
||||
import { httpClient } from "./http_client";
|
||||
import { type ApiEnvelope, unwrap } from "./response_helper";
|
||||
|
||||
export interface GetPrivateRoomMomentsInput {
|
||||
export interface GetPrivateAlbumsInput {
|
||||
character?: string;
|
||||
limit?: number;
|
||||
cursor?: string | null;
|
||||
}
|
||||
|
||||
export class PrivateRoomApi {
|
||||
async getMoments(
|
||||
input: GetPrivateRoomMomentsInput = {},
|
||||
): Promise<PrivateRoomMomentsResponse> {
|
||||
async getAlbums(
|
||||
input: GetPrivateAlbumsInput = {},
|
||||
): Promise<PrivateAlbumsResponse> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(
|
||||
ApiPath.privateRoomMoments,
|
||||
ApiPath.privateRoomAlbums,
|
||||
{
|
||||
query: {
|
||||
character: input.character ?? "elio",
|
||||
limit: input.limit ?? 20,
|
||||
...(input.cursor ? { cursor: input.cursor } : {}),
|
||||
},
|
||||
},
|
||||
);
|
||||
return PrivateRoomMomentsResponse.fromJson(unwrap(env));
|
||||
return PrivateAlbumsResponse.fromJson(unwrap(env));
|
||||
}
|
||||
|
||||
async unlockMoment(
|
||||
momentId: string,
|
||||
body: UnlockPrivateRoomMomentRequest,
|
||||
): Promise<PrivateRoomUnlockResponse> {
|
||||
async unlockAlbum(
|
||||
albumId: string,
|
||||
body: UnlockPrivateAlbumRequest,
|
||||
): Promise<PrivateAlbumUnlockResponse> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(
|
||||
ApiPath.privateRoomMomentUnlock(momentId),
|
||||
ApiPath.privateRoomAlbumUnlock(albumId),
|
||||
{
|
||||
method: "POST",
|
||||
body: body.toJson(),
|
||||
},
|
||||
);
|
||||
return PrivateRoomUnlockResponse.fromJson(unwrap(env));
|
||||
return PrivateAlbumUnlockResponse.fromJson(unwrap(env));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import type { PrivateAlbum } from "@/data/dto/private-room";
|
||||
|
||||
export function isPrivateAlbumLocked(album: PrivateAlbum): boolean {
|
||||
return album.locked || !album.unlocked || album.lockDetail.locked;
|
||||
}
|
||||
@@ -2,259 +2,208 @@ import { describe, expect, it } from "vitest";
|
||||
import { createActor, fromPromise, waitFor } from "xstate";
|
||||
|
||||
import {
|
||||
PrivateRoomMomentsResponse,
|
||||
PrivateRoomUnlockResponse,
|
||||
PrivateAlbumsResponse,
|
||||
PrivateAlbumUnlockResponse,
|
||||
} from "@/data/dto/private-room";
|
||||
import { privateRoomMachine } from "@/stores/private-room/private-room-machine";
|
||||
|
||||
const baseMoment = {
|
||||
momentId: "schedule:91",
|
||||
source: "elio_schedules",
|
||||
sourceId: "91",
|
||||
characterId: "elio",
|
||||
author: {
|
||||
id: "elio",
|
||||
name: "Elio Silvestri",
|
||||
avatarUrl: null,
|
||||
},
|
||||
createdAt: "2026-07-01T08:11:35+00:00",
|
||||
publishedAt: "2026-07-01T08:11:35+00:00",
|
||||
timeText: "7 days ago",
|
||||
title: "Paris morning",
|
||||
content: null,
|
||||
text: null,
|
||||
textPreview: "Unlock to view private room photos",
|
||||
mediaCount: 1,
|
||||
images: [
|
||||
{
|
||||
url: null,
|
||||
type: "image",
|
||||
locked: true,
|
||||
index: 0,
|
||||
},
|
||||
],
|
||||
locked: true,
|
||||
unlocked: false,
|
||||
unlockCost: 40,
|
||||
unlockCostPerImage: 40,
|
||||
requiredCredits: 40,
|
||||
currency: "credits",
|
||||
lockDetail: {
|
||||
locked: true,
|
||||
showContent: false,
|
||||
showUpgrade: true,
|
||||
reason: "private_room_moment",
|
||||
hint: "40 credits · Unlock photo",
|
||||
actionLabel: "Unlock",
|
||||
type: "private_room_moment",
|
||||
requiredCredits: 40,
|
||||
currentCredits: 100,
|
||||
shortfallCredits: 0,
|
||||
mediaCount: 1,
|
||||
unlockCostPerImage: 40,
|
||||
},
|
||||
};
|
||||
const ALBUM_ID = "a1b2c3d4-0000-0000-0000-000000000000";
|
||||
const COVER_URL =
|
||||
"https://dbapi.banlv-ai.com/storage/v1/object/public/elio-schedules/01.jpg";
|
||||
|
||||
function makeMomentsResponse(
|
||||
overrides: Partial<Parameters<typeof PrivateRoomMomentsResponse.from>[0]> = {},
|
||||
): PrivateRoomMomentsResponse {
|
||||
return PrivateRoomMomentsResponse.from({
|
||||
profile: {
|
||||
characterId: "elio",
|
||||
displayName: "Elio Silvestri",
|
||||
authorName: "Elio Silvestri",
|
||||
avatarUrl: null,
|
||||
coverUrl: null,
|
||||
title: "Elio Private room",
|
||||
subtitle: "Join me, unlock my private room",
|
||||
},
|
||||
items: [baseMoment],
|
||||
nextCursor: null,
|
||||
hasMore: false,
|
||||
creditBalance: 100,
|
||||
unlockCostDefault: 40,
|
||||
unlockCostPerImage: 40,
|
||||
currency: "credits",
|
||||
source: "elio_schedules",
|
||||
function makeAlbum(index = 0) {
|
||||
return {
|
||||
albumId: index === 0 ? ALBUM_ID : `album-${index}`,
|
||||
title: `Private album ${index + 1}`,
|
||||
content: null,
|
||||
previewText: "Only for you.",
|
||||
imageCount: 8,
|
||||
images: [{ url: `${COVER_URL}?album=${index}`, locked: true, index: 0 }],
|
||||
locked: true,
|
||||
unlocked: false,
|
||||
unlockCost: 320,
|
||||
publishedAt: "2026-07-13T00:00:00+00:00",
|
||||
lockDetail: { locked: true },
|
||||
};
|
||||
}
|
||||
|
||||
function makeAlbumsResponse(
|
||||
overrides: Partial<Parameters<typeof PrivateAlbumsResponse.from>[0]> = {},
|
||||
): PrivateAlbumsResponse {
|
||||
return PrivateAlbumsResponse.from({
|
||||
items: [makeAlbum()],
|
||||
creditBalance: 500,
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
function makeUnlockResponse(
|
||||
overrides: Partial<Parameters<typeof PrivateRoomUnlockResponse.from>[0]> = {},
|
||||
): PrivateRoomUnlockResponse {
|
||||
return PrivateRoomUnlockResponse.from({
|
||||
...baseMoment,
|
||||
overrides: Partial<Parameters<typeof PrivateAlbumUnlockResponse.from>[0]> = {},
|
||||
): PrivateAlbumUnlockResponse {
|
||||
return PrivateAlbumUnlockResponse.from({
|
||||
albumId: ALBUM_ID,
|
||||
locked: false,
|
||||
unlocked: true,
|
||||
images: [
|
||||
{
|
||||
url: "https://example.supabase.co/storage/v1/object/public/elio-schedules/photo.jpg",
|
||||
type: "image",
|
||||
locked: false,
|
||||
index: 0,
|
||||
},
|
||||
],
|
||||
reason: "ok",
|
||||
creditsCharged: 40,
|
||||
creditBalance: 60,
|
||||
unlockCost: 320,
|
||||
requiredCredits: 320,
|
||||
creditBalance: 180,
|
||||
shortfallCredits: 0,
|
||||
images: Array.from({ length: 8 }, (_, index) => ({
|
||||
url: `${COVER_URL}?image=${index}`,
|
||||
locked: false,
|
||||
index,
|
||||
})),
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
function createTestMachine(
|
||||
options: {
|
||||
firstPage?: PrivateRoomMomentsResponse;
|
||||
morePage?: PrivateRoomMomentsResponse;
|
||||
unlockResponse?: PrivateRoomUnlockResponse;
|
||||
} = {},
|
||||
) {
|
||||
function createTestMachine(options: {
|
||||
loadResponse?: PrivateAlbumsResponse;
|
||||
unlockResponse?: PrivateAlbumUnlockResponse;
|
||||
onLoad?: () => void;
|
||||
} = {}) {
|
||||
return privateRoomMachine.provide({
|
||||
actors: {
|
||||
loadMoments: fromPromise(async () => options.firstPage ?? makeMomentsResponse()),
|
||||
loadMoreMoments: fromPromise(async () =>
|
||||
options.morePage ??
|
||||
makeMomentsResponse({
|
||||
items: [
|
||||
{
|
||||
...baseMoment,
|
||||
momentId: "schedule:92",
|
||||
sourceId: "92",
|
||||
},
|
||||
],
|
||||
hasMore: false,
|
||||
nextCursor: null,
|
||||
}),
|
||||
),
|
||||
unlockMoment: fromPromise(async () =>
|
||||
options.unlockResponse ?? makeUnlockResponse(),
|
||||
loadAlbums: fromPromise(async () => {
|
||||
options.onLoad?.();
|
||||
return options.loadResponse ?? makeAlbumsResponse();
|
||||
}),
|
||||
unlockAlbum: fromPromise(async () =>
|
||||
(options.unlockResponse ?? makeUnlockResponse()),
|
||||
),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function loadMachine(options: Parameters<typeof createTestMachine>[0] = {}) {
|
||||
const actor = createActor(createTestMachine(options)).start();
|
||||
actor.send({ type: "PrivateRoomInit" });
|
||||
await waitFor(actor, (snapshot) => snapshot.matches("ready"));
|
||||
return actor;
|
||||
}
|
||||
|
||||
async function unlockFirstAlbum(
|
||||
actor: Awaited<ReturnType<typeof loadMachine>>,
|
||||
) {
|
||||
actor.send({
|
||||
type: "PrivateRoomUnlockRequested",
|
||||
albumId: ALBUM_ID,
|
||||
});
|
||||
actor.send({ type: "PrivateRoomUnlockConfirmed" });
|
||||
await waitFor(actor, (snapshot) => snapshot.matches("ready"));
|
||||
}
|
||||
|
||||
describe("privateRoomMachine", () => {
|
||||
it("loads the first page", async () => {
|
||||
const actor = createActor(createTestMachine()).start();
|
||||
|
||||
actor.send({ type: "PrivateRoomInit" });
|
||||
await waitFor(actor, (snapshot) => snapshot.matches("ready"));
|
||||
|
||||
const context = actor.getSnapshot().context;
|
||||
expect(context.profile?.displayName).toBe("Elio Silvestri");
|
||||
expect(context.items).toHaveLength(1);
|
||||
expect(context.creditBalance).toBe(100);
|
||||
|
||||
actor.stop();
|
||||
});
|
||||
|
||||
it("appends more moments without overwriting existing items", async () => {
|
||||
const actor = createActor(
|
||||
createTestMachine({
|
||||
firstPage: makeMomentsResponse({
|
||||
hasMore: true,
|
||||
nextCursor: "cursor-1",
|
||||
}),
|
||||
it("loads only the first album page into its non-paginated state", async () => {
|
||||
const actor = await loadMachine({
|
||||
loadResponse: makeAlbumsResponse({
|
||||
items: Array.from({ length: 20 }, (_, index) => makeAlbum(index)),
|
||||
}),
|
||||
).start();
|
||||
|
||||
actor.send({ type: "PrivateRoomInit" });
|
||||
await waitFor(actor, (snapshot) => snapshot.matches("ready"));
|
||||
|
||||
actor.send({ type: "PrivateRoomLoadMore" });
|
||||
await waitFor(actor, (snapshot) => snapshot.matches("ready"));
|
||||
|
||||
expect(actor.getSnapshot().context.items.map((item) => item.momentId)).toEqual([
|
||||
"schedule:91",
|
||||
"schedule:92",
|
||||
]);
|
||||
});
|
||||
const context = actor.getSnapshot().context;
|
||||
|
||||
expect(context.items).toHaveLength(20);
|
||||
expect(context.creditBalance).toBe(500);
|
||||
expect(context).not.toHaveProperty("hasMore");
|
||||
expect(context).not.toHaveProperty("nextCursor");
|
||||
actor.stop();
|
||||
});
|
||||
|
||||
it("replaces a locked moment after unlock success", async () => {
|
||||
const actor = createActor(createTestMachine()).start();
|
||||
|
||||
actor.send({ type: "PrivateRoomInit" });
|
||||
await waitFor(actor, (snapshot) => snapshot.matches("ready"));
|
||||
|
||||
actor.send({
|
||||
type: "PrivateRoomUnlockRequested",
|
||||
momentId: "schedule:91",
|
||||
});
|
||||
actor.send({ type: "PrivateRoomUnlockConfirmed" });
|
||||
await waitFor(actor, (snapshot) => snapshot.matches("ready"));
|
||||
|
||||
it("patches the album images after a successful unlock", async () => {
|
||||
const actor = await loadMachine();
|
||||
await unlockFirstAlbum(actor);
|
||||
const context = actor.getSnapshot().context;
|
||||
expect(context.items[0]?.locked).toBe(false);
|
||||
expect(context.items[0]?.images[0]?.url).toContain("https://");
|
||||
|
||||
expect(context.items[0]).toMatchObject({
|
||||
albumId: ALBUM_ID,
|
||||
locked: false,
|
||||
unlocked: true,
|
||||
title: "Private album 1",
|
||||
});
|
||||
expect(context.items[0]?.images).toHaveLength(8);
|
||||
expect(context.items[0]?.lockDetail).toEqual({ locked: false });
|
||||
expect(context.unlockSuccessNonce).toBe(1);
|
||||
|
||||
actor.stop();
|
||||
});
|
||||
|
||||
it("exposes a paywall request for insufficient credits", async () => {
|
||||
const actor = createActor(
|
||||
createTestMachine({
|
||||
unlockResponse: makeUnlockResponse({
|
||||
...baseMoment,
|
||||
reason: "insufficient_credits",
|
||||
locked: true,
|
||||
unlocked: false,
|
||||
creditBalance: 10,
|
||||
currentCredits: 10,
|
||||
shortfallCredits: 30,
|
||||
}),
|
||||
it("keeps the album locked and exposes a paywall request when credits are low", async () => {
|
||||
const actor = await loadMachine({
|
||||
unlockResponse: makeUnlockResponse({
|
||||
locked: true,
|
||||
unlocked: false,
|
||||
reason: "insufficient_credits",
|
||||
creditBalance: 100,
|
||||
shortfallCredits: 220,
|
||||
images: [{ url: COVER_URL, locked: true, index: 0 }],
|
||||
}),
|
||||
).start();
|
||||
|
||||
actor.send({ type: "PrivateRoomInit" });
|
||||
await waitFor(actor, (snapshot) => snapshot.matches("ready"));
|
||||
|
||||
actor.send({
|
||||
type: "PrivateRoomUnlockRequested",
|
||||
momentId: "schedule:91",
|
||||
});
|
||||
actor.send({ type: "PrivateRoomUnlockConfirmed" });
|
||||
await waitFor(actor, (snapshot) => snapshot.matches("ready"));
|
||||
|
||||
await unlockFirstAlbum(actor);
|
||||
const context = actor.getSnapshot().context;
|
||||
expect(context.items[0]?.locked).toBe(true);
|
||||
expect(context.unlockPaywallRequest).toMatchObject({
|
||||
momentId: "schedule:91",
|
||||
reason: "insufficient_credits",
|
||||
shortfallCredits: 30,
|
||||
});
|
||||
|
||||
expect(context.items[0]?.locked).toBe(true);
|
||||
expect(context.unlockPaywallRequest).toEqual({
|
||||
albumId: ALBUM_ID,
|
||||
reason: "insufficient_credits",
|
||||
requiredCredits: 320,
|
||||
currentCredits: 100,
|
||||
shortfallCredits: 220,
|
||||
});
|
||||
actor.stop();
|
||||
});
|
||||
|
||||
it("refreshes and keeps an unlock error when the cost changes", async () => {
|
||||
const actor = createActor(
|
||||
createTestMachine({
|
||||
unlockResponse: makeUnlockResponse({
|
||||
...baseMoment,
|
||||
reason: "cost_changed",
|
||||
locked: true,
|
||||
unlocked: false,
|
||||
}),
|
||||
it("reloads the first page when the expected cost changed", async () => {
|
||||
let loadCount = 0;
|
||||
const actor = await loadMachine({
|
||||
onLoad: () => {
|
||||
loadCount += 1;
|
||||
},
|
||||
unlockResponse: makeUnlockResponse({
|
||||
locked: true,
|
||||
unlocked: false,
|
||||
reason: "cost_changed",
|
||||
}),
|
||||
).start();
|
||||
|
||||
actor.send({ type: "PrivateRoomInit" });
|
||||
await waitFor(actor, (snapshot) => snapshot.matches("ready"));
|
||||
|
||||
actor.send({
|
||||
type: "PrivateRoomUnlockRequested",
|
||||
momentId: "schedule:91",
|
||||
});
|
||||
actor.send({ type: "PrivateRoomUnlockConfirmed" });
|
||||
await waitFor(actor, (snapshot) => snapshot.matches("ready"));
|
||||
await unlockFirstAlbum(actor);
|
||||
|
||||
expect(loadCount).toBe(2);
|
||||
expect(actor.getSnapshot().context.unlockErrorMessage).toBe(
|
||||
"Unlock price changed. Please confirm again.",
|
||||
);
|
||||
actor.stop();
|
||||
});
|
||||
|
||||
it("removes an album that no longer exists", async () => {
|
||||
const actor = await loadMachine({
|
||||
unlockResponse: makeUnlockResponse({
|
||||
locked: true,
|
||||
unlocked: false,
|
||||
reason: "not_found",
|
||||
images: [],
|
||||
}),
|
||||
});
|
||||
await unlockFirstAlbum(actor);
|
||||
|
||||
expect(actor.getSnapshot().context.items).toHaveLength(0);
|
||||
actor.stop();
|
||||
});
|
||||
|
||||
it("keeps a refunded persistence failure locked and updates the balance", async () => {
|
||||
const actor = await loadMachine({
|
||||
unlockResponse: makeUnlockResponse({
|
||||
locked: true,
|
||||
unlocked: false,
|
||||
reason: "persist_failed_refunded",
|
||||
creditBalance: 500,
|
||||
images: [{ url: COVER_URL, locked: true, index: 0 }],
|
||||
}),
|
||||
});
|
||||
await unlockFirstAlbum(actor);
|
||||
const context = actor.getSnapshot().context;
|
||||
|
||||
expect(context.items[0]?.locked).toBe(true);
|
||||
expect(context.creditBalance).toBe(500);
|
||||
expect(context.unlockErrorMessage).toContain("refunded");
|
||||
actor.stop();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,19 +12,15 @@ import type {
|
||||
|
||||
export interface PrivateRoomContextState {
|
||||
status: string;
|
||||
profile: MachineContext["profile"];
|
||||
items: MachineContext["items"];
|
||||
nextCursor: string | null;
|
||||
hasMore: boolean;
|
||||
creditBalance: number;
|
||||
errorMessage: string | null;
|
||||
unlockingMomentId: string | null;
|
||||
unlockingAlbumId: string | null;
|
||||
unlockErrorMessage: string | null;
|
||||
pendingConfirmMomentId: string | null;
|
||||
pendingConfirmAlbumId: string | null;
|
||||
unlockPaywallRequest: MachineContext["unlockPaywallRequest"];
|
||||
unlockSuccessNonce: number;
|
||||
isLoading: boolean;
|
||||
isLoadingMore: boolean;
|
||||
isUnlocking: boolean;
|
||||
}
|
||||
|
||||
@@ -63,19 +59,15 @@ function selectPrivateRoomState(
|
||||
): PrivateRoomContextState {
|
||||
return {
|
||||
status: String(state.value),
|
||||
profile: state.context.profile,
|
||||
items: state.context.items,
|
||||
nextCursor: state.context.nextCursor,
|
||||
hasMore: state.context.hasMore,
|
||||
creditBalance: state.context.creditBalance,
|
||||
errorMessage: state.context.errorMessage,
|
||||
unlockingMomentId: state.context.unlockingMomentId,
|
||||
unlockingAlbumId: state.context.unlockingAlbumId,
|
||||
unlockErrorMessage: state.context.unlockErrorMessage,
|
||||
pendingConfirmMomentId: state.context.pendingConfirmMomentId,
|
||||
pendingConfirmAlbumId: state.context.pendingConfirmAlbumId,
|
||||
unlockPaywallRequest: state.context.unlockPaywallRequest,
|
||||
unlockSuccessNonce: state.context.unlockSuccessNonce,
|
||||
isLoading: state.matches("loading"),
|
||||
isLoadingMore: state.matches("loadingMore"),
|
||||
isUnlocking: state.matches("unlocking"),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
export type PrivateRoomEvent =
|
||||
| { type: "PrivateRoomInit" }
|
||||
| { type: "PrivateRoomRefresh" }
|
||||
| { type: "PrivateRoomLoadMore" }
|
||||
| { type: "PrivateRoomUnlockRequested"; momentId: string }
|
||||
| { type: "PrivateRoomUnlockRequested"; albumId: string }
|
||||
| { type: "PrivateRoomUnlockConfirmed" }
|
||||
| { type: "PrivateRoomUnlockCancelled" }
|
||||
| { type: "PrivateRoomUnlockPaywallConsumed" };
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { fromPromise } from "xstate";
|
||||
|
||||
import type {
|
||||
PrivateRoomMomentsResponse,
|
||||
PrivateRoomUnlockResponse,
|
||||
PrivateAlbumsResponse,
|
||||
PrivateAlbumUnlockResponse,
|
||||
} from "@/data/dto/private-room";
|
||||
import { getPrivateRoomRepository } from "@/data/repositories/private_room_repository";
|
||||
import { Result } from "@/utils";
|
||||
@@ -12,10 +12,10 @@ import {
|
||||
PRIVATE_ROOM_PAGE_SIZE,
|
||||
} from "./private-room-machine.helpers";
|
||||
|
||||
export const loadPrivateRoomMomentsActor =
|
||||
fromPromise<PrivateRoomMomentsResponse>(async () => {
|
||||
export const loadPrivateAlbumsActor =
|
||||
fromPromise<PrivateAlbumsResponse>(async () => {
|
||||
const repo = getPrivateRoomRepository();
|
||||
const result = await repo.getMoments({
|
||||
const result = await repo.getAlbums({
|
||||
character: PRIVATE_ROOM_CHARACTER,
|
||||
limit: PRIVATE_ROOM_PAGE_SIZE,
|
||||
});
|
||||
@@ -23,27 +23,13 @@ export const loadPrivateRoomMomentsActor =
|
||||
return result.data;
|
||||
});
|
||||
|
||||
export const loadMorePrivateRoomMomentsActor = fromPromise<
|
||||
PrivateRoomMomentsResponse,
|
||||
{ cursor: string | null }
|
||||
export const unlockPrivateAlbumActor = fromPromise<
|
||||
PrivateAlbumUnlockResponse,
|
||||
{ albumId: string; expectedCost: number }
|
||||
>(async ({ input }) => {
|
||||
const repo = getPrivateRoomRepository();
|
||||
const result = await repo.getMoments({
|
||||
character: PRIVATE_ROOM_CHARACTER,
|
||||
limit: PRIVATE_ROOM_PAGE_SIZE,
|
||||
cursor: input.cursor,
|
||||
});
|
||||
if (Result.isErr(result)) throw result.error;
|
||||
return result.data;
|
||||
});
|
||||
|
||||
export const unlockPrivateRoomMomentActor = fromPromise<
|
||||
PrivateRoomUnlockResponse,
|
||||
{ momentId: string; expectedCost: number }
|
||||
>(async ({ input }) => {
|
||||
const repo = getPrivateRoomRepository();
|
||||
const result = await repo.unlockMoment(
|
||||
input.momentId,
|
||||
const result = await repo.unlockAlbum(
|
||||
input.albumId,
|
||||
input.expectedCost,
|
||||
);
|
||||
if (Result.isErr(result)) throw result.error;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type {
|
||||
PrivateRoomMoment,
|
||||
PrivateRoomMomentsResponse,
|
||||
PrivateRoomUnlockResponse,
|
||||
import {
|
||||
PrivateAlbum,
|
||||
type PrivateAlbumsResponse,
|
||||
type PrivateAlbumUnlockResponse,
|
||||
} from "@/data/dto/private-room";
|
||||
|
||||
import type {
|
||||
@@ -12,77 +12,82 @@ import type {
|
||||
export const PRIVATE_ROOM_CHARACTER = "elio";
|
||||
export const PRIVATE_ROOM_PAGE_SIZE = 20;
|
||||
|
||||
export function applyMomentsResponse(
|
||||
response: PrivateRoomMomentsResponse,
|
||||
export function applyAlbumsResponse(
|
||||
response: PrivateAlbumsResponse,
|
||||
): Partial<PrivateRoomState> {
|
||||
return {
|
||||
profile: response.profile,
|
||||
items: response.items,
|
||||
nextCursor: response.nextCursor,
|
||||
hasMore: response.hasMore,
|
||||
creditBalance: response.creditBalance,
|
||||
errorMessage: null,
|
||||
};
|
||||
}
|
||||
|
||||
export function appendMomentsResponse(
|
||||
context: PrivateRoomState,
|
||||
response: PrivateRoomMomentsResponse,
|
||||
): Partial<PrivateRoomState> {
|
||||
const knownIds = new Set(context.items.map((item) => item.momentId));
|
||||
const nextItems = [
|
||||
...context.items,
|
||||
...response.items.filter((item) => !knownIds.has(item.momentId)),
|
||||
];
|
||||
return {
|
||||
profile: response.profile,
|
||||
items: nextItems,
|
||||
nextCursor: response.nextCursor,
|
||||
hasMore: response.hasMore,
|
||||
creditBalance: response.creditBalance,
|
||||
errorMessage: null,
|
||||
};
|
||||
export function patchAlbumFromUnlock(
|
||||
album: PrivateAlbum,
|
||||
response: PrivateAlbumUnlockResponse,
|
||||
): PrivateAlbum {
|
||||
return PrivateAlbum.from({
|
||||
...album.toJson(),
|
||||
locked: response.locked,
|
||||
unlocked: response.unlocked,
|
||||
unlockCost: response.unlockCost || album.unlockCost,
|
||||
images: response.images.length > 0 ? response.images : album.images,
|
||||
lockDetail: { locked: response.locked },
|
||||
});
|
||||
}
|
||||
|
||||
export function replaceMoment(
|
||||
items: readonly PrivateRoomMoment[],
|
||||
nextMoment: PrivateRoomMoment,
|
||||
): PrivateRoomMoment[] {
|
||||
return items.map((item) =>
|
||||
item.momentId === nextMoment.momentId ? nextMoment : item,
|
||||
export function patchAlbumInList(
|
||||
items: readonly PrivateAlbum[],
|
||||
response: PrivateAlbumUnlockResponse,
|
||||
): PrivateAlbum[] {
|
||||
return items.map((album) =>
|
||||
album.albumId === response.albumId
|
||||
? patchAlbumFromUnlock(album, response)
|
||||
: album,
|
||||
);
|
||||
}
|
||||
|
||||
export function removeAlbum(
|
||||
items: readonly PrivateAlbum[],
|
||||
albumId: string,
|
||||
): PrivateAlbum[] {
|
||||
return items.filter((album) => album.albumId !== albumId);
|
||||
}
|
||||
|
||||
export function toPrivateRoomErrorMessage(error: unknown): string {
|
||||
if (error instanceof Error && error.message) return error.message;
|
||||
return "Private room is temporarily unavailable. Please try again.";
|
||||
}
|
||||
|
||||
export function toUnlockErrorMessage(
|
||||
response: PrivateRoomUnlockResponse,
|
||||
response: PrivateAlbumUnlockResponse,
|
||||
): string | null {
|
||||
switch (response.reason) {
|
||||
case "cost_changed":
|
||||
return "Unlock price changed. Please confirm again.";
|
||||
case "not_found":
|
||||
return "This private room post is no longer available.";
|
||||
case "no_media":
|
||||
return "This private room post has no photos to unlock.";
|
||||
case "unlock_in_progress":
|
||||
return "This album is already unlocking. Please try again shortly.";
|
||||
case "deduct_failed":
|
||||
return "Credit deduction failed. Please try again.";
|
||||
case "persist_failed_refunded":
|
||||
return "Unlock failed and your credits were refunded. Please try again.";
|
||||
case "not_found":
|
||||
return "This private album is no longer available.";
|
||||
default:
|
||||
return response.unlocked ? null : "Unlock failed. Please try again.";
|
||||
return response.unlocked && !response.locked
|
||||
? null
|
||||
: "Unlock failed. Please try again.";
|
||||
}
|
||||
}
|
||||
|
||||
export function toPaywallRequest(
|
||||
response: PrivateRoomUnlockResponse,
|
||||
response: PrivateAlbumUnlockResponse,
|
||||
): PrivateRoomUnlockPaywallRequest {
|
||||
return {
|
||||
momentId: response.momentId,
|
||||
albumId: response.albumId,
|
||||
reason: response.reason,
|
||||
requiredCredits: response.requiredCredits,
|
||||
currentCredits: response.currentCredits || response.creditBalance,
|
||||
requiredCredits: response.requiredCredits || response.unlockCost,
|
||||
currentCredits: response.creditBalance,
|
||||
shortfallCredits: response.shortfallCredits,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import { assign, setup } from "xstate";
|
||||
|
||||
import type { PrivateRoomMoment } from "@/data/dto/private-room";
|
||||
import type { PrivateAlbum } from "@/data/dto/private-room";
|
||||
|
||||
import type { PrivateRoomEvent } from "./private-room-events";
|
||||
import {
|
||||
appendMomentsResponse,
|
||||
applyMomentsResponse,
|
||||
replaceMoment,
|
||||
applyAlbumsResponse,
|
||||
patchAlbumInList,
|
||||
removeAlbum,
|
||||
toPaywallRequest,
|
||||
toPrivateRoomErrorMessage,
|
||||
toUnlockErrorMessage,
|
||||
} from "./private-room-machine.helpers";
|
||||
import {
|
||||
loadMorePrivateRoomMomentsActor,
|
||||
loadPrivateRoomMomentsActor,
|
||||
unlockPrivateRoomMomentActor,
|
||||
loadPrivateAlbumsActor,
|
||||
unlockPrivateAlbumActor,
|
||||
} from "./private-room-machine.actors";
|
||||
import { initialState, type PrivateRoomState } from "./private-room-state";
|
||||
|
||||
@@ -22,11 +21,11 @@ export type { PrivateRoomEvent } from "./private-room-events";
|
||||
export type { PrivateRoomState } from "./private-room-state";
|
||||
export { initialState } from "./private-room-state";
|
||||
|
||||
function getPendingMoment(context: PrivateRoomState): PrivateRoomMoment | null {
|
||||
if (!context.pendingConfirmMomentId) return null;
|
||||
function getPendingAlbum(context: PrivateRoomState): PrivateAlbum | null {
|
||||
if (!context.pendingConfirmAlbumId) return null;
|
||||
return (
|
||||
context.items.find(
|
||||
(item) => item.momentId === context.pendingConfirmMomentId,
|
||||
(album) => album.albumId === context.pendingConfirmAlbumId,
|
||||
) ?? null
|
||||
);
|
||||
}
|
||||
@@ -37,9 +36,8 @@ export const privateRoomMachine = setup({
|
||||
events: {} as PrivateRoomEvent,
|
||||
},
|
||||
actors: {
|
||||
loadMoments: loadPrivateRoomMomentsActor,
|
||||
loadMoreMoments: loadMorePrivateRoomMomentsActor,
|
||||
unlockMoment: unlockPrivateRoomMomentActor,
|
||||
loadAlbums: loadPrivateAlbumsActor,
|
||||
unlockAlbum: unlockPrivateAlbumActor,
|
||||
},
|
||||
}).createMachine({
|
||||
id: "privateRoom",
|
||||
@@ -58,10 +56,10 @@ export const privateRoomMachine = setup({
|
||||
unlockPaywallRequest: null,
|
||||
}),
|
||||
invoke: {
|
||||
src: "loadMoments",
|
||||
src: "loadAlbums",
|
||||
onDone: {
|
||||
target: "ready",
|
||||
actions: assign(({ event }) => applyMomentsResponse(event.output)),
|
||||
actions: assign(({ event }) => applyAlbumsResponse(event.output)),
|
||||
},
|
||||
onError: {
|
||||
target: "failed",
|
||||
@@ -81,90 +79,55 @@ export const privateRoomMachine = setup({
|
||||
|
||||
ready: {
|
||||
on: {
|
||||
PrivateRoomInit: {
|
||||
target: "loading",
|
||||
},
|
||||
PrivateRoomRefresh: {
|
||||
target: "loading",
|
||||
},
|
||||
PrivateRoomLoadMore: [
|
||||
{
|
||||
guard: ({ context }) =>
|
||||
context.hasMore && context.nextCursor !== null,
|
||||
target: "loadingMore",
|
||||
},
|
||||
],
|
||||
PrivateRoomInit: "loading",
|
||||
PrivateRoomRefresh: "loading",
|
||||
PrivateRoomUnlockRequested: {
|
||||
actions: assign(({ event }) => ({
|
||||
pendingConfirmMomentId: event.momentId,
|
||||
pendingConfirmAlbumId: event.albumId,
|
||||
unlockErrorMessage: null,
|
||||
unlockPaywallRequest: null,
|
||||
})),
|
||||
},
|
||||
PrivateRoomUnlockCancelled: {
|
||||
actions: assign({
|
||||
pendingConfirmMomentId: null,
|
||||
}),
|
||||
actions: assign({ pendingConfirmAlbumId: null }),
|
||||
},
|
||||
PrivateRoomUnlockConfirmed: [
|
||||
{
|
||||
guard: ({ context }) => getPendingMoment(context) !== null,
|
||||
guard: ({ context }) => getPendingAlbum(context) !== null,
|
||||
target: "unlocking",
|
||||
},
|
||||
],
|
||||
PrivateRoomUnlockPaywallConsumed: {
|
||||
actions: assign({
|
||||
unlockPaywallRequest: null,
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
loadingMore: {
|
||||
invoke: {
|
||||
src: "loadMoreMoments",
|
||||
input: ({ context }) => ({
|
||||
cursor: context.nextCursor,
|
||||
}),
|
||||
onDone: {
|
||||
target: "ready",
|
||||
actions: assign(({ context, event }) =>
|
||||
appendMomentsResponse(context, event.output),
|
||||
),
|
||||
},
|
||||
onError: {
|
||||
target: "ready",
|
||||
actions: assign(({ event }) => ({
|
||||
errorMessage: toPrivateRoomErrorMessage(event.error),
|
||||
})),
|
||||
actions: assign({ unlockPaywallRequest: null }),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
unlocking: {
|
||||
entry: assign(({ context }) => ({
|
||||
unlockingMomentId: context.pendingConfirmMomentId,
|
||||
unlockingAlbumId: context.pendingConfirmAlbumId,
|
||||
unlockErrorMessage: null,
|
||||
unlockPaywallRequest: null,
|
||||
})),
|
||||
invoke: {
|
||||
src: "unlockMoment",
|
||||
src: "unlockAlbum",
|
||||
input: ({ context }) => {
|
||||
const pendingMoment = getPendingMoment(context);
|
||||
const pendingAlbum = getPendingAlbum(context);
|
||||
return {
|
||||
momentId: pendingMoment?.momentId ?? "",
|
||||
expectedCost: pendingMoment?.unlockCost ?? 0,
|
||||
albumId: pendingAlbum?.albumId ?? "",
|
||||
expectedCost: pendingAlbum?.unlockCost ?? 0,
|
||||
};
|
||||
},
|
||||
onDone: [
|
||||
{
|
||||
guard: ({ event }) => event.output.unlocked,
|
||||
guard: ({ event }) =>
|
||||
event.output.unlocked && !event.output.locked,
|
||||
target: "ready",
|
||||
actions: assign(({ context, event }) => ({
|
||||
items: replaceMoment(context.items, event.output),
|
||||
creditBalance: event.output.creditBalance || context.creditBalance,
|
||||
pendingConfirmMomentId: null,
|
||||
unlockingMomentId: null,
|
||||
items: patchAlbumInList(context.items, event.output),
|
||||
creditBalance: event.output.creditBalance,
|
||||
pendingConfirmAlbumId: null,
|
||||
unlockingAlbumId: null,
|
||||
unlockErrorMessage: null,
|
||||
unlockSuccessNonce: context.unlockSuccessNonce + 1,
|
||||
})),
|
||||
@@ -174,10 +137,10 @@ export const privateRoomMachine = setup({
|
||||
event.output.reason === "insufficient_credits",
|
||||
target: "ready",
|
||||
actions: assign(({ context, event }) => ({
|
||||
items: replaceMoment(context.items, event.output),
|
||||
creditBalance: event.output.creditBalance || context.creditBalance,
|
||||
pendingConfirmMomentId: null,
|
||||
unlockingMomentId: null,
|
||||
items: patchAlbumInList(context.items, event.output),
|
||||
creditBalance: event.output.creditBalance,
|
||||
pendingConfirmAlbumId: null,
|
||||
unlockingAlbumId: null,
|
||||
unlockErrorMessage: null,
|
||||
unlockPaywallRequest: toPaywallRequest(event.output),
|
||||
})),
|
||||
@@ -186,17 +149,29 @@ export const privateRoomMachine = setup({
|
||||
guard: ({ event }) => event.output.reason === "cost_changed",
|
||||
target: "loading",
|
||||
actions: assign(({ event }) => ({
|
||||
pendingConfirmMomentId: null,
|
||||
unlockingMomentId: null,
|
||||
pendingConfirmAlbumId: null,
|
||||
unlockingAlbumId: null,
|
||||
unlockErrorMessage: toUnlockErrorMessage(event.output),
|
||||
})),
|
||||
},
|
||||
{
|
||||
guard: ({ event }) => event.output.reason === "not_found",
|
||||
target: "ready",
|
||||
actions: assign(({ context, event }) => ({
|
||||
items: removeAlbum(context.items, event.output.albumId),
|
||||
creditBalance: event.output.creditBalance,
|
||||
pendingConfirmAlbumId: null,
|
||||
unlockingAlbumId: null,
|
||||
unlockErrorMessage: toUnlockErrorMessage(event.output),
|
||||
})),
|
||||
},
|
||||
{
|
||||
target: "ready",
|
||||
actions: assign(({ context, event }) => ({
|
||||
items: replaceMoment(context.items, event.output),
|
||||
pendingConfirmMomentId: null,
|
||||
unlockingMomentId: null,
|
||||
items: patchAlbumInList(context.items, event.output),
|
||||
creditBalance: event.output.creditBalance,
|
||||
pendingConfirmAlbumId: null,
|
||||
unlockingAlbumId: null,
|
||||
unlockErrorMessage: toUnlockErrorMessage(event.output),
|
||||
})),
|
||||
},
|
||||
@@ -204,8 +179,8 @@ export const privateRoomMachine = setup({
|
||||
onError: {
|
||||
target: "ready",
|
||||
actions: assign(({ event }) => ({
|
||||
pendingConfirmMomentId: null,
|
||||
unlockingMomentId: null,
|
||||
pendingConfirmAlbumId: null,
|
||||
unlockingAlbumId: null,
|
||||
unlockErrorMessage: toPrivateRoomErrorMessage(event.error),
|
||||
})),
|
||||
},
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import type {
|
||||
PrivateRoomMoment,
|
||||
PrivateRoomProfile,
|
||||
} from "@/data/dto/private-room";
|
||||
import type { PrivateAlbum } from "@/data/dto/private-room";
|
||||
|
||||
export interface PrivateRoomUnlockPaywallRequest {
|
||||
momentId: string;
|
||||
albumId: string;
|
||||
reason: string;
|
||||
requiredCredits: number;
|
||||
currentCredits: number;
|
||||
@@ -12,29 +9,23 @@ export interface PrivateRoomUnlockPaywallRequest {
|
||||
}
|
||||
|
||||
export interface PrivateRoomState {
|
||||
profile: PrivateRoomProfile | null;
|
||||
items: PrivateRoomMoment[];
|
||||
nextCursor: string | null;
|
||||
hasMore: boolean;
|
||||
items: PrivateAlbum[];
|
||||
creditBalance: number;
|
||||
errorMessage: string | null;
|
||||
unlockingMomentId: string | null;
|
||||
unlockingAlbumId: string | null;
|
||||
unlockErrorMessage: string | null;
|
||||
pendingConfirmMomentId: string | null;
|
||||
pendingConfirmAlbumId: string | null;
|
||||
unlockPaywallRequest: PrivateRoomUnlockPaywallRequest | null;
|
||||
unlockSuccessNonce: number;
|
||||
}
|
||||
|
||||
export const initialState: PrivateRoomState = {
|
||||
profile: null,
|
||||
items: [],
|
||||
nextCursor: null,
|
||||
hasMore: false,
|
||||
creditBalance: 0,
|
||||
errorMessage: null,
|
||||
unlockingMomentId: null,
|
||||
unlockingAlbumId: null,
|
||||
unlockErrorMessage: null,
|
||||
pendingConfirmMomentId: null,
|
||||
pendingConfirmAlbumId: null,
|
||||
unlockPaywallRequest: null,
|
||||
unlockSuccessNonce: 0,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user