Skip to content

Commit

Permalink
[#70073] disable diff view button when diff is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Trzcin authored and mgielda committed Dec 12, 2024
1 parent f48f267 commit c34c81d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/components/ButtonGroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const RadioButton = styled(DefaultButton)`
border-left: none;
border-radius: 0;
&:hover {
&:hover:not(&:disabled) {
background-color: var(--icon-main-selected);
}
Expand All @@ -40,9 +40,11 @@ const ButtonGroup = ({ buttons, clickedId }) => {
<RadioButton
className="icon radio-icon"
type="button"
disabled={button.disabled}
key={button.id}
name={button.id}
onClick={() => button.action()}
onMouseOver={() => button.hover?.()}
title={button.tooltip}
active={i === clickedId}
>
Expand Down
4 changes: 4 additions & 0 deletions src/components/Buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const DefaultButton = styled.button`
outline: 0 !important;
}
&:disabled {
cursor: default;
}
cursor: pointer;
color: var(--icon-color);
text-transform: uppercase;
Expand Down
14 changes: 11 additions & 3 deletions src/components/Topbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ButtonGroup from "./ButtonGroup";
import Avatars from "./Avatars";
import TemplateManager from "./TemplateManager";
import { MystState } from "../mystState";
import { useComputed } from "@preact/signals";
import { useComputed, useSignal } from "@preact/signals";

const renderMdLinks = (title) =>
[...(title || "").matchAll(/\[(.+)\]\(([^\s]+)\)/g)].reduce(
Expand Down Expand Up @@ -200,14 +200,22 @@ const icons = {
};

export const EditorTopbar = ({ alert, users, text, buttons }) => {
const { options } = useContext(MystState);
const { options, editorView } = useContext(MystState);
const titleHtml = useComputed(() => purify.sanitize(renderMdLinks(options.title.value)));
const emptyDiff = useSignal(false);
const editorModeButtons = useComputed(() => {
const modeButtons = [
{ id: "source", tooltip: "Source", action: () => (options.mode.value = "Source"), icon: SourceIcon },
{ id: "preview", tooltip: "Preview", action: () => (options.mode.value = "Preview"), icon: PreviewIcon },
{ id: "both", tooltip: "Dual Pane", action: () => (options.mode.value = "Both"), icon: BothIcon },
{ id: "diff", tooltip: "Diff View", action: () => (options.mode.value = "Diff"), icon: DiffIcon },
{
id: "diff",
tooltip: emptyDiff.value ? "No changes to show" : "Diff View",
disabled: emptyDiff.value,
action: () => (options.mode.value = "Diff"),
hover: () => (emptyDiff.value = options.initialText == editorView.value?.state?.doc?.toString?.()),
icon: DiffIcon,
},
];
if (options.collaboration.value.resolvingCommentsEnabled) {
modeButtons.push({ id: "resolved", tooltip: "Resolved Comments", action: () => (options.mode.value = "Resolved"), icon: ResolvedIcon });
Expand Down

0 comments on commit c34c81d

Please sign in to comment.