Skip to content

Commit

Permalink
gun instance on top
Browse files Browse the repository at this point in the history
  • Loading branch information
skorotkiewicz committed May 4, 2022
1 parent 78fd92d commit a6fd7e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
18 changes: 6 additions & 12 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from "react";
import { useParams, useNavigate, Link } from "react-router-dom";
import "./App.scss";
import Gun from "gun/gun";
import SEA from "gun/sea";
import Languages from "./components/Languages";
import { B64ToText, TextToB64 } from "./utils";
Expand All @@ -17,7 +16,7 @@ import Loading from "./components/Loading";
const Monaco = lazy(() => import("./components/Monaco"));
const CodeArea = lazy(() => import("./components/CodeArea"));

function App() {
function App({ gun }) {
let params = useParams();
let navigate = useNavigate();
const [bin, setBin] = useState(params.binId);
Expand All @@ -31,14 +30,6 @@ function App() {
const [theme, setTheme] = useState("monokai");
const loaded = useRef(false);

const gun = Gun();
gun.opt({
peers: [
"https://grizzly.de1.hashbang.sh/gun",
// "https://gun-manhattan.herokuapp.com/gun",
],
});

useEffect(() => {
if (localStorage.getItem("dpaste") && loaded.current === false)
setBins(JSON.parse(localStorage.getItem("dpaste")));
Expand Down Expand Up @@ -70,7 +61,7 @@ function App() {
}
}
});
}, [bin]);
}, [bin, gun]);

const save = useCallback(async () => {
if (!data) return;
Expand All @@ -81,6 +72,9 @@ function App() {
let hash = await SEA.work(paste, null, null, {
name: "SHA-256",
});

if (!hash) return;

let b64Hash = TextToB64(hash);
let title = `[${ext}] - ${data.trim().substring(0, 10)}`;

Expand All @@ -100,7 +94,7 @@ function App() {
}
setLoading(false);
});
}, [bins, data, ext, navigate]);
}, [bins, data, ext, gun, navigate]);

return (
<div className="container">
Expand Down
13 changes: 11 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ import { createRoot } from "react-dom/client";
import "./index.css";
import App from "./App";
import { HashRouter, Routes, Route } from "react-router-dom";
import Gun from "gun/gun";

const gun = Gun();
gun.opt({
peers: [
"https://grizzly.de1.hashbang.sh/gun",
// "https://gun-manhattan.herokuapp.com/gun",
],
});

const root = createRoot(document.getElementById("root"));
root.render(
<StrictMode>
<HashRouter>
<Routes>
<Route path="/" element={<App />}>
<Route path=":binId" element={<App />} />
<Route path="/" element={<App gun={gun} />}>
<Route path=":binId" element={<App gun={gun} />} />
</Route>
</Routes>
</HashRouter>
Expand Down

0 comments on commit a6fd7e4

Please sign in to comment.