From 711823a8249343e1b8dd4f4f601518b6421296d9 Mon Sep 17 00:00:00 2001 From: Cloudburst <18114966+C10udburst@users.noreply.github.com> Date: Sat, 27 Aug 2022 10:45:32 +0200 Subject: [PATCH] improve tv support --- gatsby-browser.js | 16 ++++++++++- package-lock.json | 20 ++++++++++++++ package.json | 1 + src/components/cards/repo.jsx | 46 +++++++++++++++---------------- src/components/compatbtn.jsx | 47 ++++++++++++++++++++++++++++++++ src/components/navbar/button.jsx | 5 ++-- src/pages/404.js | 12 ++------ src/pages/index.js | 13 +++------ src/pages/install.js | 17 +++++++----- 9 files changed, 126 insertions(+), 51 deletions(-) create mode 100644 src/components/compatbtn.jsx diff --git a/gatsby-browser.js b/gatsby-browser.js index bc9e98a..a466282 100644 --- a/gatsby-browser.js +++ b/gatsby-browser.js @@ -1 +1,15 @@ -require("prism-themes/themes/prism-dracula.min.css") \ No newline at end of file +import { init } from '@noriginmedia/norigin-spatial-navigation'; + +require("prism-themes/themes/prism-dracula.min.css") + +if (window !== undefined) { + init({ + visualDebug: false + }); + + // window.addEventListener("keypress", (evt) => { + // if (evt.keyCode === 461) { + // window.history.go(-1) + // } + // }) +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 70a844e..109bd73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "recloudstream", "version": "1.0.0", "dependencies": { + "@noriginmedia/norigin-spatial-navigation": "^1.0.5", "daisyui": "^2.24.0", "gatsby": "^4.21.1", "gatsby-plugin-html-attributes": "^1.0.5", @@ -2917,6 +2918,17 @@ "node": ">= 8" } }, + "node_modules/@noriginmedia/norigin-spatial-navigation": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@noriginmedia/norigin-spatial-navigation/-/norigin-spatial-navigation-1.0.5.tgz", + "integrity": "sha512-sLdigBBihZUtlexumYRrPkqg8P8SaSp+ZsLDEfDXdySP+/NK+uGCkRl7vi/GboTfDghdKt88KhwOa8sjvTuu5Q==", + "dependencies": { + "lodash": "^4.17.21" + }, + "peerDependencies": { + "react": ">=16.8.0" + } + }, "node_modules/@parcel/bundler-default": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/@parcel/bundler-default/-/bundler-default-2.6.2.tgz", @@ -22844,6 +22856,14 @@ "fastq": "^1.6.0" } }, + "@noriginmedia/norigin-spatial-navigation": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@noriginmedia/norigin-spatial-navigation/-/norigin-spatial-navigation-1.0.5.tgz", + "integrity": "sha512-sLdigBBihZUtlexumYRrPkqg8P8SaSp+ZsLDEfDXdySP+/NK+uGCkRl7vi/GboTfDghdKt88KhwOa8sjvTuu5Q==", + "requires": { + "lodash": "^4.17.21" + } + }, "@parcel/bundler-default": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/@parcel/bundler-default/-/bundler-default-2.6.2.tgz", diff --git a/package.json b/package.json index 8f40876..7352610 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "clean": "gatsby clean" }, "dependencies": { + "@noriginmedia/norigin-spatial-navigation": "^1.0.5", "daisyui": "^2.24.0", "gatsby": "^4.21.1", "gatsby-plugin-html-attributes": "^1.0.5", diff --git a/src/components/cards/repo.jsx b/src/components/cards/repo.jsx index 726ed1c..bc3d0b8 100644 --- a/src/components/cards/repo.jsx +++ b/src/components/cards/repo.jsx @@ -1,14 +1,9 @@ -import React, { useState, useEffect, useRef } from "react"; +import React, { useState, useEffect } from "react"; + +import CompatBtn from "../compatbtn"; const RepoCard = ({ url, isFirst }) => { const [data, setData] = useState(null) - const firstButton = useRef(null) - - useEffect(() => { - if (!isFirst) return; - console.log({firstButton}) - firstButton.current?.focus() - }, [firstButton]) useEffect(() => { fetch(url) @@ -30,21 +25,26 @@ const RepoCard = ({ url, isFirst }) => {

- - + Install + { + if (navigator.clipboard) { + navigator.clipboard.writeText(url); + } else { + var tempInput = document.createElement("input"); + tempInput.value = url; + document.body.appendChild(tempInput); + tempInput.select(); + document.execCommand("copy"); + document.body.removeChild(tempInput); + } + }}>Copy URL
diff --git a/src/components/compatbtn.jsx b/src/components/compatbtn.jsx new file mode 100644 index 0000000..06354a0 --- /dev/null +++ b/src/components/compatbtn.jsx @@ -0,0 +1,47 @@ +import React, { useEffect } from "react"; +import { useFocusable } from '@noriginmedia/norigin-spatial-navigation'; +import { Link, navigate } from "gatsby"; + + +function CompatBtn({autoFocus, href, onClick, group, target, children, className, ...props}) { + const { ref, focused, focusSelf} = useFocusable(); + + useEffect(() => { + if (!autoFocus) return; + focusSelf() + }, [focusSelf]) + + if (onClick) href = "#!" + + if (focused && ref.current) { + ref.current?.focus() + } + + if (window) { + window.addEventListener("keyup", (ev) => { + if (!focused) return; + if (document.activeElement !== ref.current) return; + if (ev.key === "Enter" || ev.key === " ") { + ref.current?.click() + } + }) + } + + if (target !== "_blank" && !group && !onClick) { + return {children} + } else if (!group && !onClick) { + return {children} + } else { + return + } +} + +export default CompatBtn \ No newline at end of file diff --git a/src/components/navbar/button.jsx b/src/components/navbar/button.jsx index 001e276..373c99e 100644 --- a/src/components/navbar/button.jsx +++ b/src/components/navbar/button.jsx @@ -1,11 +1,12 @@ import React from "react" +import { Link } from "gatsby" const Button = ({url, children, name}) => (
- + {children} - +
) diff --git a/src/pages/404.js b/src/pages/404.js index 6e12ddb..257add3 100644 --- a/src/pages/404.js +++ b/src/pages/404.js @@ -1,24 +1,18 @@ -import React, {useRef, useEffect} from "react" +import React from "react" import Layout from "../components/layout" import Hero from "../components/hero" import bgImage from "../media/phones.png" -import { Link } from "gatsby" +import CompatBtn from "../components/compatbtn" const NotFoundPage = () => { - const firstBtn = useRef(null) - - useEffect(() => { - firstBtn.current.focus() - }, [firstBtn]) - return (

Not found

Sorry 😔. We couldn’t find what you were looking for.

- Home + Home
) diff --git a/src/pages/index.js b/src/pages/index.js index a30030b..d2d2b15 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -1,26 +1,21 @@ -import React, {useEffect, useRef} from "react" +import React from "react" import Layout from "../components/layout" import Hero from "../components/hero" +import CompatBtn from "../components/compatbtn" import bgImage from "../media/phones.png" import { Link } from "gatsby" const IndexPage = () => { - const firstBtn = useRef(null) - - useEffect(() => { - firstBtn.current.focus() - }, [firstBtn]) - return

Hello there

Cloudstream is an Android app for streaming and downloading Movies, TV-Series and Anime.

- Install + Install
- Repositories + Repositories
Documentation diff --git a/src/pages/install.js b/src/pages/install.js index e8ccd6b..c97ae7e 100644 --- a/src/pages/install.js +++ b/src/pages/install.js @@ -2,6 +2,7 @@ import React, { useEffect, useState } from "react" import Layout from "../components/layout" import Hero from "../components/hero" +import CompatBtn from "../components/compatbtn" import bgImage from "../media/phones.png" @@ -54,14 +55,16 @@ const InstallPage = () => {

Installation

{(data != null) &&
{ - data.btns.map(it => { + data.btns.map((it, idx) => { return
- - + Download {it.tag} + Release notes
})}