|
| 1 | +import React, { useEffect, useState } from "react"; |
| 2 | + |
| 3 | +const getStars = async () => { |
| 4 | + try { |
| 5 | + const res = await fetch( |
| 6 | + "https://api.github.com/repos/appbaseio/reactivesearch?callback=callback" |
| 7 | + ); |
| 8 | + const data = await res.text(); |
| 9 | + const lines = data.split("\n"); |
| 10 | + lines.splice(0, 1, "{"); |
| 11 | + lines.splice(-2, 1, "}"); |
| 12 | + return JSON.parse(lines.join("\n")).data.stargazers_count; |
| 13 | + } catch (error) { |
| 14 | + throw error; |
| 15 | + } |
| 16 | +}; |
| 17 | +export default ({ children }) => { |
| 18 | + const [stars, setStars] = useState( |
| 19 | + window.sessionStorage.getItem("appbase_rs_star_count") |
| 20 | + ); |
| 21 | + useEffect(() => { |
| 22 | + const sessionData = window.sessionStorage.getItem("appbase_rs_star_count"); |
| 23 | + console.log("session data", sessionData); |
| 24 | + if (!sessionData) { |
| 25 | + async function fetchData() { |
| 26 | + const currentStars = await getStars(); |
| 27 | + console.log("stars", currentStars); |
| 28 | + setStars(currentStars); |
| 29 | + window.sessionStorage.setItem("appbase_rs_star_count", currentStars); |
| 30 | + } |
| 31 | + fetchData(); |
| 32 | + } |
| 33 | + }, [stars]); |
| 34 | + return ( |
| 35 | + <div> |
| 36 | + <div |
| 37 | + style={{ |
| 38 | + position: "fixed", |
| 39 | + top: 0, |
| 40 | + left: 0, |
| 41 | + right: 0, |
| 42 | + margin: 0, |
| 43 | + display: "flex", |
| 44 | + alignItems: "center", |
| 45 | + justifyContent: "space-between", |
| 46 | + }} |
| 47 | + > |
| 48 | + <div |
| 49 | + style={{ |
| 50 | + // background: "#173baa", |
| 51 | + padding: 20, |
| 52 | + display: "flex", |
| 53 | + alignItems: "center", |
| 54 | + borderBottomRightRadius: 5, |
| 55 | + }} |
| 56 | + > |
| 57 | + <img |
| 58 | + src="https://opensource.appbase.io/reactivesearch/images/RSlogo.svg" |
| 59 | + alt="rs logo" |
| 60 | + /> |
| 61 | + <span |
| 62 | + style={{ |
| 63 | + marginLeft: 10, |
| 64 | + fontSize: 24, |
| 65 | + fontWeight: "light", |
| 66 | + }} |
| 67 | + > |
| 68 | + Reactive<span style={{ fontWight: "700" }}>Search</span> |
| 69 | + </span> |
| 70 | + {stars && ( |
| 71 | + <div style={{ display: "flex", marginLeft: 10 }}> |
| 72 | + <a |
| 73 | + href="https://github.com/appbaseio/reactivesearch" |
| 74 | + target="_blank" |
| 75 | + style={{ |
| 76 | + padding: "2px 5px 2px 4px", |
| 77 | + color: "#333", |
| 78 | + textDecoration: "none", |
| 79 | + textShadow: "0 1px 0 #fff", |
| 80 | + whiteSpace: "nowrap", |
| 81 | + cursor: "pointer", |
| 82 | + borderRadius: "3px", |
| 83 | + fontSize: 12, |
| 84 | + backgroundRepeat: "no-repeat", |
| 85 | + border: "1px solid #d5d5d5", |
| 86 | + backgroundColor: "#eee", |
| 87 | + display: "flex", |
| 88 | + alignItems: "center", |
| 89 | + }} |
| 90 | + > |
| 91 | + <span |
| 92 | + style={{ |
| 93 | + display: "inline-block", |
| 94 | + width: "14px", |
| 95 | + height: "14px", |
| 96 | + marginRight: "4px", |
| 97 | + backgroundImage: `url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2ZXJzaW9uPSIxLjEiIGlkPSJMYXllcl8xIiB4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjQwcHgiIGhlaWdodD0iNDBweCIgdmlld0JveD0iMTIgMTIgNDAgNDAiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMTIgMTIgNDAgNDAiIHhtbDpzcGFjZT0icHJlc2VydmUiPjxwYXRoIGZpbGw9IiMzMzMzMzMiIGQ9Ik0zMiAxMy40Yy0xMC41IDAtMTkgOC41LTE5IDE5YzAgOC40IDUuNSAxNS41IDEzIDE4YzEgMC4yIDEuMy0wLjQgMS4zLTAuOWMwLTAuNSAwLTEuNyAwLTMuMiBjLTUuMyAxLjEtNi40LTIuNi02LjQtMi42QzIwIDQxLjYgMTguOCA0MSAxOC44IDQxYy0xLjctMS4yIDAuMS0xLjEgMC4xLTEuMWMxLjkgMC4xIDIuOSAyIDIuOSAyYzEuNyAyLjkgNC41IDIuMSA1LjUgMS42IGMwLjItMS4yIDAuNy0yLjEgMS4yLTIuNmMtNC4yLTAuNS04LjctMi4xLTguNy05LjRjMC0yLjEgMC43LTMuNyAyLTUuMWMtMC4yLTAuNS0wLjgtMi40IDAuMi01YzAgMCAxLjYtMC41IDUuMiAyIGMxLjUtMC40IDMuMS0wLjcgNC44LTAuN2MxLjYgMCAzLjMgMC4yIDQuNyAwLjdjMy42LTIuNCA1LjItMiA1LjItMmMxIDIuNiAwLjQgNC42IDAuMiA1YzEuMiAxLjMgMiAzIDIgNS4xYzAgNy4zLTQuNSA4LjktOC43IDkuNCBjMC43IDAuNiAxLjMgMS43IDEuMyAzLjVjMCAyLjYgMCA0LjYgMCA1LjJjMCAwLjUgMC40IDEuMSAxLjMgMC45YzcuNS0yLjYgMTMtOS43IDEzLTE4LjFDNTEgMjEuOSA0Mi41IDEzLjQgMzIgMTMuNHoiLz48L3N2Zz4=)`, |
| 98 | + backgroundSize: "100% 100%", |
| 99 | + backgroundRepeat: "no-repeat", |
| 100 | + }} |
| 101 | + /> |
| 102 | + <span>Star</span> |
| 103 | + </a> |
| 104 | + <a |
| 105 | + href="https://github.com/appbaseio/dejavu/stargazers" |
| 106 | + target="_blank" |
| 107 | + style={{ |
| 108 | + marginLeft: "4px", |
| 109 | + backgroundColor: " #fafafa", |
| 110 | + border: "1px solid #d4d4d4", |
| 111 | + padding: "2px 5px 2px 4px", |
| 112 | + color: "#333", |
| 113 | + textDecoration: "none", |
| 114 | + textShadow: "0 1px 0 #fff", |
| 115 | + whiteSpace: "nowrap", |
| 116 | + cursor: "pointer", |
| 117 | + borderRadius: "3px", |
| 118 | + fontSize: 12, |
| 119 | + }} |
| 120 | + > |
| 121 | + {stars} |
| 122 | + </a> |
| 123 | + </div> |
| 124 | + )} |
| 125 | + </div> |
| 126 | + <div style={{ paddingRight: 20 }}> |
| 127 | + <img |
| 128 | + src="https://appbase.io/static/svg/appbase-dark.svg" |
| 129 | + alt="logo" |
| 130 | + height={40} |
| 131 | + /> |
| 132 | + </div> |
| 133 | + </div> |
| 134 | + <div |
| 135 | + style={{ |
| 136 | + display: "flex", |
| 137 | + flexDirection: "column", |
| 138 | + justifyContent: "center", |
| 139 | + alignItems: "center", |
| 140 | + width: "100%", |
| 141 | + }} |
| 142 | + > |
| 143 | + {children} |
| 144 | + </div> |
| 145 | + <div |
| 146 | + style={{ |
| 147 | + position: "fixed", |
| 148 | + bottom: 0, |
| 149 | + left: 0, |
| 150 | + right: 0, |
| 151 | + fontSize: 16, |
| 152 | + padding: 10, |
| 153 | + textAlign: "center", |
| 154 | + }} |
| 155 | + > |
| 156 | + <a |
| 157 | + href="https://reactivesearch-course.appbase.io" |
| 158 | + style={{ color: "dodgerblue", textDecoration: "none" }} |
| 159 | + > |
| 160 | + https://reactivesearch-course.appbase.io |
| 161 | + </a>{" "} |
| 162 | + | Use arrow keys or spacebar to navigate between slides. |
| 163 | + </div> |
| 164 | + </div> |
| 165 | + ); |
| 166 | +}; |
0 commit comments