Skip to content

Commit 78ff7ee

Browse files
committed
Refactor to add collapse
1 parent 882b515 commit 78ff7ee

File tree

4 files changed

+130
-105
lines changed

4 files changed

+130
-105
lines changed

app/components-react/root/LiveDock.m.less

-43
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,6 @@
2020
}
2121
}
2222

23-
.live-dock--left {
24-
.live-dock-chevron {
25-
right: 0;
26-
left: auto;
27-
}
28-
}
29-
30-
.live-dock.collapsed {
31-
width: 20px !important;
32-
padding: 0;
33-
34-
.live-dock-chevron {
35-
.center();
36-
37-
border: none;
38-
}
39-
}
40-
41-
.live-dock-resize-bar {
42-
// So we don't block the collapse chevron
43-
top: 20px !important;
44-
}
45-
46-
.live-dock-chevron {
47-
width: 16px;
48-
height: 20px;
49-
position: absolute;
50-
top: 0;
51-
left: 0;
52-
border-bottom: 1px solid var(--border);
53-
cursor: pointer;
54-
55-
i {
56-
.center();
57-
58-
font-size: 12px;
59-
60-
&:global(.icon-right) {
61-
transform: translate(-50%, -50%) rotate(-90deg);
62-
}
63-
}
64-
}
65-
6623
.live-dock-end-stream {
6724
margin-left: 10px;
6825
}

app/components-react/root/LiveDock.tsx

-23
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,6 @@ class LiveDockController {
212212
});
213213
}
214214

215-
setCollapsed(livedockCollapsed: boolean) {
216-
this.store.setState(s => {
217-
s.canAnimate = true;
218-
});
219-
this.windowsService.actions.updateStyleBlockers('main', true);
220-
this.customizationService.actions.setSettings({ livedockCollapsed });
221-
setTimeout(() => {
222-
this.store.setState(s => {
223-
s.canAnimate = false;
224-
});
225-
this.windowsService.actions.updateStyleBlockers('main', false);
226-
}, 300);
227-
}
228-
229215
toggleViewerCount() {
230216
this.customizationService.actions.setHiddenViewerCount(
231217
!this.customizationService.state.hideViewerCount,
@@ -288,16 +274,11 @@ function LiveDock() {
288274
]),
289275
);
290276

291-
const liveDockSize = useRealmObject(Services.CustomizationService.state).livedockSize;
292277
const collapsed = useRealmObject(Services.CustomizationService.state).livedockCollapsed;
293278
const hideViewerCount = useRealmObject(Services.CustomizationService.state).hideViewerCount;
294279
const viewerCount = hideViewerCount ? $t('Viewers Hidden') : currentViewers;
295280

296281
useEffect(() => {
297-
if (streamingStatus === EStreamingState.Starting && collapsed) {
298-
ctrl.setCollapsed(false);
299-
}
300-
301282
const elapsedInterval = window.setInterval(() => {
302283
if (streamingStatus === EStreamingState.Live) {
303284
setElapsedStreamTime(ctrl.getElapsedStreamTime());
@@ -321,10 +302,6 @@ function LiveDock() {
321302
}
322303
}, [visibleChat, isRestreaming, streamingStatus]);
323304

324-
function toggleCollapsed() {
325-
collapsed ? ctrl.setCollapsed(false) : ctrl.setCollapsed(true);
326-
}
327-
328305
// Safe getter/setter prevents getting stuck on the chat
329306
// for an app that was unloaded.
330307
function setChat(key: string) {

app/components-react/windows/Main.m.less

+40
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,46 @@
112112
border-right: 1px solid var(--border);
113113
}
114114

115+
.live-dock-collapsed {
116+
width: 20px;
117+
height: 100%;
118+
padding: 0;
119+
position: relative;
120+
border-left: 1px solid var(--border);
121+
box-sizing: border-box;
122+
123+
.live-dock-collapsed.left {
124+
border-left: none;
125+
border-right: 1px solid var(--border);
126+
}
127+
128+
.live-dock-chevron {
129+
.center();
130+
131+
border: none;
132+
}
133+
}
134+
135+
.live-dock-chevron {
136+
width: 16px;
137+
height: 20px;
138+
position: absolute;
139+
top: 0;
140+
left: 0;
141+
border-bottom: 1px solid var(--border);
142+
cursor: pointer;
143+
144+
i {
145+
.center();
146+
147+
font-size: 12px;
148+
149+
&:global(.icon-right) {
150+
transform: translate(-50%, -50%) rotate(-90deg);
151+
}
152+
}
153+
}
154+
115155
/deep/ .creator-sites-container .s-loader {
116156
.s-loader__bg {
117157
position: unset;

app/components-react/windows/Main.tsx

+90-39
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import ResizeBar from 'components-react/root/ResizeBar';
1919
import antdThemes from 'styles/antd/index';
2020
import { getPlatformService } from 'services/platforms';
2121
import { IModalOptions } from 'services/windows';
22+
import { EStreamingState } from 'services/streaming';
2223
import { TApplicationTheme } from 'services/customization';
2324
import styles from './Main.m.less';
2425
import { StatefulService } from 'services';
@@ -43,6 +44,7 @@ class MainController {
4344
private platformAppsService = Services.PlatformAppsService;
4445
private editorCommandsService = Services.EditorCommandsService;
4546
private sideNavService = Services.SideNavService;
47+
private streamingService = Services.StreamingService;
4648

4749
modalOptions: IModalOptions = {
4850
renderFn: null,
@@ -60,6 +62,7 @@ class MainController {
6062
minDockWidth: 290,
6163
maxDockWidth: 290,
6264
minEditorWidth: 500,
65+
canAnimate: false,
6366
});
6467

6568
get title() {
@@ -82,6 +85,10 @@ class MainController {
8285
return this.sideNavService.state.compactView;
8386
}
8487

88+
get streamingStatus() {
89+
return this.streamingService.state.streamingStatus;
90+
}
91+
8592
theme(bulkLoadFinished: boolean): TApplicationTheme {
8693
if (bulkLoadFinished) {
8794
return this.customizationService.currentTheme;
@@ -114,10 +121,6 @@ class MainController {
114121
);
115122
}
116123

117-
get isDockCollapsed() {
118-
return this.customizationService.state.livedockCollapsed;
119-
}
120-
121124
get leftDock() {
122125
return this.customizationService.state.leftDock;
123126
}
@@ -214,6 +217,20 @@ class MainController {
214217
updateStyleBlockers(val: boolean) {
215218
this.windowsService.actions.updateStyleBlockers('main', val);
216219
}
220+
221+
setCollapsed(livedockCollapsed: boolean) {
222+
this.store.setState(s => {
223+
s.canAnimate = true;
224+
});
225+
this.windowsService.actions.updateStyleBlockers('main', true);
226+
this.customizationService.actions.setSettings({ livedockCollapsed });
227+
setTimeout(() => {
228+
this.store.setState(s => {
229+
s.canAnimate = false;
230+
});
231+
this.windowsService.actions.updateStyleBlockers('main', false);
232+
}, 300);
233+
}
217234
}
218235

219236
export default function MainWithContext(): ReactElement<{}> {
@@ -245,8 +262,6 @@ function Main() {
245262
leftDock,
246263
applicationLoading,
247264
page,
248-
maxDockWidth,
249-
minDockWidth,
250265
hideStyleBlockers,
251266
compactView,
252267
sideNavCollapsed,
@@ -260,8 +275,6 @@ function Main() {
260275
hasLiveDock: ctrl.store.hasLiveDock,
261276
applicationLoading: ctrl.applicationLoading,
262277
page: ctrl.page,
263-
maxDockWidth: ctrl.store.maxDockWidth,
264-
minDockWidth: ctrl.store.minDockWidth,
265278
hideStyleBlockers: ctrl.hideStyleBlockers,
266279
compactView: ctrl.store.compactView,
267280
sideNavCollapsed: ctrl.sideNavCollapsed,
@@ -270,6 +283,7 @@ function Main() {
270283
);
271284

272285
const dockWidth = useRealmObject(Services.CustomizationService.state).livedockSize;
286+
const isDockCollapsed = useRealmObject(Services.CustomizationService.state).livedockCollapsed;
273287

274288
function windowSizeHandler() {
275289
if (!hideStyleBlockers) {
@@ -350,6 +364,7 @@ function Main() {
350364
}> = (appPages as Dictionary<React.FunctionComponent>)[page];
351365

352366
const sideBarSize = sideNavCollapsed ? 70 : 220;
367+
const liveDockSize = isDockCollapsed ? 20 : dockWidth;
353368

354369
return (
355370
<div
@@ -371,24 +386,10 @@ function Main() {
371386
<SideNav />
372387
</div>
373388
)}
374-
{renderDock && leftDock && (
375-
<ResizeBar
376-
position="left"
377-
onInput={(val: number) => ctrl.setLiveDockWidth(val)}
378-
max={maxDockWidth}
379-
min={minDockWidth}
380-
value={dockWidth}
381-
transformScale={1}
382-
>
383-
<div className={styles.liveDockContainer} style={{ width: dockWidth }}>
384-
<LiveDock />
385-
</div>
386-
</ResizeBar>
387-
)}
388-
389+
{leftDock && <LiveDockContainer onLeft />}
389390
<div
390391
className={cx(styles.mainMiddle, { [styles.mainMiddleCompact]: compactView })}
391-
style={{ width: `calc(100% - ${dockWidth + sideBarSize}px)` }}
392+
style={{ width: `calc(100% - ${liveDockSize + sideBarSize}px)` }}
392393
ref={mainMiddleEl}
393394
>
394395
{!showLoadingSpinner && (
@@ -405,21 +406,7 @@ function Main() {
405406
</div>
406407
)}
407408
</div>
408-
409-
{renderDock && !leftDock && (
410-
<ResizeBar
411-
position="right"
412-
onInput={(val: number) => ctrl.setLiveDockWidth(val)}
413-
max={maxDockWidth}
414-
min={minDockWidth}
415-
value={dockWidth}
416-
transformScale={1}
417-
>
418-
<div className={styles.liveDockContainer} style={{ width: `${dockWidth}px` }}>
419-
<LiveDock />
420-
</div>
421-
</ResizeBar>
422-
)}
409+
{!leftDock && <LiveDockContainer />}
423410
</div>
424411
<ModalWrapper renderFn={ctrl.modalOptions.renderFn} />
425412
<Animation transitionName="ant-fade">
@@ -432,3 +419,67 @@ function Main() {
432419
</div>
433420
);
434421
}
422+
423+
function LiveDockContainer(p: { onLeft?: boolean }) {
424+
const ctrl = useController(MainCtx);
425+
426+
const { maxDockWidth, minDockWidth, renderDock, streamingStatus } = useVuex(
427+
() => ({
428+
maxDockWidth: ctrl.store.maxDockWidth,
429+
minDockWidth: ctrl.store.minDockWidth,
430+
renderDock: ctrl.renderDock,
431+
streamingStatus: ctrl.streamingStatus,
432+
}),
433+
true,
434+
);
435+
436+
useEffect(() => {
437+
if (streamingStatus === EStreamingState.Starting && isDockCollapsed) {
438+
ctrl.setCollapsed(false);
439+
}
440+
}, [streamingStatus]);
441+
442+
const dockWidth = useRealmObject(Services.CustomizationService.state).livedockSize;
443+
const isDockCollapsed = useRealmObject(Services.CustomizationService.state).livedockCollapsed;
444+
445+
function Chevron() {
446+
return (
447+
<div className={styles.liveDockChevron} onClick={() => ctrl.setCollapsed(!isDockCollapsed)}>
448+
<i
449+
className={cx({
450+
[styles.chevronCollapsed]: isDockCollapsed,
451+
'icon-back': (!p.onLeft && isDockCollapsed) || (p.onLeft && !isDockCollapsed),
452+
['icon-down icon-right']:
453+
(p.onLeft && isDockCollapsed) || (!p.onLeft && !isDockCollapsed),
454+
})}
455+
/>
456+
</div>
457+
);
458+
}
459+
460+
if (!renderDock) return <></>;
461+
462+
if (isDockCollapsed) {
463+
return (
464+
<div className={styles.liveDockCollapsed}>
465+
<Chevron />
466+
</div>
467+
);
468+
}
469+
470+
return (
471+
<ResizeBar
472+
position={p.onLeft ? 'left' : 'right'}
473+
onInput={(val: number) => ctrl.setLiveDockWidth(val)}
474+
max={maxDockWidth}
475+
min={minDockWidth}
476+
value={dockWidth}
477+
transformScale={1}
478+
>
479+
<div className={styles.liveDockContainer} style={{ width: `${dockWidth}px` }}>
480+
<LiveDock />
481+
<Chevron />
482+
</div>
483+
</ResizeBar>
484+
);
485+
}

0 commit comments

Comments
 (0)