Skip to content

Commit 5ad72eb

Browse files
committed
Make knip happy
1 parent ab4685b commit 5ad72eb

12 files changed

Lines changed: 329 additions & 96 deletions

File tree

apps/web/src/components/views/elements/EffectsOverlay.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ const EffectsOverlay: FunctionComponent<IProps> = ({ roomWidth }) => {
2727
if (!name) return null;
2828
let effect: ICanvasEffect | null = effectsRef.current.get(name) || null;
2929
if (effect === null) {
30-
const options = CHAT_EFFECTS.find((e) => e.command === name)?.options;
30+
const definition = CHAT_EFFECTS.find((e) => e.command === name)!;
3131
try {
32-
const { default: Effect } = await import(`../../../effects/${name}`);
33-
effect = new Effect(options);
34-
effectsRef.current.set(name, effect!);
32+
effect = await definition.getRenderer();
33+
effectsRef.current.set(name, effect);
3534
} catch (err) {
36-
logger.warn(`Unable to load effect module at '../../../effects/${name}.`, err);
35+
logger.warn(`Unable to run effect module.`, err);
3736
}
3837
}
3938
return effect;

apps/web/src/effects/confetti/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ Copyright 2020 Nordeck IT + Consulting GmbH.
66
77
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
88
Please see LICENSE files in the repository root for full details.
9-
*/
9+
*/
10+
1011
import type ICanvasEffect from "../ICanvasEffect";
1112

12-
export type ConfettiOptions = {
13+
type ConfettiOptions = {
1314
/**
1415
* max confetti count
1516
*/
@@ -54,7 +55,7 @@ export const DefaultOptions: ConfettiOptions = {
5455
export default class Confetti implements ICanvasEffect {
5556
private readonly options: ConfettiOptions;
5657

57-
public constructor(options: { [key: string]: any }) {
58+
public constructor(options: Partial<ConfettiOptions>) {
5859
this.options = { ...DefaultOptions, ...options };
5960
}
6061

apps/web/src/effects/effect.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
77
Please see LICENSE files in the repository root for full details.
88
*/
99

10-
export type Effect<TOptions extends { [key: string]: any }> = {
10+
import type ICanvasEffect from "./ICanvasEffect.ts";
11+
12+
export type Effect = {
1113
/**
1214
* one or more emojis that will trigger this effect
1315
*/
@@ -29,7 +31,7 @@ export type Effect<TOptions extends { [key: string]: any }> = {
2931
*/
3032
fallbackMessage: () => string;
3133
/**
32-
* animation options
34+
* animation options TODO
3335
*/
34-
options: TOptions;
36+
getRenderer(): Promise<ICanvasEffect>;
3537
};

apps/web/src/effects/fireworks/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ Copyright 2020 Nordeck IT + Consulting GmbH.
66
77
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
88
Please see LICENSE files in the repository root for full details.
9-
*/
9+
*/
1010

1111
import type ICanvasEffect from "../ICanvasEffect";
1212

13-
export type FireworksOptions = {
13+
type FireworksOptions = {
1414
/**
1515
* max fireworks count
1616
*/
@@ -55,7 +55,7 @@ export const DefaultOptions: FireworksOptions = {
5555
export default class Fireworks implements ICanvasEffect {
5656
private readonly options: FireworksOptions;
5757

58-
public constructor(options: { [key: string]: any }) {
58+
public constructor(options: Partial<FireworksOptions>) {
5959
this.options = { ...DefaultOptions, ...options };
6060
}
6161

apps/web/src/effects/hearts/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ Copyright 2022 Arseny Uskov
55
66
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
77
Please see LICENSE files in the repository root for full details.
8-
*/
8+
*/
9+
910
import type ICanvasEffect from "../ICanvasEffect";
1011
import { arrayFastClone } from "../../utils/arrays";
1112

12-
export type HeartOptions = {
13+
type HeartOptions = {
1314
/**
1415
* The maximum number of hearts to render at a given time
1516
*/
@@ -51,7 +52,7 @@ const KEY_FRAME_INTERVAL = 15; // 15ms, roughly
5152
export default class Hearts implements ICanvasEffect {
5253
private readonly options: HeartOptions;
5354

54-
public constructor(options: { [key: string]: any }) {
55+
public constructor(options: Partial<HeartOptions>) {
5556
this.options = { ...DefaultOptions, ...options };
5657
}
5758

apps/web/src/effects/index.ts

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,88 +5,101 @@ Copyright 2020 Nordeck IT + Consulting GmbH.
55
66
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
77
Please see LICENSE files in the repository root for full details.
8-
*/
8+
*/
9+
910
import { _t, _td } from "../languageHandler";
10-
import { type ConfettiOptions } from "./confetti";
11-
import { type Effect } from "./effect";
12-
import { type FireworksOptions } from "./fireworks";
13-
import { type RainfallOptions } from "./rainfall";
14-
import { type SnowfallOptions } from "./snowfall";
15-
import { type SpaceInvadersOptions } from "./spaceinvaders";
16-
import { type HeartOptions } from "./hearts";
11+
import { type Effect } from "./effect.ts";
1712

1813
/**
1914
* This configuration defines room effects that can be triggered by custom message types and emojis
2015
*/
21-
export const CHAT_EFFECTS: Array<Effect<{ [key: string]: any }>> = [
16+
export const CHAT_EFFECTS: Array<Effect> = [
2217
{
2318
emojis: ["🎊", "🎉"],
2419
msgType: "nic.custom.confetti",
2520
command: "confetti",
2621
description: () => _td("chat_effects|confetti_description"),
2722
fallbackMessage: () => _t("chat_effects|confetti_message") + " 🎉",
28-
options: {
29-
maxCount: 150,
30-
speed: 3,
31-
frameInterval: 15,
32-
alpha: 1.0,
33-
gradient: false,
23+
getRenderer: async () => {
24+
const { default: Effect } = await import("./confetti/index.ts");
25+
return new Effect({
26+
maxCount: 150,
27+
speed: 3,
28+
frameInterval: 15,
29+
alpha: 1.0,
30+
gradient: false,
31+
});
3432
},
35-
} as Effect<ConfettiOptions>,
33+
},
3634
{
3735
emojis: ["🎆"],
3836
msgType: "nic.custom.fireworks",
3937
command: "fireworks",
4038
description: () => _td("chat_effects|fireworks_description"),
4139
fallbackMessage: () => _t("chat_effects|fireworks_message") + " 🎆",
42-
options: {
43-
maxCount: 500,
44-
gravity: 0.05,
40+
getRenderer: async () => {
41+
const { default: Effect } = await import("./fireworks/index.ts");
42+
return new Effect({
43+
maxCount: 500,
44+
gravity: 0.05,
45+
});
4546
},
46-
} as Effect<FireworksOptions>,
47+
},
4748
{
4849
emojis: ["🌧️", "⛈️", "🌦️"],
4950
msgType: "io.element.effect.rainfall",
5051
command: "rainfall",
5152
description: () => _td("chat_effects|rainfall_description"),
5253
fallbackMessage: () => _t("chat_effects|rainfall_message") + " 🌧️",
53-
options: {
54-
maxCount: 600,
55-
speed: 10,
54+
getRenderer: async () => {
55+
const { default: Effect } = await import("./rainfall/index.ts");
56+
return new Effect({
57+
maxCount: 600,
58+
speed: 10,
59+
});
5660
},
57-
} as Effect<RainfallOptions>,
61+
},
5862
{
5963
emojis: ["❄", "🌨"],
6064
msgType: "io.element.effect.snowfall",
6165
command: "snowfall",
6266
description: () => _td("chat_effects|snowfall_description"),
6367
fallbackMessage: () => _t("chat_effects|snowfall_message") + " ❄",
64-
options: {
65-
maxCount: 200,
66-
gravity: 0.05,
67-
maxDrift: 5,
68+
getRenderer: async () => {
69+
const { default: Effect } = await import("./snowfall/index.ts");
70+
return new Effect({
71+
maxCount: 200,
72+
gravity: 0.05,
73+
maxDrift: 5,
74+
});
6875
},
69-
} as Effect<SnowfallOptions>,
76+
},
7077
{
7178
emojis: ["👾", "🌌"],
7279
msgType: "io.element.effects.space_invaders",
7380
command: "spaceinvaders",
7481
description: () => _td("chat_effects|spaceinvaders_description"),
7582
fallbackMessage: () => _t("chat_effects|spaceinvaders_message") + " 👾",
76-
options: {
77-
maxCount: 50,
78-
gravity: 0.01,
83+
getRenderer: async () => {
84+
const { default: Effect } = await import("./spaceinvaders/index.ts");
85+
return new Effect({
86+
maxCount: 50,
87+
gravity: 0.01,
88+
});
7989
},
80-
} as Effect<SpaceInvadersOptions>,
90+
},
8191
{
8292
emojis: ["💝"],
8393
msgType: "io.element.effect.hearts",
8494
command: "hearts",
8595
description: () => _td("chat_effects|hearts_description"),
8696
fallbackMessage: () => _t("chat_effects|hearts_message") + " 💝",
87-
options: {
88-
maxCount: 120,
89-
gravity: 3.2,
97+
getRenderer: async () => {
98+
const { default: Effect } = await import("./hearts/index.ts");
99+
return new Effect({
100+
maxCount: 120,
101+
gravity: 3.2,
102+
});
90103
},
91-
} as Effect<HeartOptions>,
104+
},
92105
];

apps/web/src/effects/rainfall/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ Copyright 2021 Josias Allestad
55
66
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
77
Please see LICENSE files in the repository root for full details.
8-
*/
8+
*/
9+
910
import type ICanvasEffect from "../ICanvasEffect";
1011
import { arrayFastClone } from "../../utils/arrays";
1112

12-
export type RainfallOptions = {
13+
type RainfallOptions = {
1314
/**
1415
* The maximum number of raindrops to render at a given time
1516
*/
@@ -38,7 +39,7 @@ const KEY_FRAME_INTERVAL = 15;
3839
export default class Rainfall implements ICanvasEffect {
3940
private readonly options: RainfallOptions;
4041

41-
public constructor(options: { [key: string]: any }) {
42+
public constructor(options: Partial<RainfallOptions>) {
4243
this.options = { ...DefaultOptions, ...options };
4344
}
4445

apps/web/src/effects/snowfall/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ Copyright 2020-2023 The Matrix.org Foundation C.I.C.
44
55
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
66
Please see LICENSE files in the repository root for full details.
7-
*/
7+
*/
8+
89
import type ICanvasEffect from "../ICanvasEffect";
910
import { arrayFastClone } from "../../utils/arrays";
1011

11-
export type SnowfallOptions = {
12+
type SnowfallOptions = {
1213
/**
1314
* The maximum number of snowflakes to render at a given time
1415
*/
@@ -43,7 +44,7 @@ const KEY_FRAME_INTERVAL = 15; // 15ms, roughly
4344
export default class Snowfall implements ICanvasEffect {
4445
private readonly options: SnowfallOptions;
4546

46-
public constructor(options: { [key: string]: any }) {
47+
public constructor(options: Partial<SnowfallOptions>) {
4748
this.options = { ...DefaultOptions, ...options };
4849
}
4950

apps/web/src/effects/spaceinvaders/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ Copyright 2021-2023 The Matrix.org Foundation C.I.C.
44
55
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
66
Please see LICENSE files in the repository root for full details.
7-
*/
7+
*/
8+
89
import type ICanvasEffect from "../ICanvasEffect";
910
import { arrayFastClone } from "../../utils/arrays";
1011

11-
export type SpaceInvadersOptions = {
12+
type SpaceInvadersOptions = {
1213
/**
1314
* The maximum number of invaders to render at a given time
1415
*/
@@ -37,7 +38,7 @@ const GLYPH = "👾";
3738
export default class SpaceInvaders implements ICanvasEffect {
3839
private readonly options: SpaceInvadersOptions;
3940

40-
public constructor(options: { [key: string]: any }) {
41+
public constructor(options: Partial<SpaceInvadersOptions>) {
4142
this.options = { ...DefaultOptions, ...options };
4243
}
4344

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"@element-hq/element-web-playwright-common": "catalog:",
3131
"@nx-tools/nx-container": "^7.2.1",
3232
"@nx/jest": "^22.5.0",
33-
"@types/node": "22",
3433
"@playwright/test": "catalog:",
34+
"@types/node": "22",
3535
"cronstrue": "^3.0.0",
3636
"eslint-plugin-matrix-org": "^3.0.0",
3737
"husky": "^9.0.0",
@@ -67,9 +67,9 @@
6767
"jest-fixed-jsdom": "patches/jest-fixed-jsdom.patch",
6868
"jsdom": "patches/jsdom.patch",
6969
"rollup": "patches/rollup.patch",
70-
"knip": "patches/knip.patch",
7170
"postcss-mixins": "patches/postcss-mixins.patch",
72-
"app-builder-lib": "patches/app-builder-lib.patch"
71+
"app-builder-lib": "patches/app-builder-lib.patch",
72+
"knip": "patches/knip.patch"
7373
},
7474
"peerDependencyRules": {
7575
"allowedVersions": {

0 commit comments

Comments
 (0)