Skip to content

Commit

Permalink
Feat: add my message component (#8)
Browse files Browse the repository at this point in the history
* base message

* basic messages added

* Image attachments added

* attachments are in

* all media is in one file

* fix compile issue

* css properties patch

* Image Thumb is in use

* tests pass

* File Thumb

* read receipts are documented
  • Loading branch information
alamorre authored Nov 8, 2021
1 parent 112b351 commit c5ee8f7
Show file tree
Hide file tree
Showing 28 changed files with 830 additions and 334 deletions.
251 changes: 52 additions & 199 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@
"typescript": "^4.4.4"
},
"dependencies": {
"html-to-text": "^8.0.0"
"react-grid-system": "^7.3.1"
}
}
6 changes: 3 additions & 3 deletions scripts/new.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

mkdir ./src/$1

echo "" > ./src/$1/index.tsx
echo "" > ./src/$1/props.tsx
echo "import React from 'react';import { Props } from './props';export const index: React.FC<Props> = ({}) => {return <div />;};" > ./src/$1/index.tsx
echo "export interface Props {}" > ./src/$1/props.tsx
echo "" > ./src/$1/stories.tsx
echo "" > ./src/$1/styles.tsx
echo "import { Properties } from 'csstype';export const styles = {example: {} as Properties,};" > ./src/$1/styles.tsx
echo "" > ./src/$1/.test.tsx
11 changes: 11 additions & 0 deletions src/ChatFeed/FileThumb/.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import * as ReactDOM from 'react-dom';
import { Default as Thing } from './stories';

describe('Thing', () => {
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Thing />, div);
ReactDOM.unmountComponentAtNode(div);
});
});
46 changes: 46 additions & 0 deletions src/ChatFeed/FileThumb/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, { useState } from 'react';

import { getFileName } from '../../util/file';

import { Props } from './props';
import { styles } from './styles';

export const FileThumb: React.FC<Props> = ({
attachment,
isLoading = false,
children = 'Loading...',
style = {},
loadingStyle = {},
}) => {
const [hovered, setHovered] = useState<boolean>(false);

const fileStyle = {
...styles.fileView,
...{
color: hovered ? '#1890ff' : '#434343',
border: hovered ? '1px solid #1890ff' : '1px solid #434343',
},
};

if (isLoading || !attachment) {
return (
<div style={{ ...styles.loadingContainer, ...loadingStyle }}>
{children}
</div>
);
}

return (
<div
style={{
...fileStyle,
...style,
}}
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
onClick={() => window.open(attachment.file)}
>
{getFileName(attachment.file)}
</div>
);
};
13 changes: 13 additions & 0 deletions src/ChatFeed/FileThumb/props.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ReactNode } from 'react';

import { Properties } from 'csstype';

import { AttachmentProps } from '../../util/interfaces';

export interface Props {
attachment?: AttachmentProps;
isLoading?: boolean;
children?: ReactNode;
style?: Properties;
loadingStyle?: Properties;
}
29 changes: 29 additions & 0 deletions src/ChatFeed/FileThumb/stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';

import { Meta, Story } from '@storybook/react';

import { FileThumb } from '.';

import { Props } from './props';

import { fileAttachment } from '../../util/mocks';

const meta: Meta = {
title: 'ChatFeed/FileThumb',
component: FileThumb,
argTypes: {},
};

export default meta;

const Template: Story<Props> = (props) => <FileThumb {...props}></FileThumb>;

export const Default = Template.bind({});
Default.args = {
attachment: fileAttachment,
};

export const Loading = Template.bind({});
Loading.args = {
isLoading: true,
};
28 changes: 28 additions & 0 deletions src/ChatFeed/FileThumb/styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Properties } from 'csstype';

export const styles = {
fileView: {
fontFamily: 'Avenir',
padding: '12px',
borderRadius: '14px',
display: 'inline-block',
marginBottom: '4px',
marginRight: '2px',
cursor: 'pointer',
transition: 'all .33s ease',
WebkitTransition: 'all .33s ease',
MozTransition: 'all .33s ease',
} as Properties,
loadingContainer: {
fontFamily: 'Avenir',
color: 'white',
padding: '14px',
display: 'inline-block',
borderRadius: '14px',
marginRight: '2px',
width: '136px',
marginBottom: '4px',
marginLeft: '4px',
backgroundColor: '#d9d9d9',
} as Properties,
};
11 changes: 11 additions & 0 deletions src/ChatFeed/ImageThumb/.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import * as ReactDOM from 'react-dom';
import { Default as Thing } from './stories';

describe('Thing', () => {
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Thing />, div);
ReactDOM.unmountComponentAtNode(div);
});
});
41 changes: 41 additions & 0 deletions src/ChatFeed/ImageThumb/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { useState } from 'react';

import { Props } from './props';
import { styles } from './styles';

export const ImageThumb: React.FC<Props> = ({
attachment,
isLoading = false,
children = 'Loading...',
style = {},
loadingStyle = {},
}) => {
const [hovered, setHovered] = useState<boolean>(false);

const thumbnailStyle = {
...styles.thumbnail,
...{ border: hovered ? '1px solid #1890ff' : '1px solid #fff' },
};

if (isLoading || !attachment) {
return (
<div style={{ ...styles.loadingContainer, ...loadingStyle }}>
{children}
</div>
);
}

return (
<img
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
src={attachment.file}
alt={'thumb-nail'}
style={{
...thumbnailStyle,
...style,
}}
onClick={() => window.open(attachment.file)}
/>
);
};
13 changes: 13 additions & 0 deletions src/ChatFeed/ImageThumb/props.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ReactNode } from 'react';

import { Properties } from 'csstype';

import { AttachmentProps } from '../../util/interfaces';

export interface Props {
attachment?: AttachmentProps;
isLoading?: boolean;
children?: ReactNode;
style?: Properties;
loadingStyle?: Properties;
}
29 changes: 29 additions & 0 deletions src/ChatFeed/ImageThumb/stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';

import { Meta, Story } from '@storybook/react';

import { ImageThumb } from '.';

import { Props } from './props';

import { imageAttachment } from '../../util/mocks';

const meta: Meta = {
title: 'ChatFeed/ImageThumb',
component: ImageThumb,
argTypes: {},
};

export default meta;

const Template: Story<Props> = (props) => <ImageThumb {...props}></ImageThumb>;

export const Default = Template.bind({});
Default.args = {
attachment: imageAttachment,
};

export const Loading = Template.bind({});
Loading.args = {
isLoading: true,
};
41 changes: 41 additions & 0 deletions src/ChatFeed/ImageThumb/styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Properties } from 'csstype';

export const styles = {
thumbnail: {
cursor: 'pointer',
textAlign: 'right',
display: 'inline',
objectFit: 'cover',
borderRadius: '0.3em',
padding: '2px',
// Size
height: '30vw',
width: '30vw',
maxHeight: '200px',
maxWidth: '200px',
minHeight: '100px',
minWidth: '100px',
transition: 'all .33s ease',
WebkitTransition: 'all .33s ease',
MozTransition: 'all .33s ease',
} as Properties,
loadingContainer: {
fontFamily: 'Avenir',
color: 'white',
cursor: 'pointer',
textAlign: 'right',
display: 'inline-block',
objectFit: 'cover',
borderRadius: '0.3em',
padding: '2px',
marginRight: '2px',
marginBottom: '4px',
height: '30vw',
width: '30vw',
maxHeight: '200px',
maxWidth: '200px',
minHeight: '100px',
minWidth: '100px',
backgroundColor: '#d9d9d9',
} as Properties,
};
13 changes: 13 additions & 0 deletions src/ChatFeed/MyMessage/.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import * as ReactDOM from 'react-dom';
import { Default as Thing } from './stories';

import { message } from '../../util/mocks';

describe('Thing', () => {
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Thing message={message} />, div);
ReactDOM.unmountComponentAtNode(div);
});
});
Loading

0 comments on commit c5ee8f7

Please sign in to comment.