Skip to content

Commit 62d3730

Browse files
author
naiylo
committed
fix build and reduce complexity of composer
1 parent 370df4c commit 62d3730

3 files changed

Lines changed: 19 additions & 20 deletions

File tree

src/components/WidgetWorkbench.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ export function WidgetWorkbench({
2828
const modalClass =
2929
"workbench-modal" + (mode === "addWidget" ? " workbench-modal--wide" : "");
3030

31+
const renderComposer = () => {
32+
if (mode === "addWidget") {
33+
return <AddWidget widgets={widgets} />;
34+
}
35+
if (!currentComposer) return null;
36+
37+
if (!currentComposer.elements?.composer) return null;
38+
return currentComposer.elements.composer({
39+
actions: widgetActions[currentComposer.type],
40+
authorId: selectedAuthorId,
41+
onClose,
42+
});
43+
};
44+
3145
const handleRemoveWidget = async (type: string, registryName?: string) => {
3246
const target = registryName || type;
3347
setRemoveNotice("");
@@ -108,22 +122,7 @@ export function WidgetWorkbench({
108122
)}
109123
</div>
110124

111-
{mode === "addWidget" ? (
112-
<AddWidget widgets={widgets} />
113-
) : currentComposer?.elements?.composer ? (
114-
currentComposer.elements.composer({
115-
actions: widgetActions[currentComposer.type],
116-
authorId: selectedAuthorId,
117-
onClose,
118-
})
119-
) : (currentComposer as any)?.composer ? (
120-
// Legacy widgets might still export composer at the top level.
121-
(currentComposer as any).composer({
122-
actions: widgetActions[currentComposer.type],
123-
authorId: selectedAuthorId,
124-
onClose,
125-
})
126-
) : null}
125+
{renderComposer()}
127126
</div>
128127
</div>
129128
);

src/exampleWidgets/examplepoll.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ function PollView({
211211

212212
const options = message.custom.options;
213213
const votes = allMessages.filter(
214-
(m) =>
214+
(m): m is Message & { custom: VoteCustom } =>
215215
m.type === "vote" &&
216216
isVoteCustom(m.custom) &&
217217
m.custom.pollId === message.id
@@ -241,7 +241,7 @@ function PollView({
241241
<div className="poll-options">
242242
{options.map((option) => {
243243
const optionVotes = votes.filter(
244-
(v) => (v.custom as VoteCustom).optionId === option.id
244+
(v) => v.custom.optionId === option.id
245245
);
246246
const percent = totalVotes
247247
? Math.round((optionVotes.length / totalVotes) * 100)

src/widgets/examplepoll.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ function PollView({
211211

212212
const options = message.custom.options;
213213
const votes = allMessages.filter(
214-
(m) =>
214+
(m): m is Message & { custom: VoteCustom } =>
215215
m.type === "vote" &&
216216
isVoteCustom(m.custom) &&
217217
m.custom.pollId === message.id
@@ -241,7 +241,7 @@ function PollView({
241241
<div className="poll-options">
242242
{options.map((option) => {
243243
const optionVotes = votes.filter(
244-
(v) => (v.custom as VoteCustom).optionId === option.id
244+
(v) => v.custom.optionId === option.id
245245
);
246246
const percent = totalVotes
247247
? Math.round((optionVotes.length / totalVotes) * 100)

0 commit comments

Comments
 (0)