aboutsummaryrefslogtreecommitdiffstats
path: root/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'frontend')
-rw-r--r--frontend/components/Marquees/Marquee.module.css38
-rw-r--r--frontend/components/Marquees/Marquee.tsx20
-rw-r--r--frontend/components/Marquees/Marquees.tsx35
-rw-r--r--frontend/pages/index.tsx25
-rw-r--r--frontend/shared-types.ts5
-rw-r--r--frontend/styles/Home.module.css1
6 files changed, 111 insertions, 13 deletions
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 => (
+ <a className={styles.marquee} href={url} style={{
+ animationDelay: delayShorthand,
+ top: topShorthand,
+ animationDirection: direction === "left" ? "normal" : "reverse",
+ }}>{text}</a>
+);
+
+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 (
+ <div className={styles.marqueeContainer}>
+ { links.map((link, idx) => (
+ <Marquee
+ key={idx}
+ url={link.url}
+ text={link.title}
+ delayShorthand={getRandomDelayBetween(0, 9)}
+ topShorthand={getTopFromIndex(idx, links.length)}
+ direction={getRandomAnimationName()}
+ />
+ ))}
+ </div>
+ );
+};
+
+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<number | undefined>(undefined);
+ const [papers, setPapers] = useState<MarqueeLink[]>([]);
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 => {
<img src="/tomi_sq.png" alt="" />
</div>
</button>
- <Marquees links={mockData} />
+ <Marquees links={papers} />
</div>
);
};
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 {