mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-20 10:19:08 +00:00
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import React, { useEffect, useRef } from 'react';
|
|
import * as Backbone from 'backbone';
|
|
|
|
type InboxViewType = Backbone.View & {
|
|
onEmpty?: () => void;
|
|
};
|
|
|
|
type InboxViewOptionsType = Backbone.ViewOptions & {
|
|
initialLoadComplete: boolean;
|
|
window: typeof window;
|
|
};
|
|
|
|
export type PropsType = {
|
|
hasInitialLoadCompleted: boolean;
|
|
};
|
|
|
|
export const Inbox = ({ hasInitialLoadCompleted }: PropsType): JSX.Element => {
|
|
const hostRef = useRef<HTMLDivElement | null>(null);
|
|
const viewRef = useRef<InboxViewType | undefined>(undefined);
|
|
|
|
useEffect(() => {
|
|
const viewOptions: InboxViewOptionsType = {
|
|
el: hostRef.current,
|
|
initialLoadComplete: false,
|
|
window,
|
|
};
|
|
const view = new window.Whisper.InboxView(viewOptions);
|
|
|
|
viewRef.current = view;
|
|
|
|
return () => {
|
|
if (!viewRef || !viewRef.current) {
|
|
return;
|
|
}
|
|
|
|
viewRef.current.remove();
|
|
viewRef.current = undefined;
|
|
};
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (hasInitialLoadCompleted && viewRef.current && viewRef.current.onEmpty) {
|
|
viewRef.current.onEmpty();
|
|
}
|
|
}, [hasInitialLoadCompleted, viewRef]);
|
|
|
|
return <div className="inbox index" ref={hostRef} />;
|
|
};
|