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

[pull] main from outline:main #162

Merged
merged 2 commits into from
Jan 23, 2025
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
48 changes: 23 additions & 25 deletions app/scenes/Document/Shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,33 +217,31 @@ function SharedDocumentScene(props: Props) {
);
}

const SharedDocument = ({
shareId,
response,
}: {
shareId?: string;
response: Response;
}) => {
const { setDocument } = useDocumentContext();

if (!response.document) {
return null;
}
const SharedDocument = observer(
({ shareId, response }: { shareId?: string; response: Response }) => {
const { hasHeadings, setDocument } = useDocumentContext();

const tocPosition = response.team?.tocPosition ?? TOCPosition.Left;
setDocument(response.document);
if (!response.document) {
return null;
}

return (
<Document
abilities={EMPTY_OBJECT}
document={response.document}
sharedTree={response.sharedTree}
shareId={shareId}
tocPosition={tocPosition}
readOnly
/>
);
};
const tocPosition = hasHeadings
? response.team?.tocPosition ?? TOCPosition.Left
: false;
setDocument(response.document);

return (
<Document
abilities={EMPTY_OBJECT}
document={response.document}
sharedTree={response.sharedTree}
shareId={shareId}
tocPosition={tocPosition}
readOnly
/>
);
}
);

const Content = styled(Text)`
color: ${s("textSecondary")};
Expand Down
16 changes: 9 additions & 7 deletions app/scenes/Document/components/Document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type Props = WithTranslation &
revision?: Revision;
readOnly: boolean;
shareId?: string;
tocPosition?: TOCPosition;
tocPosition?: TOCPosition | false;
onCreateLink?: (
params: Properties<Document>,
nested?: boolean
Expand Down Expand Up @@ -438,13 +438,15 @@ class DocumentScene extends React.Component<Props> {
const embedsDisabled =
(team && team.documentEmbeds === false) || document.embedsDisabled;

const showContents =
(ui.tocVisible === true && !document.isTemplate) ||
(isShare && ui.tocVisible !== false);
const tocPos =
tocPosition ??
((team?.getPreference(TeamPreference.TocPosition) as TOCPosition) ||
TOCPosition.Left);
const showContents =
tocPos &&
(isShare
? ui.tocVisible !== false
: !document.isTemplate && ui.tocVisible === true);
const multiplayerEditor =
!document.isArchived && !document.isDeleted && !revision && !isShare;

Expand Down Expand Up @@ -622,7 +624,7 @@ class DocumentScene extends React.Component<Props> {

type MainProps = {
fullWidth: boolean;
tocPosition: TOCPosition;
tocPosition: TOCPosition | false;
};

const Main = styled.div<MainProps>`
Expand Down Expand Up @@ -650,7 +652,7 @@ const Main = styled.div<MainProps>`

type ContentsContainerProps = {
docFullWidth: boolean;
position: TOCPosition;
position: TOCPosition | false;
};

const ContentsContainer = styled.div<ContentsContainerProps>`
Expand All @@ -668,7 +670,7 @@ const ContentsContainer = styled.div<ContentsContainerProps>`
type EditorContainerProps = {
docFullWidth: boolean;
showContents: boolean;
tocPosition: TOCPosition;
tocPosition: TOCPosition | false;
};

const EditorContainer = styled.div<EditorContainerProps>`
Expand Down
15 changes: 11 additions & 4 deletions app/scenes/Document/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function DocumentHeader({
const ref = React.useRef<HTMLDivElement | null>(null);
const size = useComponentSize(ref);
const isMobile = isMobileMedia || size.width < 700;
const isShare = !!shareId;

// We cache this value for as long as the component is mounted so that if you
// apply a template there is still the option to replace it until the user
Expand All @@ -109,8 +110,13 @@ function DocumentHeader({
}, [onSave]);

const handleToggle = React.useCallback(() => {
ui.set({ tocVisible: !ui.tocVisible });
}, [ui]);
// Public shares, by default, show ToC on load.
if (isShare && ui.tocVisible === undefined) {
ui.set({ tocVisible: false });
} else {
ui.set({ tocVisible: !ui.tocVisible });
}
}, [ui, isShare]);

const context = useActionContext({
activeDocumentId: document?.id,
Expand All @@ -120,7 +126,6 @@ function DocumentHeader({
const { isDeleted, isTemplate } = document;
const isTemplateEditable = can.update && isTemplate;
const canToggleEmbeds = team?.documentEmbeds;
const isShare = !!shareId;
const showContents =
(ui.tocVisible === true && !document.isTemplate) ||
(isShare && ui.tocVisible !== false);
Expand Down Expand Up @@ -212,7 +217,9 @@ function DocumentHeader({
hasSidebar={sharedTree && sharedTree.children?.length > 0}
left={
isMobile ? (
<TableOfContentsMenu />
hasHeadings ? (
<TableOfContentsMenu />
) : null
) : (
<PublicBreadcrumb
documentId={document.id}
Expand Down
1 change: 1 addition & 0 deletions server/models/GroupMembership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ class GroupMembership extends ParanoidModel<
},
{
transaction,
hooks: false,
}
);
}
Expand Down