Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
sekaiking committed Nov 22, 2023
1 parent 62aec06 commit 46c3209
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
cache: yarn

- name: Install Dependencies
id: install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: 16
cache: yarn
registry-url: 'https://registry.npmjs.org'
cache: yarn
registry-url: "https://registry.npmjs.org"

- name: Install Dependencies
id: install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: 16
cache: yarn
cache: yarn

- name: Install Dependencies
id: install
Expand Down
8 changes: 4 additions & 4 deletions gateway/config/flags.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const flags = {
bosLoaderUrl: process.env.BOS_LOADER_URL || "http://127.0.0.1:4040",
bosLoaderWs: process.env.BOS_LOADER_WS || "ws://127.0.0.1:4040",
enableHotReload: process.env.ENABLE_HOT_RELOAD ?? false
}
bosLoaderUrl: process.env.BOS_LOADER_URL || "http://127.0.0.1:4040",
bosLoaderWs: process.env.BOS_LOADER_WS || "ws://127.0.0.1:4040",
enableHotReload: process.env.ENABLE_HOT_RELOAD ?? false,
};
2 changes: 1 addition & 1 deletion gateway/config/presets/loadPreset.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const loadPresets = (env = { presets: [] }) => {
/** @type {string[]} */
const mergedPresets = [].concat(...[presets]);
const mergedConfigs = mergedPresets.map((presetName) =>
require(`./webpack.${presetName}.js`)(env)
require(`./webpack.${presetName}.js`)(env),
);

return merge({}, ...mergedConfigs);
Expand Down
2 changes: 1 addition & 1 deletion gateway/public/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down
14 changes: 7 additions & 7 deletions gateway/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ function Viewer({ widgetSrc, code }) {
Array.from(searchParams.entries()).reduce((props, [key, value]) => {
props[key] = value;
return props;
}, {})
}, {}),
);
}, [location]);

let src;

if (!code) { // prioritize code if provided
if (!code) {
// prioritize code if provided
src = widgetSrc || location.pathname;
if (src) {
src = src.substring(src.lastIndexOf('/', src.indexOf('.near')) + 1);
src = src.substring(src.lastIndexOf("/", src.indexOf(".near")) + 1);
} else {
src = 'devhub.near/widget/app';
src = "devhub.near/widget/app";
}
}

const { components: redirectMap} = useRedirectMap();

const { components: redirectMap } = useRedirectMap();

return (
<Widget
Expand All @@ -60,7 +60,7 @@ function App(props) {
useEffect(() => {
initNear &&
initNear({
networkId: 'mainnet',
networkId: "mainnet",
customElements: {
Link: (props) => {
if (!props.to && props.href) {
Expand Down
12 changes: 7 additions & 5 deletions gateway/src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ body {
overflow-y: scroll;
}

body, html {
body,
html {
-webkit-font-smoothing: antialiased;
}

.pointer {
cursor: pointer;
}

.btn-success, .btn-primary {
.btn-success,
.btn-primary {
.text-muted {
color: #fff !important;
};
}
}

.outline-none {
Expand All @@ -33,15 +35,15 @@ a {
}

.sidebar-items {
&> div {
& > div {
border-right: 1px solid #e5e5e5;
text-align: center;
min-height: 4rem;
max-height: 4rem;
display: flex;
}

&> div:not(.apps) {
& > div:not(.apps) {
min-width: 4rem;
align-items: center !important;
justify-content: center !important;
Expand Down
11 changes: 5 additions & 6 deletions gateway/src/index.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
:root {
--slate-dark-1: #151718;
--slate-dark-5: #2B2F31;
--slate-dark-5: #2b2f31;
--slate-dark-6: #313538;
--slate-dark-8: #4C5155;
--slate-dark-8: #4c5155;
--slate-dark-9: #697177;
--slate-dark-11: #9BA1A6;
--slate-dark-12: #ECEDEE;
--blue-light-9: #0091FF;
--slate-dark-11: #9ba1a6;
--slate-dark-12: #ecedee;
--blue-light-9: #0091ff;

--font-weight-medium: 500;
--font-weight-bold: 600;
Expand All @@ -16,4 +16,3 @@
--account-center-position-top: 64px;
--account-center-position-right: -10px;
}

2 changes: 1 addition & 1 deletion gateway/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
</React.StrictMode>,
);
87 changes: 43 additions & 44 deletions gateway/src/useRedirectMap.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
import { useEffect, useState } from 'react';
import io from 'socket.io-client';
import { flags } from '../config/flags.js';
import { useEffect, useState } from "react";
import io from "socket.io-client";
import { flags } from "../config/flags.js";

function useRedirectMap() {
const [devJson, setDevJson] = useState({
components: {},
data: {},
});
const [uWebSocket, setUWebSocket] = useState(flags.enableHotReload);

useEffect(() => {
if (uWebSocket) {
const socket = io(flags.bosLoaderWs, {
reconnectionAttempts: 1 // Limit reconnection attempts
});

socket.on('fileChange', (d) => {
console.log('File change detected via WebSocket', d);
setDevJson(d);
});

socket.on('connect_error', () => {
console.warning('WebSocket connection error. Switching to HTTP.');
setUWebSocket(false);
socket.disconnect();
});

return () => {
socket.disconnect();
};
} else {
fetch(flags.bosLoaderUrl)
.then((r) => r.json())
.then((d) => {
console.log('File change detected via HTTP', d);
setDevJson(d);
})
.catch((error) => {
console.error('HTTP request failed:', error);
});
}
}, [uWebSocket]);

return devJson;
const [devJson, setDevJson] = useState({
components: {},
data: {},
});
const [uWebSocket, setUWebSocket] = useState(flags.enableHotReload);

useEffect(() => {
if (uWebSocket) {
const socket = io(flags.bosLoaderWs, {
reconnectionAttempts: 1, // Limit reconnection attempts
});

socket.on("fileChange", (d) => {
console.log("File change detected via WebSocket", d);
setDevJson(d);
});

socket.on("connect_error", () => {
console.warning("WebSocket connection error. Switching to HTTP.");
setUWebSocket(false);
socket.disconnect();
});

return () => {
socket.disconnect();
};
} else {
fetch(flags.bosLoaderUrl)
.then((r) => r.json())
.then((d) => {
console.log("File change detected via HTTP", d);
setDevJson(d);
})
.catch((error) => {
console.error("HTTP request failed:", error);
});
}
}, [uWebSocket]);

return devJson;
}


export default useRedirectMap;
12 changes: 6 additions & 6 deletions gateway/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ module.exports = function (env) {
}),
new HTMLWebpackPlugin({
template: `${paths.publicPath}/index.html`,
publicPath: process.env.PUBLIC_PATH ?? '/',
minify: false
publicPath: process.env.PUBLIC_PATH ?? "/",
minify: false,
}),
new HTMLWebpackPlugin({
template: `${paths.publicPath}/index.html`,
filename: '404.html',
publicPath: process.env.PUBLIC_PATH ?? '/',
minify: false
filename: "404.html",
publicPath: process.env.PUBLIC_PATH ?? "/",
minify: false,
}),
new webpack.ProgressPlugin(),
new webpack.ProvidePlugin({
Expand All @@ -98,6 +98,6 @@ module.exports = function (env) {
],
},
loadConfig(mode),
loadPreset(env)
loadPreset(env),
);
};
Loading

0 comments on commit 46c3209

Please sign in to comment.