Skip to content

Commit

Permalink
Add FilePreviewOverride component (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickmister authored Jun 16, 2020
1 parent e388f82 commit 0b4e57e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions webapp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ This plugin registers a file upload action that, when clicked, triggers the root
This plugin registers a link tooltip component, whose content is fully customizable. It is displayed when the mouse cursor hovers over a link in a post.
![link tooltip](docs/link_tooltip.png)

## File Preview Override

This plugin registers a file preview component, which is rendered when the user clicks on a post's file attachment. You can apply any logic necessary to determine whether or not the preview should be overridden. In the case of this plugin's implementation, the file must have the extension `demo`.
![file preview override](docs/file_preview_override.png)

## Right-Hand Sidebar

This plugin registers a right-hand sidebar component, whose content is fully customizable and it is triggered by calling an action where required. In this demo plugin, it is triggered by the Channel Header Action Button.
Expand Down
Binary file added webapp/docs/file_preview_override.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';

import {FileInfo} from 'mattermost-redux/types/files';
import {Theme} from 'mattermost-redux/types/preferences';

type Props = {
fileInfo: FileInfo;
onModalDismissed: () => void;
theme: Theme;
};

export default function FilePreviewOverride(props: Props) {
const {theme} = props;

const style = {
backgroundColor: theme.centerChannelBg,
color: theme.centerChannelColor,
paddingTop: '10px',
paddingBottom: '10px',
};

const buttonStyle = {
backgroundColor: theme.buttonBg,
color: theme.buttonColor,
};

return (
<div style={style}>
<h3>{props.fileInfo.name}</h3>
<button
className={'save-button btn'}
style={buttonStyle}
onClick={props.onModalDismissed}
>
{'Close'}
</button>
</div>
);
}
12 changes: 12 additions & 0 deletions webapp/src/components/file_preview_override/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {connect} from 'react-redux';

import {GlobalState} from 'mattermost-redux/types/store';
import {getTheme} from 'mattermost-redux/selectors/entities/preferences';

import FilePreviewOverride from './file_preview_override';

const mapStateToProps = (state: GlobalState) => ({
theme: getTheme(state),
});

export default connect(mapStateToProps)(FilePreviewOverride);
3 changes: 3 additions & 0 deletions webapp/src/plugin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import UserActions from './components/user_actions';
import RHSView from './components/right_hand_sidebar';
import SecretMessageSetting from './components/admin_settings/secret_message_setting';
import CustomSetting from './components/admin_settings/custom_setting';
import FilePreviewOverride from './components/file_preview_override';

import PostType from './components/post_type';
import EphemeralPostType from './components/ephemeral_post_type';
Expand Down Expand Up @@ -192,6 +193,8 @@ export default class DemoPlugin {
registry.registerAdminConsoleCustomSetting('SecretMessage', SecretMessageSetting, {showTitle: true});
registry.registerAdminConsoleCustomSetting('CustomSetting', CustomSetting);

registry.registerFilePreviewComponent((fileInfo) => fileInfo.extension === 'demo', FilePreviewOverride);

registry.registerReducer(reducer);

// Immediately fetch the current plugin status.
Expand Down

0 comments on commit 0b4e57e

Please sign in to comment.