mirror of
https://github.com/outline/outline.git
synced 2026-11-28 08:14:58 +03:00
fix: Collection overview edit state (#11586)
This commit is contained in:
1 parent
03e322f1ad
commit
6b98da54bd
2 files changed
+37
-5
No files matched your search
@@ -3,7 +3,9 @@ import breakpoint from "styled-components-breakpoint";
|
||||
import first from "lodash/first";
|
||||
import { Suspense, useCallback } from "react";
|
||||
import styled from "styled-components";
|
||||
import { CollectionValidation } from "@shared/validations";
|
||||
import Heading from "~/components/Heading";
|
||||
import ContentEditable from "~/components/ContentEditable";
|
||||
import CollectionIcon from "~/components/Icons/CollectionIcon";
|
||||
import type Collection from "~/models/Collection";
|
||||
import { colorPalette } from "@shared/utils/collections";
|
||||
@@ -16,16 +18,32 @@ const IconPicker = lazyWithRetry(() => import("~/components/IconPicker"));
|
||||
type Props = {
|
||||
/** The collection for which to render a header */
|
||||
collection: Collection;
|
||||
/** Whether the header is in editing mode */
|
||||
isEditing?: boolean;
|
||||
};
|
||||
|
||||
export const Header = observer(function Header_({ collection }: Props) {
|
||||
export const Header = observer(function Header_({
|
||||
collection,
|
||||
isEditing,
|
||||
}: Props) {
|
||||
const can = usePolicy(collection);
|
||||
const canEdit = can.update && isEditing;
|
||||
const handleIconChange = useCallback(
|
||||
(icon: string | null, color: string | null) =>
|
||||
collection?.save({ icon, color }),
|
||||
[collection]
|
||||
);
|
||||
|
||||
const handleTitleChange = useCallback(
|
||||
(text: string) => {
|
||||
const trimmed = text.trim();
|
||||
if (trimmed.length > 0 && trimmed !== collection.name) {
|
||||
void collection.save({ name: trimmed });
|
||||
}
|
||||
},
|
||||
[collection]
|
||||
);
|
||||
|
||||
const fallbackIcon = collection ? (
|
||||
<CollectionIcon collection={collection} size={40} expanded />
|
||||
) : null;
|
||||
@@ -33,7 +51,7 @@ export const Header = observer(function Header_({ collection }: Props) {
|
||||
return (
|
||||
<StyledHeading>
|
||||
<IconTitleWrapper>
|
||||
{can.update ? (
|
||||
{canEdit ? (
|
||||
<Suspense fallback={fallbackIcon}>
|
||||
<IconPicker
|
||||
icon={collection.icon ?? "collection"}
|
||||
@@ -51,7 +69,16 @@ export const Header = observer(function Header_({ collection }: Props) {
|
||||
fallbackIcon
|
||||
)}
|
||||
</IconTitleWrapper>
|
||||
{collection.name}
|
||||
{canEdit ? (
|
||||
<ContentEditable
|
||||
value={collection.name}
|
||||
onChange={handleTitleChange}
|
||||
maxLength={CollectionValidation.maxNameLength}
|
||||
dir="auto"
|
||||
/>
|
||||
) : (
|
||||
collection.name
|
||||
)}
|
||||
</StyledHeading>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -176,7 +176,10 @@ const CollectionScene = observer(function CollectionScene_() {
|
||||
>
|
||||
<CenteredContent withStickyHeader>
|
||||
<Notices collection={collection} />
|
||||
<Header collection={collection} />
|
||||
<Header
|
||||
collection={collection}
|
||||
isEditing={isEditRoute && !!user?.separateEditMode}
|
||||
/>
|
||||
|
||||
<PinnedDocuments
|
||||
pins={pins}
|
||||
@@ -209,7 +212,9 @@ const CollectionScene = observer(function CollectionScene_() {
|
||||
{showOverview ? (
|
||||
<Overview
|
||||
collection={collection}
|
||||
readOnly={!isEditRoute && !!user?.separateEditMode}
|
||||
readOnly={
|
||||
!can.update || (!isEditRoute && !!user?.separateEditMode)
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<Redirect
|
||||
|
||||
Reference in new issue
Block a user