Skip to content

Commit 4ec45a2

Browse files
committed
feat(core): add sign in button to shared doc (#7952)
![CleanShot 2024-08-23 at 12 05 12@2x](https://github.com/user-attachments/assets/2c146707-9551-4044-b289-0904653f30f2)
1 parent dde4574 commit 4ec45a2

File tree

6 files changed

+38
-61
lines changed

6 files changed

+38
-61
lines changed

packages/frontend/core/src/components/cloud/share-header-right-item/authenticated-item.tsx

Lines changed: 0 additions & 49 deletions
This file was deleted.

packages/frontend/core/src/components/cloud/share-header-right-item/index.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { AuthService } from '@affine/core/modules/cloud';
22
import { type DocMode, useLiveData, useService } from '@toeverything/infra';
3-
import { useState } from 'react';
43

5-
import { AuthenticatedItem } from './authenticated-item';
64
import { PresentButton } from './present';
5+
import { SignIn } from './sign-in';
76
import * as styles from './styles.css';
87
import { PublishPageUserAvatar } from './user-avatar';
98

@@ -16,20 +15,16 @@ export type ShareHeaderRightItemProps = {
1615
const ShareHeaderRightItem = ({ ...props }: ShareHeaderRightItemProps) => {
1716
const loginStatus = useLiveData(useService(AuthService).session.status$);
1817
const { publishMode } = props;
19-
const [isMember, setIsMember] = useState(false);
20-
21-
// TODO(@JimmFly): Add TOC
18+
const authenticated = loginStatus === 'authenticated';
2219
return (
2320
<div className={styles.rightItemContainer}>
24-
{loginStatus === 'authenticated' ? (
25-
<AuthenticatedItem setIsMember={setIsMember} {...props} />
26-
) : null}
21+
{authenticated ? null : <SignIn />}
2722
{publishMode === 'edgeless' ? <PresentButton /> : null}
28-
{loginStatus === 'authenticated' ? (
23+
{authenticated ? (
2924
<>
3025
<div
3126
className={styles.headerDivider}
32-
data-is-member={isMember}
27+
data-authenticated={true}
3328
data-is-edgeless={publishMode === 'edgeless'}
3429
/>
3530
<PublishPageUserAvatar />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Button } from '@affine/component/ui/button';
2+
import { authAtom } from '@affine/core/atoms';
3+
import { useI18n } from '@affine/i18n';
4+
import { useSetAtom } from 'jotai';
5+
import { useCallback } from 'react';
6+
7+
import * as styles from './styles.css';
8+
9+
export const SignIn = () => {
10+
const setOpen = useSetAtom(authAtom);
11+
12+
const t = useI18n();
13+
14+
const onClickSignIn = useCallback(() => {
15+
setOpen(state => ({
16+
...state,
17+
openModal: true,
18+
}));
19+
}, [setOpen]);
20+
21+
return (
22+
<Button
23+
className={styles.editButton}
24+
onClick={onClickSignIn}
25+
data-testid="share-page-sign-in-button"
26+
>
27+
{t['com.affine.share-page.header.login']()}
28+
</Button>
29+
);
30+
};

packages/frontend/core/src/pages/workspace/share/share-header.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BlocksuiteHeaderTitle } from '@affine/core/components/blocksuite/block-suite-header/title';
22
import { EditorModeSwitch } from '@affine/core/components/blocksuite/block-suite-mode-switch';
33
import ShareHeaderRightItem from '@affine/core/components/cloud/share-header-right-item';
4+
import { AuthModal } from '@affine/core/providers/modal-provider';
45
import type { DocCollection } from '@blocksuite/store';
56
import type { DocMode } from '@toeverything/infra';
67

@@ -25,6 +26,7 @@ export function ShareHeader({
2526
pageId={pageId}
2627
publishMode={publishMode}
2728
/>
29+
<AuthModal />
2830
</div>
2931
);
3032
}

packages/frontend/i18n/src/resources/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,7 @@
14081408
"com.affine.share-page.footer.description": "Empower your sharing with AFFiNE Cloud: One-click doc sharing",
14091409
"com.affine.share-page.footer.get-started": "Get started for free",
14101410
"com.affine.share-page.header.present": "Present",
1411+
"com.affine.share-page.header.login": "Login or Sign Up",
14111412
"com.affine.shortcutsTitle.edgeless": "Edgeless",
14121413
"com.affine.shortcutsTitle.general": "General",
14131414
"com.affine.shortcutsTitle.markdownSyntax": "Markdown syntax",

tests/affine-cloud/e2e/share-page.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ test('share page with default edgeless', async ({ page, browser }) => {
111111
expect(page2.locator('affine-paragraph').first()).toContainText(
112112
'TEST CONTENT'
113113
);
114-
const editButton = page2.getByTestId('share-page-edit-button');
115-
await expect(editButton).not.toBeVisible();
116114
}
117115
});
118116

0 commit comments

Comments
 (0)