Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmp: dont close callback page #4149

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3de31c3
tmp: dont close callback page
sshanzel Feb 5, 2025
8ccd6ef
tmp: more logs
sshanzel Feb 5, 2025
1372d58
fix: actions being ready
sshanzel Feb 5, 2025
20e104e
tmp: is authenticating
sshanzel Feb 5, 2025
efd126f
tmp: is message received
sshanzel Feb 5, 2025
fdf8d26
chore: log removal
sshanzel Feb 5, 2025
6d3733b
tmp: logs
sshanzel Feb 5, 2025
1ba2e1c
tmp: stop cleanup
sshanzel Feb 5, 2025
624e74a
Revert "tmp: stop cleanup"
sshanzel Feb 5, 2025
2eff3d7
fetch main
sshanzel Feb 5, 2025
9cf42f6
Revert "Revert "fix: onboarding anon user fetching actions (#4150)" (…
sshanzel Feb 5, 2025
018c882
fix: missing dependencies
sshanzel Feb 5, 2025
a592f83
chore: log removal
sshanzel Feb 5, 2025
92c40a5
Merge branch 'revert-revert-condition' into fix-facebook-signup
sshanzel Feb 5, 2025
70e1b08
Merge branch 'main' into fix-facebook-signup
sshanzel Feb 6, 2025
af0452d
Merge branch 'main' into fix-facebook-signup
sshanzel Feb 6, 2025
a12abcd
refactor: usage of broadcast channel
sshanzel Feb 6, 2025
5604328
test: broadcast messaging
sshanzel Feb 6, 2025
1127f64
chore: log removal
sshanzel Feb 6, 2025
70f5c3c
test: sending message
sshanzel Feb 6, 2025
7700e56
tmp: test
sshanzel Feb 6, 2025
e7ad720
tmp: pass props
sshanzel Feb 6, 2025
2111560
revert: test
sshanzel Feb 6, 2025
c1f56b8
revert
sshanzel Feb 6, 2025
c5a41d8
Merge branch 'main' into fix-facebook-signup
sshanzel Feb 6, 2025
a40fa30
fix: is onboarding ready evaluation
sshanzel Feb 7, 2025
2b20e64
fix: missing dep
sshanzel Feb 7, 2025
9a93601
Revert "fix: missing dep"
sshanzel Feb 7, 2025
87189ef
Revert "fix: is onboarding ready evaluation"
sshanzel Feb 7, 2025
efaf755
refactor: name of returned variable
sshanzel Feb 7, 2025
64efb79
Merge branch 'main' into fix-facebook-signup
sshanzel Feb 12, 2025
ec233e5
test: use the same channels
sshanzel Feb 12, 2025
abc59ed
Merge branch 'fix-isonboarding' into fix-facebook-signup
sshanzel Feb 12, 2025
97828c0
Revert "test: use the same channels"
sshanzel Feb 12, 2025
5d82dfb
tmp: usage of new channel
sshanzel Feb 12, 2025
1efbd3e
feat: channel listener
sshanzel Feb 12, 2025
d17e0e3
use two listeners
sshanzel Feb 12, 2025
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
26 changes: 23 additions & 3 deletions packages/shared/src/components/auth/AuthOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ import type { CloseAuthModalFunc } from '../../hooks/useAuthForms';
import { useLogContext } from '../../contexts/LogContext';
import { useSettingsContext } from '../../contexts/SettingsContext';
import { useToastNotification, useEventListener } from '../../hooks';
import { isTesting } from '../../lib/constants';
import { BROADCAST_CHANNEL_NAME, isTesting } from '../../lib/constants';
import type { SignBackProvider } from '../../hooks/auth/useSignBack';
import { SIGNIN_METHOD_KEY, useSignBack } from '../../hooks/auth/useSignBack';
import type { AnonymousUser, LoggedUser } from '../../lib/user';
import { labels } from '../../lib';
import type { ButtonProps } from '../buttons/Button';
import usePersistentState from '../../hooks/usePersistentState';
import { broadcastMessage } from '../../lib/func';

const AuthDefault = dynamic(
() => import(/* webpackChunkName: "authDefault" */ './AuthDefault'),
Expand Down Expand Up @@ -309,11 +310,17 @@ function AuthOptions({
onSetActiveDisplay(AuthDisplay.CodeVerification);
};

useEventListener(globalThis, 'message', async (e) => {
const [channel] = useState(new BroadcastChannel(BROADCAST_CHANNEL_NAME));

const eventSend = async (e) => {
console.log('message received: ', e.data);

if (e.data?.eventKey !== AuthEvent.SocialRegistration || ignoreMessages) {
return undefined;
}

console.log('messaging flow: ', e.data.flow);

if (e.data?.flow) {
const connected = await getKratosFlow(AuthFlow.Registration, e.data.flow);

Expand Down Expand Up @@ -376,7 +383,10 @@ function AuthOptions({
}

return onSetActiveDisplay(AuthDisplay.SocialRegistration);
});
};

useEventListener(channel, 'message', eventSend);
useEventListener(globalThis, 'message', eventSend);

const onEmailRegistration = (emailAd: string) => {
// before displaying registration, ensure the email doesn't exist
Expand Down Expand Up @@ -410,6 +420,16 @@ function AuthOptions({
onSetActiveDisplay(defaultDisplay);
};

useEffect(() => {
console.log('MOUNTED');

broadcastMessage({ eventKey: 'test' });

return () => {
console.log('UNMOUNTED');
};
}, []);

return (
<div
className={classNames(
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/hooks/auth/useOnboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ActionType } from '../../graphql/actions';

interface UseOnboarding {
shouldShowAuthBanner: boolean;
isOnboardingReady: boolean;
isOnboardingActionsReady: boolean;
hasCompletedEditTags: boolean;
hasCompletedContentTypes: boolean;
completeStep: (action: ActionType) => void;
Expand Down Expand Up @@ -33,7 +33,7 @@ export const useOnboarding = (): UseOnboarding => {

return {
shouldShowAuthBanner,
isOnboardingReady: isActionsFetched && isAuthReady,
isOnboardingActionsReady: isActionsFetched && isAuthReady,
hasCompletedEditTags,
hasCompletedContentTypes,
completeStep: (action: ActionType) => completeAction(action),
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,4 @@ export const invalidPlusRegions = [
export const DeletedPostId = '404';

export const BROADCAST_CHANNEL_NAME = 'dailydev_broadcast';
export const BROADCAST_CHANNEL = new BroadcastChannel(BROADCAST_CHANNEL_NAME);
11 changes: 7 additions & 4 deletions packages/webapp/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ const getRedirectUri = () =>
const getPage = () => window.location.pathname;

function InternalApp({ Component, pageProps, router }: AppProps): ReactElement {
const { isOnboardingReady, hasCompletedContentTypes, hasCompletedEditTags } =
useOnboarding();
const {
isOnboardingActionsReady,
hasCompletedContentTypes,
hasCompletedEditTags,
} = useOnboarding();
const didRegisterSwRef = useRef(false);

const { unreadCount } = useNotificationContext();
Expand All @@ -78,14 +81,14 @@ function InternalApp({ Component, pageProps, router }: AppProps): ReactElement {

useEffect(() => {
if (
isOnboardingReady &&
isOnboardingActionsReady &&
(!hasCompletedEditTags || !hasCompletedContentTypes) &&
!router.pathname.includes('/onboarding')
) {
router.replace('/onboarding');
}
}, [
isOnboardingReady,
isOnboardingActionsReady,
router,
hasCompletedEditTags,
hasCompletedContentTypes,
Expand Down
35 changes: 28 additions & 7 deletions packages/webapp/pages/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
} from '@dailydotdev/shared/src/lib/featureManagement';
import { OnboardingHeadline } from '@dailydotdev/shared/src/components/auth';
import {
useActions,
useConditionalFeature,
useViewSize,
ViewSize,
Expand All @@ -60,7 +61,10 @@ import type { LoggedUser } from '@dailydotdev/shared/src/lib/user';
import { useSettingsContext } from '@dailydotdev/shared/src/contexts/SettingsContext';
import { ChecklistViewState } from '@dailydotdev/shared/src/lib/checklist';
import { getPathnameWithQuery } from '@dailydotdev/shared/src/lib';
import { webappUrl } from '@dailydotdev/shared/src/lib/constants';
import {
BROADCAST_CHANNEL_NAME,
webappUrl,
} from '@dailydotdev/shared/src/lib/constants';
import dynamic from 'next/dynamic';
import { usePushNotificationContext } from '@dailydotdev/shared/src/contexts/PushNotificationContext';
import { PaymentContextProvider } from '@dailydotdev/shared/src/contexts/PaymentContext';
Expand Down Expand Up @@ -152,18 +156,15 @@ const seo: NextSeoProps = {

export function OnboardPage(): ReactElement {
const { isAvailable: canUserInstallPWA } = useInstallPWA();
const {
isOnboardingReady,
hasCompletedEditTags,
hasCompletedContentTypes,
completeStep,
} = useOnboarding();
const { hasCompletedEditTags, hasCompletedContentTypes, completeStep } =
useOnboarding();
const router = useRouter();
const { setSettings, autoDismissNotifications } = useSettingsContext();
const isLogged = useRef(false);
const { logSubscriptionEvent } = usePlusSubscription();
const { user, isAuthReady, anonymous, loginState, isValidRegion } =
useAuthContext();
const { isActionsFetched } = useActions();
const shouldVerify = anonymous?.shouldVerify;
const { growthbook } = useGrowthBookContext();
const { getFeatureValue } = useFeaturesReadyContext();
Expand Down Expand Up @@ -224,6 +225,8 @@ export function OnboardPage(): ReactElement {
OnboardingStep.AndroidPWA,
].includes(activeScreen);

const isOnboardingReady = isAuthReady && (isActionsFetched || !user);

useEffect(() => {
if (
!isPageReady ||
Expand Down Expand Up @@ -264,6 +267,24 @@ export function OnboardPage(): ReactElement {
activeScreen,
]);

const [channel] = useState(new BroadcastChannel(BROADCAST_CHANNEL_NAME));
useEffect(() => {
if (!channel) {
return undefined;
}

const func = () => {
console.log('onboarding received message');
};

channel.addEventListener('message', func);

return () => {
channel.removeEventListener('message', func);
channel.close();
};
}, [channel]);

const onClickNext: OnboardingOnClickNext = (options) => {
logEvent({
event_name: LogEvent.ClickOnboardingNext,
Expand Down