-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* open PDF viewer above the chat webview --------- Co-authored-by: gabriellsh <gabriel.henriques@rocket.chat> Co-authored-by: Tasso Evangelista <tasso.evangelista@rocket.chat>
- Loading branch information
1 parent
11e89ae
commit d64e820
Showing
19 changed files
with
234 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { handle } from '../ipc/main'; | ||
import { SERVER_DOCUMENT_VIEWER_OPEN_URL } from '../servers/actions'; | ||
import { dispatch, select } from '../store'; | ||
|
||
export const startDocumentViewerHandler = (): void => { | ||
handle( | ||
'document-viewer/open-window', | ||
async (event, url, _format, _options) => { | ||
const validUrl = new URL(url); | ||
const allowedProtocols = ['http:', 'https:']; | ||
if (!allowedProtocols.includes(validUrl.protocol)) { | ||
return; | ||
} | ||
const server = select(({ servers }) => | ||
servers.find( | ||
(s) => new URL(s.url).origin === new URL(event.getURL()).origin | ||
) | ||
); | ||
if (!server) { | ||
return; | ||
} | ||
|
||
dispatch({ | ||
type: SERVER_DOCUMENT_VIEWER_OPEN_URL, | ||
payload: { server: server.url, documentUrl: url }, | ||
}); | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ipcRenderer } from 'electron'; | ||
|
||
export const openDocumentViewer = ( | ||
url: string, | ||
format: string, | ||
options: any | ||
): void => { | ||
ipcRenderer.invoke('document-viewer/open-window', url, format, options); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { dispatch } from '../../store'; | ||
import { WEBVIEW_USER_THEME_APPEARANCE_CHANGED } from '../../ui/actions'; | ||
import type { Server } from '../common'; | ||
import { getServerUrl } from './urls'; | ||
|
||
export const setUserThemeAppearance = ( | ||
themeAppearance: Server['themeAppearance'] | ||
): void => { | ||
dispatch({ | ||
type: WEBVIEW_USER_THEME_APPEARANCE_CHANGED, | ||
payload: { | ||
url: getServerUrl(), | ||
themeAppearance, | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Box, IconButton } from '@rocket.chat/fuselage'; | ||
import { useDarkMode } from '@rocket.chat/fuselage-hooks'; | ||
|
||
const DocumentViewer = ({ | ||
url, | ||
partition, | ||
closeDocumentViewer, | ||
themeAppearance, | ||
}: { | ||
url: string; | ||
partition: string; | ||
themeAppearance: string | undefined; | ||
closeDocumentViewer: () => void; | ||
}) => { | ||
const theme = useDarkMode( | ||
themeAppearance === 'auto' ? undefined : themeAppearance === 'dark' | ||
) | ||
? 'dark' | ||
: 'light'; | ||
return ( | ||
<> | ||
<Box | ||
bg={theme} | ||
width='100%' | ||
height='100%' | ||
position='absolute' | ||
content='center' | ||
alignItems='center' | ||
> | ||
<Box | ||
content='center' | ||
alignItems='center' | ||
display='flex' | ||
color={theme === 'dark' ? 'font-white' : 'font-text'} | ||
> | ||
<IconButton | ||
icon='arrow-back' | ||
onClick={closeDocumentViewer} | ||
mi='x8' | ||
color={theme === 'dark' ? 'white' : 'default'} | ||
/> | ||
<h2>PDF Viewer</h2> | ||
</Box> | ||
|
||
<Box> | ||
<webview | ||
src={url} | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
position: 'absolute', | ||
left: 0, | ||
top: 50, | ||
right: 0, | ||
bottom: 0, | ||
}} | ||
partition={partition} | ||
/> | ||
</Box> | ||
</Box> | ||
</> | ||
); | ||
}; | ||
|
||
export default DocumentViewer; |
Oops, something went wrong.