-
Notifications
You must be signed in to change notification settings - Fork 684
Expand file tree
/
Copy pathWidgetWindow.tsx
More file actions
86 lines (80 loc) · 3.31 KB
/
WidgetWindow.tsx
File metadata and controls
86 lines (80 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React from 'react';
import { useOnCreate } from 'slap';
import { ModalLayout } from '../../shared/ModalLayout';
import { Services } from '../../service-provider';
import { AlertBox } from '../AlertBox';
import { AlertBoxModule } from '../useAlertBox';
import { useWidgetRoot, WidgetModule } from './useWidget';
// TODO: import other widgets here to avoid merge conflicts
import { GenericGoal, GenericGoalModule } from '../GenericGoal';
import { ChatBox, ChatBoxModule } from '../ChatBox';
// ChatHighlight
// Credits
import { DonationTicker, DonationTickerModule } from '../DonationTicker';
import { EmoteWall, EmoteWallModule } from '../EmoteWall';
import { EventList, EventListModule } from '../EventList';
// MediaShare
// Poll
// SpinWheel
import { SponsorBanner, SponsorBannerModule } from '../SponsorBanner';
// StreamBoss
// TipJar
import { GameWidget, GameWidgetModule } from '../GameWidget';
import { ViewerCount, ViewerCountModule } from '../ViewerCount';
import { CustomWidget, CustomWidgetModule } from '../CustomWidget';
import { GamePulseWidget } from 'components-react/widgets/GamePulse';
import { GamePulseModule } from 'components-react/widgets/game-pulse/useGamePulseWidget';
import { useSubscription } from '../../hooks/useSubscription';
import { useChildWindowParams } from 'components-react/hooks';
import { Streamboss, StreambossModule } from '../StreamBoss';
// define list of Widget components and modules
export const components = {
AlertBox: [AlertBox, AlertBoxModule],
BitGoal: [GenericGoal, GenericGoalModule],
DonationGoal: [GenericGoal, GenericGoalModule],
CharityGoal: [GenericGoal, GenericGoalModule],
FollowerGoal: [GenericGoal, GenericGoalModule],
StarsGoal: [GenericGoal, GenericGoalModule],
SubGoal: [GenericGoal, GenericGoalModule],
SubscriberGoal: [GenericGoal, GenericGoalModule],
SuperchatGoal: [GenericGoal, GenericGoalModule],
ChatBox: [ChatBox, ChatBoxModule],
// ChatHighlight
// Credits
DonationTicker: [DonationTicker, DonationTickerModule],
EmoteWall: [EmoteWall, EmoteWallModule],
EventList: [EventList, EventListModule],
// MediaShare
// Poll
// SpinWheel
SponsorBanner: [SponsorBanner, SponsorBannerModule],
StreamBoss: [Streamboss, StreambossModule],
// TipJar
ViewerCount: [ViewerCount, ViewerCountModule],
GameWidget: [GameWidget, GameWidgetModule],
CustomWidget: [CustomWidget, CustomWidgetModule],
GamePulseWidget: [GamePulseWidget, GamePulseModule],
};
/**
* Renders a widget window by given sourceId from window's query params
*/
export function WidgetWindow() {
const { WidgetsService } = Services;
const { sourceId, widgetType } = useChildWindowParams();
// take the source id and widget's component from the window's params
const { Module, WidgetSettingsComponent } = useOnCreate(() => {
// TODO: index
// @ts-ignore
const [WidgetSettingsComponent, Module] = components[widgetType];
return { sourceId, Module, WidgetSettingsComponent };
});
// initialize the Redux module for the widget
// so all children components can use it via `useWidget()` call
const { reload } = useWidgetRoot(Module as typeof WidgetModule, { sourceId });
useSubscription(WidgetsService.settingsInvalidated, reload);
return (
<ModalLayout bodyStyle={{ padding: '0px' }} hideFooter={true}>
<WidgetSettingsComponent />
</ModalLayout>
);
}