Initial commit
This commit is contained in:
commit
6b48ea42c4
55 changed files with 29418 additions and 0 deletions
README.mdconfig-overrides.jspackage-lock.jsonpackage.json
public
src
animations
components
app
chat-log
compose
header
responsive-canvas
sidebar
hooks
index.jsindex.style.jslogo.svgsetupTests.js
70
README.md
Normal file
70
README.md
Normal file
|
@ -0,0 +1,70 @@
|
|||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
|
||||
|
||||
The page will reload when you make changes.\
|
||||
You may also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
|
||||
|
||||
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
|
||||
|
||||
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
||||
|
||||
### `npm run build` fails to minify
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
12
config-overrides.js
Normal file
12
config-overrides.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
const {
|
||||
override,
|
||||
addWebpackAlias,
|
||||
} = require("customize-cra");
|
||||
const path = require("path");
|
||||
|
||||
module.exports = override(
|
||||
addWebpackAlias({
|
||||
'@': path.resolve(__dirname, 'src/'),
|
||||
'@components': path.resolve(__dirname, 'src/components'),
|
||||
}),
|
||||
);
|
27991
package-lock.json
generated
Normal file
27991
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
44
package.json
Normal file
44
package.json
Normal file
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"name": "chat",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^5.16.1",
|
||||
"@testing-library/react": "^12.1.2",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"canvas-confetti": "^1.5.1",
|
||||
"customize-cra": "^1.0.0",
|
||||
"mfm-js": "^0.22.1",
|
||||
"polished": "^4.1.3",
|
||||
"react": "^17.0.2",
|
||||
"react-app-rewired": "^2.2.1",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-router-dom": "^6.2.1",
|
||||
"react-scripts": "5.0.0",
|
||||
"react-transition-group": "^4.4.2",
|
||||
"styled-components": "^5.3.3"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-app-rewired start",
|
||||
"build": "react-app-rewired build",
|
||||
"test": "react-app-rewired test"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
BIN
public/favicon.ico
Normal file
BIN
public/favicon.ico
Normal file
Binary file not shown.
After Width: 64px | Height: 64px | Size: 3.8 KiB |
25
public/index.html
Normal file
25
public/index.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Chat Mirror for OVTK (according to skeh's preferences)"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,1,0" />
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@48,400,0,0" />
|
||||
<title>OVTK Chat Mirror</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>Needs JavaScript to function. Boooooo</noscript>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
BIN
public/logo192.png
Normal file
BIN
public/logo192.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 5.2 KiB |
BIN
public/logo512.png
Normal file
BIN
public/logo512.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 9.4 KiB |
25
public/manifest.json
Normal file
25
public/manifest.json
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
3
public/robots.txt
Normal file
3
public/robots.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
42
src/animations/useConfetti.js
Normal file
42
src/animations/useConfetti.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { useRef, useCallback, useEffect } from 'react';
|
||||
import confetti from 'canvas-confetti';
|
||||
|
||||
const commonOptions = (tier) => ({
|
||||
ticks: 400,
|
||||
particleCount: 25 * tier,
|
||||
});
|
||||
|
||||
const delay = 1000;
|
||||
|
||||
export default function useZoom(count, tier) {
|
||||
const canvasRef = useRef();
|
||||
|
||||
const doAnimation = useCallback(() => {
|
||||
const confettiCannon = confetti.create(canvasRef.current, { useWorker: true });
|
||||
let remainCount = count;
|
||||
|
||||
const pop = () => {
|
||||
confettiCannon({
|
||||
origin: { x: 0, y: 1 },
|
||||
angle: 45,
|
||||
drift: -0.5,
|
||||
...commonOptions(tier),
|
||||
});
|
||||
confettiCannon({
|
||||
origin: { x: 1, y: 1 },
|
||||
angle: 135,
|
||||
drift: 0.5,
|
||||
...commonOptions(tier),
|
||||
});
|
||||
remainCount -= 1;
|
||||
|
||||
if (remainCount > 0) {
|
||||
setTimeout(pop, Math.max(delay / remainCount, 200));
|
||||
}
|
||||
};
|
||||
|
||||
pop();
|
||||
}, [canvasRef]);
|
||||
|
||||
return [canvasRef, doAnimation];
|
||||
}
|
79
src/animations/useZoom.js
Normal file
79
src/animations/useZoom.js
Normal file
|
@ -0,0 +1,79 @@
|
|||
import { useRef, useCallback, useEffect } from 'react';
|
||||
import XTERM_COLORS from '../xterm';
|
||||
|
||||
const RAIDERS_PER_SECOND = 5;
|
||||
const MAX_SECONDS = 10;
|
||||
const FPS_CAP = 120;
|
||||
const LINE_HEIGHT = 5;
|
||||
const LINE_WIDTH = 700;
|
||||
// Speed is in "seconds to cross card width"
|
||||
const START_SPEED = 0.06;
|
||||
const MIN_SPEED = 0.2;
|
||||
|
||||
export default function useZoom(count) {
|
||||
const canvasRef = useRef();
|
||||
|
||||
const doAnimation = useCallback(() => {
|
||||
const canvas = canvasRef.current;
|
||||
const ctx = canvas.getContext('2d');
|
||||
const height = canvas.height;
|
||||
const width = canvas.width;
|
||||
|
||||
let delay = count / RAIDERS_PER_SECOND;
|
||||
if (delay > MAX_SECONDS) { delay = MAX_SECONDS };
|
||||
const lines = Array(count).fill(null).map(() => ({
|
||||
y: Math.floor(Math.random() * height),
|
||||
x: width + LINE_WIDTH,
|
||||
offset: Math.floor(Math.random() * delay * 1000),
|
||||
speed: width / START_SPEED,
|
||||
decel: Math.random() * (width / (MIN_SPEED - START_SPEED)),
|
||||
color: XTERM_COLORS[118 + Math.floor(Math.random() * 24)],
|
||||
}));
|
||||
|
||||
const fpsInterval = FPS_CAP / 1000;
|
||||
const start = Date.now();
|
||||
let then = Date.now();
|
||||
let now, dt, elapsed;
|
||||
let animationFrameId = requestAnimationFrame(animStep);
|
||||
|
||||
function animStep() {
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
animationFrameId = requestAnimationFrame(animStep);
|
||||
|
||||
let alive = false;
|
||||
now = Date.now();
|
||||
dt = now - then;
|
||||
if (dt < fpsInterval) return;
|
||||
then = now - (dt % fpsInterval);
|
||||
elapsed = now - start;
|
||||
dt = dt / 1000;
|
||||
|
||||
lines.forEach((line, i) => {
|
||||
if (line.x < 0) { return; }
|
||||
alive = true;
|
||||
if (line.offset > elapsed) return;
|
||||
|
||||
const nextX = line.x - (dt * line.speed);
|
||||
ctx.beginPath();
|
||||
ctx.lineWidth = LINE_HEIGHT;
|
||||
ctx.strokeStyle = line.color;
|
||||
ctx.moveTo(line.x, line.y);
|
||||
ctx.lineTo(nextX - LINE_WIDTH, line.y);
|
||||
ctx.stroke();
|
||||
ctx.closePath();
|
||||
|
||||
line.x = nextX;
|
||||
if (line.speed - line.decel > (width / MIN_SPEED)) {
|
||||
line.speed -= line.decel;
|
||||
}
|
||||
});
|
||||
|
||||
if (!alive) {
|
||||
cancelAnimationFrame(animationFrameId);
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
}
|
||||
};
|
||||
}, [canvasRef, count]);
|
||||
|
||||
return [canvasRef, doAnimation];
|
||||
}
|
95
src/components/app/app.jsx
Normal file
95
src/components/app/app.jsx
Normal file
|
@ -0,0 +1,95 @@
|
|||
import { useEffect, useState, useCallback } from 'react';
|
||||
import { useQuery } from '../../hooks';
|
||||
|
||||
import ChatLog from '../chat-log';
|
||||
import Sidebar from '../sidebar';
|
||||
import Compose from '../compose';
|
||||
import Header from '../header';
|
||||
|
||||
import { Wrapper, Main } from './app.style.js';
|
||||
|
||||
const maxsize = 25;
|
||||
|
||||
function App() {
|
||||
const [socket, setSocket] = useState();
|
||||
const [messages, setMessages] = useState(Array(maxsize).fill(null));
|
||||
const [mentionCount, setMentionCount] = useState(0);
|
||||
const [unread, setUnread] = useState(false);
|
||||
const [userPresent, setUserPresent] = useState(false);
|
||||
|
||||
const query = useQuery();
|
||||
const websocketAddress = query.get('ws') ?? 'ws://127.0.0.1:8080';
|
||||
|
||||
const onEvent = useCallback((eventRaw) => {
|
||||
const event = JSON.parse(eventRaw.data);
|
||||
setMessages((state) => {
|
||||
const newState = [...state];
|
||||
newState.unshift(event);
|
||||
newState.pop();
|
||||
return newState;
|
||||
});
|
||||
if (!userPresent) setUnread(true);
|
||||
if (event.type.includes('Message') && event.data.monitization !== null) {
|
||||
setMentionCount((count) => count + 1);
|
||||
}
|
||||
}, [userPresent]);
|
||||
|
||||
useEffect(() => {
|
||||
if (socket) {
|
||||
const onDiscconect = () => setSocket(null);
|
||||
socket.addEventListener('message', onEvent);
|
||||
socket.addEventListener('error', onDiscconect);
|
||||
socket.addEventListener('close', onDiscconect);
|
||||
|
||||
return () => {
|
||||
socket.removeEventListener('message', onEvent);
|
||||
socket.removeEventListener('error', onDiscconect);
|
||||
socket.removeEventListener('close', onDiscconect);
|
||||
};
|
||||
} else {
|
||||
const attemptConnect = () => {
|
||||
try {
|
||||
const ws = new WebSocket(websocketAddress);
|
||||
setSocket(ws);
|
||||
} catch (error) {
|
||||
setTimeout(attemptConnect, 5000);
|
||||
}
|
||||
};
|
||||
attemptConnect();
|
||||
}
|
||||
}, [socket, websocketAddress, onEvent]);
|
||||
|
||||
useEffect(() => {
|
||||
const focus = () => {
|
||||
setUserPresent(true);
|
||||
setUnread(false);
|
||||
};
|
||||
const blur = () => {
|
||||
setUserPresent(false);
|
||||
};
|
||||
|
||||
window.addEventListener("focus", focus);
|
||||
window.addEventListener("blur", blur);
|
||||
return () => {
|
||||
window.removeEventListener("focus", focus);
|
||||
window.removeEventListener("blur", blur);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleOnSend = useCallback((message) => {
|
||||
console.log(message);
|
||||
}, [socket]);
|
||||
|
||||
return (
|
||||
<Wrapper>
|
||||
<Sidebar mentionCount={mentionCount} unread={unread} />
|
||||
<Main>
|
||||
<Header />
|
||||
<ChatLog log={messages} />
|
||||
<Compose onSend={handleOnSend} />
|
||||
</Main>
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
20
src/components/app/app.style.js
Normal file
20
src/components/app/app.style.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
import styled from 'styled-components';
|
||||
|
||||
export const Wrapper = styled.div`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
overflow: hidden;
|
||||
height: 100%;
|
||||
`;
|
||||
|
||||
export const Main = styled.div`
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
:first-child {
|
||||
flex: 1;
|
||||
}
|
||||
padding: 0 20px 20px;
|
||||
`;
|
1
src/components/app/index.js
Normal file
1
src/components/app/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from './app'
|
72
src/components/chat-log/chat-log.jsx
Normal file
72
src/components/chat-log/chat-log.jsx
Normal file
|
@ -0,0 +1,72 @@
|
|||
import { useRef, useLayoutEffect } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import Message from './message';
|
||||
import Raid from './event-card/raid';
|
||||
import Subscription from './event-card/sub';
|
||||
import Follow from './event-card/follow';
|
||||
|
||||
import { List, Spacer } from './chat-log.style';
|
||||
|
||||
const elementMap = {
|
||||
Message,
|
||||
Raid,
|
||||
Follow,
|
||||
Subscription,
|
||||
null: Spacer,
|
||||
};
|
||||
|
||||
const canCollapse = (acc, current) => {
|
||||
if (acc.length > 0) {
|
||||
const last = acc[acc.length - 1];
|
||||
if (current.type.includes('Message') && last.type.includes('Message') && last.data.user_id == current.data.user_id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function ChatLog({
|
||||
log,
|
||||
}) {
|
||||
const listRef = useRef();
|
||||
const renderableEvents = log.reduce((acc, current) => {
|
||||
if (!current?.type) {
|
||||
current = { type: ['null'], data: { }};
|
||||
}
|
||||
if (canCollapse(acc, current)) {
|
||||
const last = JSON.parse(JSON.stringify(acc[acc.length - 1]))
|
||||
last.data.text = current.data.text + '\n' + last.data.text;
|
||||
acc[acc.length - 1] = last;
|
||||
} else {
|
||||
acc.push(current);
|
||||
}
|
||||
return acc;
|
||||
}, []).map((event) => {
|
||||
const bestRenderableInterface = event.type.find((interfaceName) => Object.keys(elementMap).includes(interfaceName));
|
||||
const renderer = elementMap[bestRenderableInterface];
|
||||
return [event, renderer];
|
||||
}).filter(([event, renderer]) => !!renderer)
|
||||
|
||||
useLayoutEffect(() => {
|
||||
listRef.current.scrollTop = -1;
|
||||
}, [renderableEvents]);
|
||||
|
||||
return (
|
||||
<List ref={listRef}>
|
||||
{renderableEvents.map(([event, Element]) => (
|
||||
<Element key={event.data.id} {...event.data} />
|
||||
))}
|
||||
</List>
|
||||
);
|
||||
}
|
||||
|
||||
ChatLog.propTypes = {
|
||||
log: PropTypes.arrayOf(PropTypes.shape({
|
||||
type: PropTypes.arrayOf(PropTypes.string),
|
||||
data: PropTypes.shape({
|
||||
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
}),
|
||||
})).isRequired,
|
||||
};
|
||||
|
||||
export default ChatLog;
|
32
src/components/chat-log/chat-log.style.js
Normal file
32
src/components/chat-log/chat-log.style.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
import styled from 'styled-components';
|
||||
|
||||
export const List = styled.div`
|
||||
flex: 1;
|
||||
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column-reverse;
|
||||
align-items: start;
|
||||
justify-content: end;
|
||||
gap: 16px;
|
||||
|
||||
padding-bottom: 18px;
|
||||
|
||||
overflow: scroll;
|
||||
scroll-behavior: smooth;
|
||||
|
||||
scrollbar-width: none;
|
||||
&::-webkit-scrollbar {
|
||||
width: 0px;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
font-family: 'Noto Sans', sans-serif;
|
||||
font-size: 22px;
|
||||
`;
|
||||
|
||||
export const Spacer = styled.div`
|
||||
min-height: 2em;
|
||||
`;
|
31
src/components/chat-log/event-card/common.styles.js
Normal file
31
src/components/chat-log/event-card/common.styles.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import styled, { css } from 'styled-components';
|
||||
import XTERM_COLORS from '../../../xterm';
|
||||
|
||||
export const Root = styled.div`
|
||||
width: 100%;
|
||||
position: relative;
|
||||
background-color: ${XTERM_COLORS[236]};
|
||||
text-align: center;
|
||||
`;
|
||||
|
||||
export const Foreground = styled.div`
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1;
|
||||
padding: 12px;
|
||||
|
||||
span {
|
||||
text-shadow: 0 0 4px rgba(0, 0, 0, 60%);
|
||||
}
|
||||
`;
|
||||
|
||||
export const Background = styled.div`
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
`;
|
16
src/components/chat-log/event-card/follow/follow.jsx
Normal file
16
src/components/chat-log/event-card/follow/follow.jsx
Normal file
|
@ -0,0 +1,16 @@
|
|||
import React from 'react';
|
||||
|
||||
import { Root, Foreground, Channel } from './follow.style';
|
||||
|
||||
const Follow = ({
|
||||
user_name,
|
||||
}) => (
|
||||
<Root>
|
||||
<Foreground>
|
||||
<Channel>{user_name}</Channel>
|
||||
<span>joins the roost~</span>
|
||||
</Foreground>
|
||||
</Root>
|
||||
);
|
||||
|
||||
export default Follow;
|
|
@ -0,0 +1,8 @@
|
|||
import styled from 'styled-components';
|
||||
import XTERM_COLORS from '@/xterm';
|
||||
|
||||
export { Root, Background, Foreground } from '../common.styles';
|
||||
|
||||
export const Channel = styled.span`
|
||||
color: ${XTERM_COLORS[6]};
|
||||
`;
|
1
src/components/chat-log/event-card/follow/index.js
Normal file
1
src/components/chat-log/event-card/follow/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from './follow';
|
1
src/components/chat-log/event-card/raid/index.js
Normal file
1
src/components/chat-log/event-card/raid/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from './raid';
|
26
src/components/chat-log/event-card/raid/raid.jsx
Normal file
26
src/components/chat-log/event-card/raid/raid.jsx
Normal file
|
@ -0,0 +1,26 @@
|
|||
import React, { useRef, useCallback, useEffect } from 'react';
|
||||
|
||||
import { Root, Foreground, Background, Channel } from './raid.style';
|
||||
import Canvas from '@components/responsive-canvas';
|
||||
|
||||
import useZoom from '@/animations/useZoom';
|
||||
|
||||
const Raid = ({
|
||||
from_channel, user_count,
|
||||
}) => {
|
||||
const [canvasRef, doAnimation] = useZoom(user_count);
|
||||
|
||||
return (
|
||||
<Root>
|
||||
<Foreground>
|
||||
<Channel>{from_channel}</Channel>
|
||||
<span>soars in with their {user_count}-odd flock!</span>
|
||||
</Foreground>
|
||||
<Background>
|
||||
<Canvas ref={canvasRef} onResize={doAnimation} />
|
||||
</Background>
|
||||
</Root>
|
||||
);
|
||||
};
|
||||
|
||||
export default Raid;
|
9
src/components/chat-log/event-card/raid/raid.style.js
Normal file
9
src/components/chat-log/event-card/raid/raid.style.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
import styled from 'styled-components';
|
||||
import XTERM_COLORS from '@/xterm';
|
||||
|
||||
export { Root, Background, Foreground } from '../common.styles';
|
||||
|
||||
export const Channel = styled.span`
|
||||
color: ${XTERM_COLORS[223]};
|
||||
font-size: 28px;
|
||||
`;
|
1
src/components/chat-log/event-card/sub/index.js
Normal file
1
src/components/chat-log/event-card/sub/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from './sub';
|
47
src/components/chat-log/event-card/sub/sub.jsx
Normal file
47
src/components/chat-log/event-card/sub/sub.jsx
Normal file
|
@ -0,0 +1,47 @@
|
|||
import React from 'react';
|
||||
|
||||
import {
|
||||
Root, Foreground, Background,
|
||||
Channel, Streak,
|
||||
} from './sub.style';
|
||||
import Canvas from '@components/responsive-canvas';
|
||||
|
||||
import useConfetti from '@/animations/useConfetti';
|
||||
|
||||
|
||||
const Sub = ({
|
||||
user_name, gifted_to, streak,
|
||||
}) => {
|
||||
const [canvasRef, doAnimation] = useConfetti(gifted_to?.length ?? 1, 1);
|
||||
|
||||
let msg;
|
||||
if (gifted_to?.length) {
|
||||
msg = (
|
||||
<>
|
||||
<Channel>{user_name}</Channel>
|
||||
<span>gifted {gifted_to.length} subscriptions!</span>
|
||||
</>
|
||||
);
|
||||
} else {
|
||||
msg = (
|
||||
<>
|
||||
<Channel>{user_name}</Channel>
|
||||
<span>has subscribed!</span>
|
||||
{streak > 1 ? (
|
||||
<Streak>{streak} times and counting!</Streak>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Root>
|
||||
<Foreground>{msg}</Foreground>
|
||||
<Background>
|
||||
<Canvas ref={canvasRef} onResize={doAnimation} />
|
||||
</Background>
|
||||
</Root>
|
||||
);
|
||||
};
|
||||
|
||||
export default Sub;
|
14
src/components/chat-log/event-card/sub/sub.style.js
Normal file
14
src/components/chat-log/event-card/sub/sub.style.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import styled from 'styled-components';
|
||||
import XTERM_COLORS from '@/xterm';
|
||||
|
||||
export { Root, Background, Foreground } from '../common.styles';
|
||||
|
||||
export const Channel = styled.span`
|
||||
color: ${XTERM_COLORS[6]};
|
||||
font-size: 28px;
|
||||
`;
|
||||
|
||||
export const Streak = styled.span`
|
||||
color: ${XTERM_COLORS[247]};
|
||||
font-size: 16px;
|
||||
`;
|
1
src/components/chat-log/index.js
Normal file
1
src/components/chat-log/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from './chat-log';
|
1
src/components/chat-log/message/index.js
Normal file
1
src/components/chat-log/message/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from './message';
|
103
src/components/chat-log/message/message.jsx
Normal file
103
src/components/chat-log/message/message.jsx
Normal file
|
@ -0,0 +1,103 @@
|
|||
import { useMemo } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { parse as mfmParse, toString as mfmUnparse } from 'mfm-js';
|
||||
|
||||
import XTERM_COLORS from '../../../xterm';
|
||||
|
||||
import { Wrapper, Author, Body, Emote, Attachments } from './message.style';
|
||||
|
||||
import * as mfmElements from './mfm';
|
||||
|
||||
const stringHashcode = (str) => {
|
||||
var hash = 0, i, chr;
|
||||
if (str.length === 0) return hash;
|
||||
for (i = 0; i < str.length; i++) {
|
||||
chr = str.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + chr;
|
||||
hash |= 0; // Convert to 32bit integer
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
const elForType = {
|
||||
image: (src) => <img src={src} />,
|
||||
audio: (src) => <audio src={src} />,
|
||||
video: (src) => <video src={src} />,
|
||||
};
|
||||
|
||||
const renderMfm = (mfmNode, note) => {
|
||||
const ElForNode = mfmElements[mfmNode.type];
|
||||
|
||||
let node;
|
||||
if (!ElForNode) {
|
||||
const text = mfmUnparse(mfmNode);
|
||||
const TextNode = mfmElements.text;
|
||||
node = <TextNode note={note} text={text} />;
|
||||
} else {
|
||||
const children = mfmNode.children?.map((node) => renderMfm(node, note));
|
||||
node = <ElForNode note={note} {...mfmNode.props} children={children} />;
|
||||
}
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
function Message(note) {
|
||||
const {
|
||||
user_id, user_name, user_type, user_color, text, emotes, attachments, deemphasize,
|
||||
} = note;
|
||||
|
||||
const fallbackColor = XTERM_COLORS[(stringHashcode(user_id.toString()) % 144) + 88];
|
||||
const displayFiles = useMemo(() => {
|
||||
if (attachments) {
|
||||
const filtered = attachments
|
||||
.map(([type, url]) => [type.split('/')[0], url])
|
||||
.filter(([type, url]) => Object.keys(elForType).includes(type));
|
||||
return filtered;
|
||||
}
|
||||
return null;
|
||||
}, [attachments]);
|
||||
|
||||
const mfmTree = useMemo(() => mfmParse(text), [text]);
|
||||
const tree = mfmTree.map((node) => renderMfm(node, note));
|
||||
|
||||
return (
|
||||
<Wrapper type={user_type}>
|
||||
<Author>
|
||||
{user_name}
|
||||
</Author>
|
||||
{mfmTree.length !== 0 && (
|
||||
<Body>
|
||||
{tree}
|
||||
</Body>
|
||||
)}
|
||||
{!!displayFiles && (
|
||||
<Attachments>
|
||||
{displayFiles.map(([type, url]) => elForType[type](url))}
|
||||
</Attachments>
|
||||
)}
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
|
||||
Message.propTypes = {
|
||||
user_id: PropTypes.string.isRequired,
|
||||
user_name: PropTypes.node.isRequired,
|
||||
user_type: PropTypes.string.isRequired,
|
||||
user_color: PropTypes.string,
|
||||
text: PropTypes.node,
|
||||
emotes: PropTypes.shape({
|
||||
[PropTypes.string]: PropTypes.string,
|
||||
}),
|
||||
deemphasize: PropTypes.bool,
|
||||
attachments: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.string)),
|
||||
};
|
||||
|
||||
Message.defaultProps = {
|
||||
text: '',
|
||||
user_color: undefined,
|
||||
emotes: {},
|
||||
deemphasize: false,
|
||||
attachments: null,
|
||||
};
|
||||
|
||||
export default Message;
|
43
src/components/chat-log/message/message.style.js
Normal file
43
src/components/chat-log/message/message.style.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
import styled from 'styled-components';
|
||||
|
||||
export const Author = styled.div`
|
||||
width: fit-content;
|
||||
margin-bottom: 4px;
|
||||
`;
|
||||
|
||||
export const Body = styled.span`
|
||||
`;
|
||||
|
||||
export const Emote = styled.img`
|
||||
height: 2em;
|
||||
vertical-align: middle;
|
||||
`;
|
||||
|
||||
export const Wrapper = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
overflow-wrap: break-word;
|
||||
|
||||
color: black;
|
||||
${Author} {
|
||||
color: black;
|
||||
font-weight: bold;
|
||||
}
|
||||
`;
|
||||
|
||||
export const Attachments = styled.div`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px 6px;
|
||||
padding: 8px;
|
||||
|
||||
img {
|
||||
flex: 1;
|
||||
min-width: 33%;
|
||||
max-width: 100%;
|
||||
max-height: 300px;
|
||||
object-fit: scale-down;
|
||||
}
|
||||
`;
|
11
src/components/chat-log/message/mfm/bold.jsx
Normal file
11
src/components/chat-log/message/mfm/bold.jsx
Normal file
|
@ -0,0 +1,11 @@
|
|||
import styled from 'styled-components';
|
||||
|
||||
const Embolden = styled.span`
|
||||
font-weight: bold;
|
||||
`;
|
||||
|
||||
const BoldText = ({ children }) => (
|
||||
<Embolden>{children}</Embolden>
|
||||
);
|
||||
|
||||
export default BoldText;
|
36
src/components/chat-log/message/mfm/emojiCode.jsx
Normal file
36
src/components/chat-log/message/mfm/emojiCode.jsx
Normal file
|
@ -0,0 +1,36 @@
|
|||
import styled from 'styled-components';
|
||||
import PropTypes from 'prop-types'
|
||||
import Text from './text';
|
||||
|
||||
const Emote = styled.img`
|
||||
height: 2em;
|
||||
vertical-align: middle;
|
||||
`;
|
||||
|
||||
const EmojiCode = ({
|
||||
note, name,
|
||||
}) => {
|
||||
if (note.emotes?.[name]) {
|
||||
return (
|
||||
<Emote src={note.emotes[name]} title={name} />
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Text text={`:${name}:`} />
|
||||
);
|
||||
};
|
||||
|
||||
EmojiCode.propTypes = {
|
||||
note: PropTypes.shape({
|
||||
emotes: PropTypes.shape({
|
||||
[PropTypes.string]: PropTypes.string,
|
||||
}),
|
||||
}),
|
||||
name: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
EmojiCode.defaultProps = {
|
||||
note: { emotes: {} },
|
||||
};
|
||||
|
||||
export default EmojiCode;
|
178
src/components/chat-log/message/mfm/fn.jsx
Normal file
178
src/components/chat-log/message/mfm/fn.jsx
Normal file
|
@ -0,0 +1,178 @@
|
|||
import styled, { css, keyframes } from 'styled-components';
|
||||
|
||||
const tada = keyframes`
|
||||
from {
|
||||
transform: scale3d(1, 1, 1);
|
||||
}
|
||||
10%, 20% {
|
||||
transform: scale3d(0.9, 0.9, 0.9) rotate3d(0, 0, 1, -3deg);
|
||||
}
|
||||
30%, 50%, 70%, 90% {
|
||||
transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg);
|
||||
}
|
||||
40%, 60%, 80% {
|
||||
transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg);
|
||||
}
|
||||
to {
|
||||
transform: scale3d(1, 1, 1);
|
||||
}
|
||||
`;
|
||||
const spin = keyframes`
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
`;
|
||||
const spinX = keyframes`
|
||||
0% { transform: perspective(128px) rotateX(0deg); }
|
||||
100% { transform: perspective(128px) rotateX(360deg); }
|
||||
`;
|
||||
const spinY = keyframes`
|
||||
0% { transform: perspective(128px) rotateY(0deg); }
|
||||
100% { transform: perspective(128px) rotateY(360deg); }
|
||||
`;
|
||||
const jump = keyframes`
|
||||
0% { transform: translateY(0); }
|
||||
25% { transform: translateY(-16px); }
|
||||
50% { transform: translateY(0); }
|
||||
75% { transform: translateY(-8px); }
|
||||
100% { transform: translateY(0); }
|
||||
`;
|
||||
const bounce = keyframes`
|
||||
0% { transform: translateY(0) scale(1, 1); }
|
||||
25% { transform: translateY(-16px) scale(1, 1); }
|
||||
50% { transform: translateY(0) scale(1, 1); }
|
||||
75% { transform: translateY(0) scale(1.5, 0.75); }
|
||||
100% { transform: translateY(0) scale(1, 1); }
|
||||
`;
|
||||
const twitch = keyframes`
|
||||
0% { transform: translate(7px, -2px) }
|
||||
5% { transform: translate(-3px, 1px) }
|
||||
10% { transform: translate(-7px, -1px) }
|
||||
15% { transform: translate(0px, -1px) }
|
||||
20% { transform: translate(-8px, 6px) }
|
||||
25% { transform: translate(-4px, -3px) }
|
||||
30% { transform: translate(-4px, -6px) }
|
||||
35% { transform: translate(-8px, -8px) }
|
||||
40% { transform: translate(4px, 6px) }
|
||||
45% { transform: translate(-3px, 1px) }
|
||||
50% { transform: translate(2px, -10px) }
|
||||
55% { transform: translate(-7px, 0px) }
|
||||
60% { transform: translate(-2px, 4px) }
|
||||
65% { transform: translate(3px, -8px) }
|
||||
70% { transform: translate(6px, 7px) }
|
||||
75% { transform: translate(-7px, -2px) }
|
||||
80% { transform: translate(-7px, -8px) }
|
||||
85% { transform: translate(9px, 3px) }
|
||||
90% { transform: translate(-3px, -2px) }
|
||||
95% { transform: translate(-10px, 2px) }
|
||||
100% { transform: translate(-2px, -6px) }
|
||||
`;
|
||||
const shake = keyframes`
|
||||
0% { transform: translate(-3px, -1px) rotate(-8deg) }
|
||||
5% { transform: translate(0px, -1px) rotate(-10deg) }
|
||||
10% { transform: translate(1px, -3px) rotate(0deg) }
|
||||
15% { transform: translate(1px, 1px) rotate(11deg) }
|
||||
20% { transform: translate(-2px, 1px) rotate(1deg) }
|
||||
25% { transform: translate(-1px, -2px) rotate(-2deg) }
|
||||
30% { transform: translate(-1px, 2px) rotate(-3deg) }
|
||||
35% { transform: translate(2px, 1px) rotate(6deg) }
|
||||
40% { transform: translate(-2px, -3px) rotate(-9deg) }
|
||||
45% { transform: translate(0px, -1px) rotate(-12deg) }
|
||||
50% { transform: translate(1px, 2px) rotate(10deg) }
|
||||
55% { transform: translate(0px, -3px) rotate(8deg) }
|
||||
60% { transform: translate(1px, -1px) rotate(8deg) }
|
||||
65% { transform: translate(0px, -1px) rotate(-7deg) }
|
||||
70% { transform: translate(-1px, -3px) rotate(6deg) }
|
||||
75% { transform: translate(0px, -2px) rotate(4deg) }
|
||||
80% { transform: translate(-2px, -1px) rotate(3deg) }
|
||||
85% { transform: translate(1px, -3px) rotate(-10deg) }
|
||||
90% { transform: translate(1px, 0px) rotate(3deg) }
|
||||
95% { transform: translate(-2px, 0px) rotate(-3deg) }
|
||||
100% { transform: translate(2px, 1px) rotate(2deg) }
|
||||
`;
|
||||
const rubberBand = keyframes`
|
||||
from { transform: scale3d(1, 1, 1); }
|
||||
30% { transform: scale3d(1.25, 0.75, 1); }
|
||||
40% { transform: scale3d(0.75, 1.25, 1); }
|
||||
50% { transform: scale3d(1.15, 0.85, 1); }
|
||||
65% { transform: scale3d(0.95, 1.05, 1); }
|
||||
75% { transform: scale3d(1.05, 0.95, 1); }
|
||||
to { transform: scale3d(1, 1, 1); }
|
||||
`;
|
||||
const rainbow = keyframes`
|
||||
0% { filter: hue-rotate(0deg) contrast(150%) saturate(150%); }
|
||||
100% { filter: hue-rotate(360deg) contrast(150%) saturate(150%); }
|
||||
`;
|
||||
|
||||
const validTime = (t, d = null) => {
|
||||
if (t == null) return d;
|
||||
return t.match(/^[0-9.]+s$/) ? t : d;
|
||||
};
|
||||
|
||||
// TODO: font, sparkle
|
||||
const mfmFnStyles = {
|
||||
tada: css`
|
||||
font-size: 150%;
|
||||
animation: ${tada} 1s linear infinite both;
|
||||
`,
|
||||
jelly: css`animation: ${rubberBand} ${(props) => validTime(props.speed, '1s')} linear infinite both;`,
|
||||
twitch: css`animation: ${twitch} ${(props) => validTime(props.speed, '0.5s')} ease infinite;`,
|
||||
shake: css`animation: ${shake} ${(props) => validTime(props.speed, '0.5s')} ease infinite;`,
|
||||
spin: (props) => {
|
||||
let direction;
|
||||
if (props.left) direction = 'reverse'
|
||||
else if (props.alternate) direction = 'alternate'
|
||||
else direction = 'normal';
|
||||
|
||||
let anime;
|
||||
if (props.x) anime = spinX
|
||||
else if (props.y) anime = spinY
|
||||
else anime = spin;
|
||||
|
||||
return css`
|
||||
animation: ${anime} ${(props) => validTime(props.speed, '1.5s')} linear infinite;
|
||||
animation-direction: ${direction};
|
||||
`;
|
||||
},
|
||||
jump: css`animation: ${jump} 0.75s linear infinite;`,
|
||||
bounce: css`
|
||||
animation: ${bounce} 0.75s linear infinite;
|
||||
transform-origin: center bottom;
|
||||
`,
|
||||
flip: (props) => {
|
||||
let transRights;
|
||||
if (props.h && props.v) transRights = 'scale(-1, -1)';
|
||||
else if (props.v) transRights = 'scaleY(-1)';
|
||||
else transRights = 'scaleX(-1)';
|
||||
|
||||
return css`
|
||||
transform: ${transRights};
|
||||
`;
|
||||
},
|
||||
x2: css`font-size: 200%;`,
|
||||
x3: css`font-size: 400%;`,
|
||||
x4: css`font-size: 600%;`,
|
||||
rainbow: css`
|
||||
color: #f42069;
|
||||
animation: ${rainbow} 1s linear infinite;`,
|
||||
rotate: css`
|
||||
transform: rotate(${(props) => parseInt(props.deg) || '90'}deg);
|
||||
transform-origin: center center;
|
||||
`,
|
||||
};
|
||||
|
||||
const MfmFnRunner = styled.span`
|
||||
> span {
|
||||
display: inline-block;
|
||||
${(props) => mfmFnStyles[props.mfmFn]};
|
||||
}
|
||||
`;
|
||||
|
||||
const MfmFunction = ({ children, name, args }) => (
|
||||
<MfmFnRunner mfmFn={name} {...args}>
|
||||
<span>
|
||||
{children}
|
||||
</span>
|
||||
</MfmFnRunner>
|
||||
);
|
||||
|
||||
export default MfmFunction;
|
7
src/components/chat-log/message/mfm/index.js
Normal file
7
src/components/chat-log/message/mfm/index.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
export { default as emojiCode } from './emojiCode';
|
||||
export { default as italic } from './italic';
|
||||
export { default as bold } from './bold';
|
||||
export { default as fn } from './fn';
|
||||
export { default as unicodeEmoji } from './unicodeEmoji';
|
||||
export { default as url } from './url';
|
||||
export { default as text } from './text';
|
11
src/components/chat-log/message/mfm/italic.jsx
Normal file
11
src/components/chat-log/message/mfm/italic.jsx
Normal file
|
@ -0,0 +1,11 @@
|
|||
import styled from 'styled-components';
|
||||
|
||||
const Italic = styled.span`
|
||||
font-style: italic;
|
||||
`;
|
||||
|
||||
const ItalicText = ({ children }) => (
|
||||
<Italic>{children}</Italic>
|
||||
);
|
||||
|
||||
export default ItalicText;
|
7
src/components/chat-log/message/mfm/text.jsx
Normal file
7
src/components/chat-log/message/mfm/text.jsx
Normal file
|
@ -0,0 +1,7 @@
|
|||
const Text = ({ text }) => {
|
||||
return (
|
||||
<span style={{ 'white-space': 'pre-line' }}>{text}</span>
|
||||
);
|
||||
}
|
||||
|
||||
export default Text;
|
5
src/components/chat-log/message/mfm/unicodeEmoji.jsx
Normal file
5
src/components/chat-log/message/mfm/unicodeEmoji.jsx
Normal file
|
@ -0,0 +1,5 @@
|
|||
const UnicodeEmoji = ({ emoji }) => (
|
||||
<span>{emoji}</span>
|
||||
);
|
||||
|
||||
export default UnicodeEmoji;
|
5
src/components/chat-log/message/mfm/url.jsx
Normal file
5
src/components/chat-log/message/mfm/url.jsx
Normal file
|
@ -0,0 +1,5 @@
|
|||
const Url = ({ url }) => (
|
||||
<a>{url}</a>
|
||||
);
|
||||
|
||||
export default Url;
|
16
src/components/compose/compose.jsx
Normal file
16
src/components/compose/compose.jsx
Normal file
|
@ -0,0 +1,16 @@
|
|||
import styled from 'styled-components';
|
||||
|
||||
const Input = styled.textarea`
|
||||
height: 50px;
|
||||
padding: 12px;
|
||||
font-family: 'Noto Sans', sans-serif;
|
||||
font-size: 20px;
|
||||
`;
|
||||
|
||||
function Compose({ onSend }) {
|
||||
return (
|
||||
<Input placeholder="Message #twitch-chat"></Input>
|
||||
)
|
||||
}
|
||||
|
||||
export default Compose;
|
1
src/components/compose/index.js
Normal file
1
src/components/compose/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from './compose';
|
47
src/components/header/header.jsx
Normal file
47
src/components/header/header.jsx
Normal file
|
@ -0,0 +1,47 @@
|
|||
import styled from 'styled-components';
|
||||
|
||||
const Root = styled.div`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 2px solid #0000002a;
|
||||
margin: 0 -20px;
|
||||
padding: 20px 20px;
|
||||
width: calc(100% + 40px);
|
||||
height: 80px;
|
||||
|
||||
font-family: 'Noto Sans', sans-serif;
|
||||
font-size: 20px;
|
||||
`;
|
||||
|
||||
const Desc = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
gap: 4px;
|
||||
`;
|
||||
|
||||
const Head = styled.span`
|
||||
color: #000;
|
||||
font-weight: 600;
|
||||
`;
|
||||
|
||||
const Sub = styled.span`
|
||||
color: #666;
|
||||
`;
|
||||
|
||||
function Header() {
|
||||
return (
|
||||
<Root>
|
||||
<Desc>
|
||||
<Head>#twitch-chat</Head>
|
||||
<Sub>Cheer any amount to ping</Sub>
|
||||
</Desc>
|
||||
<span class="material-symbols-rounded">info</span>
|
||||
</Root>
|
||||
)
|
||||
}
|
||||
|
||||
export default Header;
|
1
src/components/header/index.js
Normal file
1
src/components/header/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from './header'
|
39
src/components/responsive-canvas/get-size.js
Normal file
39
src/components/responsive-canvas/get-size.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* Copyright 2018 Ross Zurowski
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*/
|
||||
// via https://github.com/rosszurowski/react-responsive-canvas/blob/master/src/get-size.js
|
||||
|
||||
const parseNumber = prop => parseFloat(prop) || 0;
|
||||
|
||||
const getSize = (el: Element) => {
|
||||
if (el === window || el === document.body) {
|
||||
return [window.innerWidth, window.innerHeight];
|
||||
}
|
||||
|
||||
let temporary = false;
|
||||
|
||||
if (!el.parentNode && document.body) {
|
||||
temporary = true;
|
||||
document.body.appendChild(el);
|
||||
}
|
||||
|
||||
const rect = el.getBoundingClientRect();
|
||||
const styles = getComputedStyle(el);
|
||||
const height =
|
||||
(rect.height | 0) +
|
||||
parseNumber(styles.getPropertyValue('margin-top')) +
|
||||
parseNumber(styles.getPropertyValue('margin-bottom'));
|
||||
const width =
|
||||
(rect.width | 0) +
|
||||
parseNumber(styles.getPropertyValue('margin-left')) +
|
||||
parseNumber(styles.getPropertyValue('margin-right'));
|
||||
|
||||
if (temporary && document.body) {
|
||||
document.body.removeChild(el);
|
||||
}
|
||||
|
||||
return [width, height];
|
||||
};
|
||||
|
||||
export default getSize;
|
1
src/components/responsive-canvas/index.js
Normal file
1
src/components/responsive-canvas/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from './responsive-canvas';
|
56
src/components/responsive-canvas/responsive-canvas.jsx
Normal file
56
src/components/responsive-canvas/responsive-canvas.jsx
Normal file
|
@ -0,0 +1,56 @@
|
|||
import React, {
|
||||
useEffect, useState, useCallback, useRef, useImperativeHandle, forwardRef,
|
||||
} from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import getSize from './get-size';
|
||||
|
||||
const ResponsiveCanvas = forwardRef(({ scale, onResize }, ref) => {
|
||||
const [width, setWidth] = useState(null);
|
||||
const [height, setHeight] = useState(null);
|
||||
const canvasRef = useRef();
|
||||
|
||||
useImperativeHandle(ref, () => canvasRef.current);
|
||||
|
||||
const handleResize = useCallback(() => {
|
||||
const parent = canvasRef.current.parentElement;
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
const [width, height] = getSize(parent);
|
||||
setWidth(width);
|
||||
setHeight(height);
|
||||
}, [canvasRef]);
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener('resize', handleResize, false);
|
||||
handleResize();
|
||||
return () => window.removeEventListener('resize', handleResize, false);
|
||||
}, [handleResize]);
|
||||
|
||||
useEffect(() => {
|
||||
if (onResize && width !== null && height !== null) onResize();
|
||||
}, [width, height, onResize]);
|
||||
|
||||
return (
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
width={width * scale}
|
||||
height={height * scale}
|
||||
style={{ width, height }}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
ResponsiveCanvas.propTypes = {
|
||||
onResize: PropTypes.func,
|
||||
scale: PropTypes.number,
|
||||
};
|
||||
|
||||
const defaultScale = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
||||
ResponsiveCanvas.defaultProps = {
|
||||
onResize: undefined,
|
||||
scale: defaultScale,
|
||||
};
|
||||
|
||||
export default ResponsiveCanvas;
|
1
src/components/sidebar/index.js
Normal file
1
src/components/sidebar/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default } from './sidebar.jsx';
|
53
src/components/sidebar/sidebar.jsx
Normal file
53
src/components/sidebar/sidebar.jsx
Normal file
|
@ -0,0 +1,53 @@
|
|||
import { Root, Header, Group, Item, Seperator, MentionInd } from './sidebar.style'
|
||||
|
||||
function Sidebar({ unread, mentionCount }) {
|
||||
return (
|
||||
<Root>
|
||||
<Header>
|
||||
Skehstreams
|
||||
<span class="material-symbols-outlined">expand_more</span>
|
||||
</Header>
|
||||
<Item unread={unread}><span class="material-symbols-outlined">notes</span>All unread</Item>
|
||||
<Item><span class="material-symbols-outlined">chat</span>Threads</Item>
|
||||
<Item><span class="material-symbols-outlined">alternate_email</span>Mentions & reactions</Item>
|
||||
<Item><span class="material-symbols-outlined">content_copy</span>Drafts</Item>
|
||||
<Item><span class="material-symbols-outlined">arrow_downward</span>Show more</Item>
|
||||
<Seperator />
|
||||
<Group>
|
||||
<h1>
|
||||
<span class="material-symbols-outlined">arrow_drop_down</span>
|
||||
<span class="text">Starred</span>
|
||||
</h1>
|
||||
</Group>
|
||||
<Group>
|
||||
<h1>
|
||||
<span class="material-symbols-outlined">arrow_drop_down</span>
|
||||
<span class="text">Channels</span>
|
||||
<span class="material-symbols-outlined add">add</span>
|
||||
</h1>
|
||||
<Item><span class="material-symbols-outlined">lock</span>birbspace-br18hprp</Item>
|
||||
<Item><span class="material-symbols-outlined">tag</span>birbspace-stream-channel</Item>
|
||||
<Item><span class="material-symbols-outlined">tag</span>birbspace-perch</Item>
|
||||
<Item unread={unread}>
|
||||
<span class="material-symbols-outlined">tag</span>
|
||||
<span>twitch-chat</span>
|
||||
<MentionInd visible={!!mentionCount}>{mentionCount}</MentionInd>
|
||||
</Item>
|
||||
<Item><span class="material-symbols-outlined">tag</span>vtopia-chat</Item>
|
||||
</Group>
|
||||
<Group>
|
||||
<h1>
|
||||
<span class="material-symbols-outlined">arrow_drop_down</span>
|
||||
<span class="text">Direct Messages</span>
|
||||
<span class="material-symbols-outlined add">add</span>
|
||||
</h1>
|
||||
<Item><span class="material-symbols-outlined online">fiber_manual_record</span>Skeh (human)</Item>
|
||||
<Item><span class="material-symbols-outlined offline">fiber_manual_record</span>Spug</Item>
|
||||
<Item><span class="material-symbols-outlined offline">fiber_manual_record</span>Issac</Item>
|
||||
<Item><span class="material-symbols-outlined offline">fiber_manual_record</span>Ada</Item>
|
||||
</Group>
|
||||
</Root>
|
||||
)
|
||||
}
|
||||
|
||||
export default Sidebar;
|
81
src/components/sidebar/sidebar.style.js
Normal file
81
src/components/sidebar/sidebar.style.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
import styled, { css } from 'styled-components';
|
||||
|
||||
export const Root = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 360px;
|
||||
min-width: 360px;
|
||||
|
||||
background-color: #3d123f;
|
||||
color: #ffffffaa;
|
||||
font-weight: 500;
|
||||
padding: 20px;
|
||||
font-family: 'Noto Sans', sans-serif;
|
||||
|
||||
gap: 10px;
|
||||
`;
|
||||
|
||||
export const Header = styled.span`
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
height: calc(80px - 20px);
|
||||
|
||||
border-bottom: 2px solid #ffffff2a;
|
||||
margin: 0 -20px;
|
||||
padding: 0 20px;
|
||||
|
||||
display: flex;
|
||||
align-items: start;
|
||||
.material-symbols-outlined {
|
||||
padding-left: 8px;
|
||||
}
|
||||
margin-bottom: 15px;
|
||||
`;
|
||||
export const Group = styled.div`
|
||||
margin: 0 16px 20px 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
h1 {
|
||||
margin: 0 -16px;
|
||||
font-size: 20px;
|
||||
font-weight: 500;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
.text {
|
||||
flex: 1;
|
||||
}
|
||||
.material-symbols-outlined:not(.add) {
|
||||
font-size: 32px;
|
||||
padding-right: 8px;
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const Item = styled.span`
|
||||
font-size: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
.material-symbols-outlined {
|
||||
font-size: 18px;
|
||||
padding-right: 0.5em;
|
||||
}
|
||||
${(props) => props.unread && css`
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
`}
|
||||
|
||||
.online {
|
||||
color: #34a975;
|
||||
}
|
||||
`;
|
||||
export const Seperator = styled.hr`
|
||||
width: calc(100% + 38px);
|
||||
margin: 15px -20px;
|
||||
color: #ffffff2a;
|
||||
border-style: solid;
|
||||
`;
|
||||
export const MentionInd = styled.span`
|
||||
${(props) => !props.visible && css`display: none;`}
|
||||
`;
|
1
src/hooks/index.js
Normal file
1
src/hooks/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default as useQuery } from './useQuery';
|
5
src/hooks/useQuery.js
Normal file
5
src/hooks/useQuery.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { useLocation } from 'react-router-dom';
|
||||
|
||||
export default function useQuery() {
|
||||
return new URLSearchParams(useLocation().search);
|
||||
}
|
16
src/index.js
Normal file
16
src/index.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { BrowserRouter } from "react-router-dom";
|
||||
import App from './components/app/app';
|
||||
|
||||
import { GlobalStyle } from './index.style';
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<GlobalStyle />
|
||||
<BrowserRouter>
|
||||
<App />
|
||||
</BrowserRouter>
|
||||
</React.StrictMode>,
|
||||
document.getElementById('root')
|
||||
);
|
21
src/index.style.js
Normal file
21
src/index.style.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import css, { createGlobalStyle } from 'styled-components';
|
||||
import { normalize } from 'polished';
|
||||
|
||||
export const GlobalStyle = createGlobalStyle`
|
||||
${normalize()};
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
#root {
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
overflow: none;
|
||||
}
|
||||
`;
|
1
src/logo.svg
Normal file
1
src/logo.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
|
After (image error) Size: 2.6 KiB |
5
src/setupTests.js
Normal file
5
src/setupTests.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom';
|
Loading…
Add table
Reference in a new issue