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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ webapp.xml
.idea/

# Figma MCP
figma-images/
figma-images/

# Build cache
*.tsbuildinfo
node-compile-cache/
2 changes: 1 addition & 1 deletion packages/webapp/hooks/log/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type { CardConfig, NavigationEvent } from './useCardNavigation';

// Data fetching
export { useLog, LOG_QUERY_KEY, NoLogDataError } from './useLog';
export type { UseLogResult } from './useLog';
export type { UseLogResult, UseLogOptions } from './useLog';

// Music
export { useBackgroundMusic } from './useBackgroundMusic';
Expand Down
23 changes: 18 additions & 5 deletions packages/webapp/hooks/log/useLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import type { LogData } from '../../types/log';
*/
export const LOG_QUERY_KEY = ['log'];

export interface UseLogOptions {
enabled?: boolean;
userId?: string;
}

/**
* Custom error class for when user has no log data
*/
Expand All @@ -21,8 +26,13 @@ export class NoLogDataError extends Error {
* Fetch log data from the API.
* Throws NoLogDataError if user doesn't have enough data (404 response).
*/
async function fetchLog(): Promise<LogData> {
const response = await fetch(`${apiUrl}/log`, {
async function fetchLog(userId?: string): Promise<LogData> {
const url = new URL(`${apiUrl}/log`);
if (userId) {
url.searchParams.set('userId', userId);
}

const response = await fetch(url.toString(), {
credentials: 'include',
});

Expand Down Expand Up @@ -51,10 +61,13 @@ export interface UseLogResult {
* Hook for fetching log data from the API.
* Returns hasData: false when the user doesn't have enough 2025 activity.
*/
export function useLog(enabled = true): UseLogResult {
export function useLog(options: UseLogOptions | boolean = true): UseLogResult {
const { enabled = true, userId } =
typeof options === 'boolean' ? { enabled: options } : options;

const query = useQuery<LogData, Error>({
queryKey: LOG_QUERY_KEY,
queryFn: fetchLog,
queryKey: userId ? [...LOG_QUERY_KEY, userId] : LOG_QUERY_KEY,
queryFn: () => fetchLog(userId),
enabled,
staleTime: Infinity, // Log data doesn't change often
retry: (failureCount, error) => {
Expand Down
12 changes: 11 additions & 1 deletion packages/webapp/pages/log/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React, {
useCallback,
useRef,
} from 'react';
import { useRouter } from 'next/router';
import { motion, AnimatePresence } from 'framer-motion';
import { useAuthContext } from '@dailydotdev/shared/src/contexts/AuthContext';
import { useLogContext } from '@dailydotdev/shared/src/contexts/LogContext';
Expand Down Expand Up @@ -54,14 +55,23 @@ export const getServerSideProps: GetServerSideProps = async () => {
const noDataTheme = CARD_THEMES.welcome;

export default function LogPage(): ReactElement {
const router = useRouter();
const { userId } = router.query;
const { user, isLoggedIn, isAuthReady, tokenRefreshed } = useAuthContext();
const { logEvent } = useLogContext();
const [isTouchDevice, setIsTouchDevice] = useState(true);
const hasLoggedImpression = useRef(false);
const { displayToast } = useToastNotification();

// Fetch log data from API
const { data, isLoading: isDataLoading, hasData } = useLog(isLoggedIn);
const {
data,
isLoading: isDataLoading,
hasData,
} = useLog({
enabled: isLoggedIn,
userId: typeof userId === 'string' ? userId : undefined,
});

// Preload images (archetypes + source logos) during browser idle time
const imagesToPreload = useMemo(() => {
Expand Down