Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"jsqr": "1.4.0",
"lucide-react": "^0.546.0",
"motion": "^12.23.24",
"onehook-api-client": "1.0.23",
"onehook-api-client": "1.0.30",
"qrcode.react": "^4.2.0",
"react": "^19.0.1",
"react-dom": "^19.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/api/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type PresenceState = 'ONLINE' | 'OFFLINE';
* as a JSON string the client parses into a map of `reactorUserId -> reaction ciphertext`; each value
* is E2E-encrypted exactly like a message body.
*/
export interface ChatMessageExtended extends ChatMessage {
export interface ChatMessageExtended extends Omit<ChatMessage, 'contentType'> {
contentType?: MessageContentType | null;
replyToMessageId?: string | null;
replyToTimestamp?: number | null;
Expand Down
32 changes: 25 additions & 7 deletions src/api/matching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ import {
type RoseQuota,
} from './rest';

/** Discovery categories (mirrors the backend `DiscoveryCategory`). */
export type DiscoveryCategory = 'ALL' | 'PROFILE_MATCH' | 'ONEHOOK_SUGGESTED' | 'SIMILAR';

export interface DiscoverFeed {
candidates: RankedCandidate[];
count: number;
algorithm: string;
/** The category the backend applied. */
category?: DiscoveryCategory;
/** Categories this member's tier may pick; just ['ALL'] for free members. */
availableCategories?: DiscoveryCategory[];
}

export type ProfileSection =
| 'PHOTOS'
| 'BIO'
Expand All @@ -25,16 +38,21 @@ export const MatchingApi = {
return (sdkClient as any).indexLocation({ userId, lat, lon });
},

discover: async (userId: string, lat: number, lon: number) => {
const timeoutPromise = new Promise<{ candidates: RankedCandidate[]; count: number; algorithm: string }>((_, reject) =>
/**
* The discover feed. Without `category` every tier gets the mixed deck (OneHook Intelligence +
* Mr. OneHook). Super+ may pass a category; the backend answers 403 PREMIUM_REQUIRED otherwise.
*/
discover: async (userId: string, lat: number, lon: number, category?: DiscoveryCategory) => {
const timeoutPromise = new Promise<DiscoverFeed>((_, reject) =>
setTimeout(() => reject(new Error('Discover request timed out. Please check your connection and try again.')), 10000)
);
const discoverPromise = (async () => {
return (await (sdkClient as any).discover({ userId, lat, lon })) as unknown as {
candidates: RankedCandidate[];
count: number;
algorithm: string;
};
return (await (sdkClient as any).discover({
userId,
lat,
lon,
...(category && category !== 'ALL' ? { category } : {}),
})) as unknown as DiscoverFeed;
})();
return Promise.race([discoverPromise, timeoutPromise]);
},
Expand Down
6 changes: 6 additions & 0 deletions src/app/AppContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ export function AppContent() {
loading: candidatesLoading,
error: candidatesError,
refresh: refreshCandidates,
category: discoveryCategory,
availableCategories,
setCategory: setDiscoveryCategory,
} = useCandidates(userCoords);
const { pass, like, loading: swipeLoading } = useSwipe();
const { showToast } = useToast();
Expand Down Expand Up @@ -309,6 +312,9 @@ export function AppContent() {
>
<DiscoveryView
candidates={candidates}
category={discoveryCategory}
availableCategories={availableCategories}
onCategoryChange={setDiscoveryCategory}
loading={candidatesLoading}
error={candidatesError}
currentUser={currentUser}
Expand Down
22 changes: 18 additions & 4 deletions src/features/discovery/DiscoveryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export interface DiscoveryProfileData {
verified?: boolean;
score?: number;
recommendationReason?: string;
/** 'ONEHOOK_INTELLIGENCE' | 'MR_ONEHOOK' (from the discover API). */
matchFinder?: string;
matchFinderLabel?: string;
/** Why this candidate is shown (from the discover API). */
reasoning?: string;
photos?: string[];
pictures?: string[];
pictureTransforms?: Record<string, string>;
Expand Down Expand Up @@ -630,10 +635,19 @@ export function DiscoveryCard({

return (
<article className={`w-full max-w-[470px] mx-auto bg-surface-card sm:border sm:border-border sm:rounded-xl flex flex-col overflow-hidden select-none ${className}`}>
{/* Recommendation banner */}
{((candidate.score && candidate.score >= 0.9) || candidate.recommendationReason) && (
<div className="bg-ig-blue/5 border-b border-border px-4 py-3 text-[11px] text-text-secondary leading-relaxed italic">
{candidate.recommendationReason || 'Handpicked for you — high compatibility and shared vibe.'}
{/* Match finder: who found this person and why. Mr. OneHook = from a OneHook suggestion (asked or
inferred); OneHook Intelligence = profile details match the member's preferences. */}
{(candidate.matchFinderLabel || candidate.reasoning || candidate.recommendationReason) && (
<div
className={`border-b border-border px-4 py-3 text-[11px] leading-relaxed ${
candidate.matchFinder === 'MR_ONEHOOK' ? 'bg-ig-blue/10 text-text' : 'bg-ig-blue/5 text-text-secondary'
}`}
data-match-finder={candidate.matchFinder || undefined}
>
{candidate.matchFinderLabel && (
<span className="font-semibold not-italic mr-1.5">{candidate.matchFinderLabel}</span>
)}
<span className="italic">{candidate.reasoning || candidate.recommendationReason}</span>
</div>
)}

Expand Down
59 changes: 57 additions & 2 deletions src/features/discovery/DiscoveryView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AnimatePresence, motion } from 'motion/react';
import type { DiscoveryCandidate, UserProfile } from '../../types';
import type { ApiError } from '../../lib/api-client';
import type { LikeTargetType } from '../../api/rest';
import { MatchingApi } from '../../api/matching';
import { MatchingApi, type DiscoveryCategory } from '../../api/matching';
import { LoadingSpinner } from '../../components/common/LoadingSpinner';
import { DiscoveryCard } from './DiscoveryCard';
import { CommentComposer } from './CommentComposer';
Expand All @@ -25,6 +25,9 @@ export function DiscoveryView({
onRetry,
onPass,
onLike,
category = 'ALL',
availableCategories = ['ALL'],
onCategoryChange,
}: {
key?: string;
candidates: DiscoveryCandidate[];
Expand All @@ -44,6 +47,10 @@ export function DiscoveryView({
likeKind?: 'LIKE' | 'ROSE'
) => Promise<boolean>;
onNavigateToProfile?: () => void;
/** Applied discovery category and the ones this member may pick (from the backend). */
category?: DiscoveryCategory;
availableCategories?: DiscoveryCategory[];
onCategoryChange?: (category: DiscoveryCategory) => void;
}) {
// The element being commented on (composer open). `kind` distinguishes a normal like from a rose.
const [activeComposer, setActiveComposer] = useState<{
Expand Down Expand Up @@ -129,6 +136,12 @@ export function DiscoveryView({
advance(candidateId);
};

// Super+ members get a category selector; free members (availableCategories = ['ALL']) see none.
const selector =
onCategoryChange && availableCategories.length > 1 ? (
<CategorySelector value={category} options={availableCategories} onChange={onCategoryChange} />
) : null;

if (loading) {
return (
<div className="h-full flex items-center justify-center bg-bg text-text">
Expand Down Expand Up @@ -157,7 +170,8 @@ export function DiscoveryView({

if (!currentCandidate) {
return (
<div className="h-full flex items-center justify-center bg-bg text-text p-6">
<div className="h-full flex flex-col items-center justify-center bg-bg text-text p-6 gap-6">
{selector}
<div className="max-w-sm w-full text-center space-y-3">
<h2 className="text-lg font-semibold text-text">You&rsquo;re All Caught Up</h2>
<p className="text-sm text-text-secondary">Check back soon for new people to meet.</p>
Expand All @@ -169,6 +183,7 @@ export function DiscoveryView({
return (
<div className="h-full overflow-y-auto bg-bg text-text">
<div className="w-full max-w-[500px] mx-auto px-0 sm:px-4 py-4">
{selector && <div className="px-4 sm:px-0 pb-3">{selector}</div>}
<AnimatePresence mode="wait">
<motion.div
key={currentCandidate.id}
Expand Down Expand Up @@ -203,3 +218,43 @@ export function DiscoveryView({
</div>
);
}

const CATEGORY_LABELS: Record<DiscoveryCategory, string> = {
ALL: 'For you',
PROFILE_MATCH: 'Matches your preferences',
ONEHOOK_SUGGESTED: 'Mr. OneHook picks',
SIMILAR: 'Similar to your likes',
};

/** Discovery category chips (Super+). Options come from the backend's availableCategories. */
function CategorySelector({
value,
options,
onChange,
}: {
value: DiscoveryCategory;
options: DiscoveryCategory[];
onChange: (c: DiscoveryCategory) => void;
}) {
return (
<div role="tablist" aria-label="Discovery category" className="flex gap-2 overflow-x-auto no-scrollbar">
{options.map((option) => (
<button
key={option}
type="button"
role="tab"
aria-selected={option === value}
onClick={() => option !== value && onChange(option)}
{...trackProps(UiElement.DISCOVER_CATEGORY_SELECT, { value: option.toLowerCase() })}
className={`shrink-0 px-3 py-1.5 rounded-full text-xs font-semibold border transition-colors cursor-pointer ${
option === value
? 'bg-ig-blue text-white border-ig-blue'
: 'bg-surface border-border text-text-secondary hover:text-text'
}`}
>
{CATEGORY_LABELS[option] ?? option}
</button>
))}
</div>
);
}
29 changes: 26 additions & 3 deletions src/hooks/use-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { MessageStatus } from 'onehook-api-client/graphql';
import { PreferencesApi } from '../api/preferences';
import { StateApi } from '../api/state';
import { ProfileApi } from '../api/profile';
import { MatchingApi, type ProfileSection } from '../api/matching';
import { MatchingApi, type DiscoveryCategory, type ProfileSection } from '../api/matching';
import type { LikeTargetType, ReceivedLike } from '../api/rest';
import { ChatMessagingApi } from '../api/chat';
import { ChatEncryptionManager } from '../lib/chat-encryption';
Expand Down Expand Up @@ -170,12 +170,28 @@ function toDiscoveryCandidate(
distanceKm: candidate.distanceKm,
score: candidate.score,
photos: [],
...finderOf(candidate),
};
}

/** The match-finder attribution the backend puts on every card; survives profile hydration. */
function finderOf(candidate: DiscoverResponse['candidates'][number]) {
return {
matchFinder: candidate.matchFinder,
matchFinderLabel: candidate.matchFinderLabel,
reasoning: candidate.reasoning,
suggestionBasis: candidate.suggestionBasis,
suggestionId: candidate.suggestionId,
};
}

export function useCandidates(activeCoords?: Coordinates) {
const { currentUser, setCandidates } = useAppStore();
const [candidatesList, setCandidatesList] = useState<DiscoveryCandidate[]>([]);
// Discovery category (Super+ may narrow the feed). availableCategories comes from the backend, so the
// selector never hard-codes tier rules.
const [category, setCategory] = useState<DiscoveryCategory>('ALL');
const [availableCategories, setAvailableCategories] = useState<DiscoveryCategory[]>(['ALL']);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<ApiError | null>(null);
const [refreshKey, setRefreshKey] = useState(0);
Expand Down Expand Up @@ -220,8 +236,11 @@ export function useCandidates(activeCoords?: Coordinates) {
throw new ApiError('Authentication required to discover candidates', 401, 'UNAUTHORIZED');
}

const res = await MatchingApi.discover(userId, lat, lon);
const res = await MatchingApi.discover(userId, lat, lon, category);
if (!active) return;
if (Array.isArray(res?.availableCategories) && res.availableCategories.length > 0) {
setAvailableCategories(res.availableCategories);
}

if (res && Array.isArray(res.candidates) && res.candidates.length > 0) {
const candidatePromises = res.candidates.map(async (candidate) => {
Expand All @@ -247,6 +266,7 @@ export function useCandidates(activeCoords?: Coordinates) {
distance: candidate.distanceKm,
distanceKm: candidate.distanceKm,
score: candidate.score,
...finderOf(candidate),
} as DiscoveryCandidate;
}
} catch (pErr) {
Expand Down Expand Up @@ -296,7 +316,7 @@ export function useCandidates(activeCoords?: Coordinates) {
return () => {
active = false;
};
}, [uid, lat, lon, refreshKey, setCandidates]);
}, [uid, lat, lon, refreshKey, category, setCandidates]);

const refresh = useCallback(() => {
setRefreshKey((prev) => prev + 1);
Expand All @@ -307,6 +327,9 @@ export function useCandidates(activeCoords?: Coordinates) {
loading,
error,
refresh,
category,
availableCategories,
setCategory,
};
}

Expand Down
10 changes: 6 additions & 4 deletions src/lib/analytics/generated/telemetryCatalog.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// GENERATED FILE - DO NOT EDIT.
// telemetry-integrity: sha256 ba978d01fe927413a36fd8f2b3d8d595ed4c72a84bc4ad1c5a9e880a72aa4c97
// telemetry-integrity: sha256 34a4918a54cc60e7ee0259d51cd8fba1a6167c89465599a00f3f8ef937c44004
// Source of truth: OneHookBackend/packages/telemetry/src/catalog.ts
// Regenerate: (OneHookBackend) npm run telemetry:generate && npm run telemetry:sync
// Catalog version 1.7.0, hash 4a3328962531236a.
// Catalog version 1.8.0, hash 9a56f9fef0ed4ae7.
//
// HARD RULE: every user interaction MUST emit ui_interaction with an id from THIS file, and
// ids are controlled by the backend. Read TELEMETRY_CONTRACT.txt (printed by every build).
/* eslint-disable */

export const TELEMETRY_CATALOG_VERSION = "1.7.0";
export const TELEMETRY_CATALOG_HASH = "4a3328962531236a";
export const TELEMETRY_CATALOG_VERSION = "1.8.0";
export const TELEMETRY_CATALOG_HASH = "9a56f9fef0ed4ae7";

/** Every signal type the ingest accepts. */
export const SignalType = {
Expand Down Expand Up @@ -335,6 +335,7 @@ export const UiElement = {
DISCOVER_LIKES_YOU_OPEN: "discover.likes_you_open",
DISCOVER_ADD_HOOK_OPEN: "discover.add_hook_open",
DISCOVER_RETRY: "discover.retry",
DISCOVER_CATEGORY_SELECT: "discover.category_select",
DISCOVER_ADD_HOOK_SUBMIT: "discover.add_hook_submit",
DISCOVER_UPGRADE_OPEN: "discover.upgrade_open",
LIKE_COMPOSER_SEND: "like_composer.send",
Expand Down Expand Up @@ -591,6 +592,7 @@ export const UI_ELEMENTS: { readonly [K in UiElementId]: UiElementSpec } = {
"discover.likes_you_open": { screen: "DISCOVER", kind: "button", actions: ["tap", "dismiss"], values: null, platforms: ["ios", "android"] },
"discover.add_hook_open": { screen: "DISCOVER", kind: "button", actions: ["tap", "dismiss"], values: null, platforms: ["ios"] },
"discover.retry": { screen: "DISCOVER", kind: "button", actions: ["tap"], values: null, platforms: ["web", "ios", "android"] },
"discover.category_select": { screen: "DISCOVER", kind: "button", actions: ["tap"], values: ["all", "profile_match", "onehook_suggested", "similar"], platforms: ["web", "ios", "android"] },
"discover.add_hook_submit": { screen: "DISCOVER", kind: "button", actions: ["submit"], values: null, platforms: ["web", "ios"] },
"discover.upgrade_open": { screen: "DISCOVER", kind: "button", actions: ["tap", "dismiss"], values: null, platforms: ["ios"] },
"like_composer.send": { screen: "LIKE_COMPOSER", kind: "button", actions: ["submit"], values: null, platforms: ["web", "ios", "android"] },
Expand Down
Loading
Loading