From b6beb5f02e8c291f2b5f2bc7d0c15d0955336c32 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 2 Jul 2021 11:19:25 +0300 Subject: Implement research papers --- frontend/components/Marquees/Marquee.module.css | 38 +++++++++++++++++++++++++ frontend/components/Marquees/Marquee.tsx | 20 +++++++++++++ frontend/components/Marquees/Marquees.tsx | 35 +++++++++++++++++++++++ frontend/pages/index.tsx | 25 ++++++++-------- frontend/shared-types.ts | 5 ++++ frontend/styles/Home.module.css | 1 + 6 files changed, 111 insertions(+), 13 deletions(-) create mode 100644 frontend/components/Marquees/Marquee.module.css create mode 100644 frontend/components/Marquees/Marquee.tsx create mode 100644 frontend/components/Marquees/Marquees.tsx (limited to 'frontend') diff --git a/frontend/components/Marquees/Marquee.module.css b/frontend/components/Marquees/Marquee.module.css new file mode 100644 index 0000000..0fb8ece --- /dev/null +++ b/frontend/components/Marquees/Marquee.module.css @@ -0,0 +1,38 @@ +.marqueeContainer { + height: 100vh; + overflow: hidden; + position: relative; + background: #fefefe; + color: #333; + z-index: 10; +} + +.marquee { + position: absolute; + width: 100%; + height: 50px; + margin: 0; + line-height: 50px; + text-align: center; + transform: translateX(100%); + animation: scroll-left 10s linear infinite; + text-decoration: underline; +} + +@keyframes scroll-left { + 0% { + transform: translateX(100%); + } + 100% { + transform: translateX(-100%); + } +} + +@keyframes scroll-right { + 0% { + transform: translateX(-100%); + } + 100% { + transform: translateX(100%); + } +} diff --git a/frontend/components/Marquees/Marquee.tsx b/frontend/components/Marquees/Marquee.tsx new file mode 100644 index 0000000..4cc41a2 --- /dev/null +++ b/frontend/components/Marquees/Marquee.tsx @@ -0,0 +1,20 @@ +import React, { ReactElement } from "react"; +import styles from "./Marquee.module.css"; + +interface Props { + delayShorthand: string; + topShorthand: string; + url: string; + text: string; + direction: "left" | "right"; +} + +const Marquee = ({ delayShorthand, url, text, topShorthand, direction }: Props): ReactElement => ( + {text} +); + +export default Marquee; diff --git a/frontend/components/Marquees/Marquees.tsx b/frontend/components/Marquees/Marquees.tsx new file mode 100644 index 0000000..04747fb --- /dev/null +++ b/frontend/components/Marquees/Marquees.tsx @@ -0,0 +1,35 @@ +import React, { ReactElement } from "react"; +import styles from "./Marquee.module.css"; +import Marquee from "./Marquee"; + +export interface MarqueeLink { + title: string; + url: string; +} + +interface Props { + links: MarqueeLink[] +} + +const getRandomDelayBetween = (start: number, end: number) => `${Math.random() * (end - start) + start}s`; +const getTopFromIndex = (index: number, n: number) => `calc((100% - 50px) * (${index} / ${n - 1}))`; +const getRandomAnimationName = () => Math.random() > 0.5 ? "right" : "left"; + +const Marquees = ({ links }: Props): ReactElement => { + return ( +
+ { links.map((link, idx) => ( + + ))} + + ); +}; + +export default Marquees; diff --git a/frontend/pages/index.tsx b/frontend/pages/index.tsx index 58b3b56..6193488 100644 --- a/frontend/pages/index.tsx +++ b/frontend/pages/index.tsx @@ -7,19 +7,9 @@ import styles from "../styles/Home.module.css"; const socket = io(config.backendUrl); -const mockData: MarqueeLink[] = [ - { title: "Foobar of Foos and Bars", url: "https://example.com" }, - { title: "Foobar of Foos and Bars", url: "https://example.com" }, - { title: "Foobar of Foos and Bars", url: "https://example.com" }, - { title: "Foobar of Foos and Bars", url: "https://example.com" }, - { title: "Foobar of Foos and Bars", url: "https://example.com" }, - { title: "Foobar of Foos and Bars", url: "https://example.com" }, - { title: "Foobar of Foos and Bars", url: "https://example.com" }, - { title: "Foobar of Foos and Bars", url: "https://example.com" }, -]; - const Home = (): ReactElement => { const [value, setValue] = useState(undefined); + const [papers, setPapers] = useState([]); useEffect(() => { socket.on("connect", () => { @@ -29,11 +19,20 @@ const Home = (): ReactElement => { console.log("disconnected, reason:", reason); }); socket.on("update", (arg: number) => { - console.log("update:", arg); setValue(arg); }); }); + useEffect(() => { + async function fetchPapers() { + const resp = await fetch(`${config.backendUrl}/api/papers`); + const data = await resp.json(); + + setPapers(data); + } + fetchPapers(); + }, []); + const increment = () => { socket.emit("increment"); }; @@ -57,7 +56,7 @@ const Home = (): ReactElement => { - + ); }; diff --git a/frontend/shared-types.ts b/frontend/shared-types.ts index 51f3281..f68b896 100644 --- a/frontend/shared-types.ts +++ b/frontend/shared-types.ts @@ -1,3 +1,8 @@ export interface ValueRecord { value: number; } + +export interface Paper { + title: string; + url: string; +} diff --git a/frontend/styles/Home.module.css b/frontend/styles/Home.module.css index 6f43b54..814ebba 100644 --- a/frontend/styles/Home.module.css +++ b/frontend/styles/Home.module.css @@ -19,6 +19,7 @@ top: 50%; margin-left: -40vw; margin-top: -40vw; + z-index: 20; } .btnInner { -- cgit v1.3