Skip to content

Commit

Permalink
Add progress indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Apr 9, 2023
1 parent 8c66b2d commit baf720c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
"dependencies": {
"@arethetypeswrong/core": "file:../core",
"immer": "^9.0.21",
"nprogress": "^0.2.0",
"validate-npm-package-name": "^5.0.0"
},
"devDependencies": {
"@types/nprogress": "^0.2.0",
"@types/validate-npm-package-name": "^4.0.0",
"esbuild": "^0.17.4",
"vite": "^4.0.4"
Expand Down
9 changes: 9 additions & 0 deletions packages/web/src/main.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import url("nprogress/nprogress.css");

:root {
--color-bg: #fff;
--color-text-primary: rgba(0, 0, 0, 1);
Expand Down Expand Up @@ -130,3 +132,10 @@ td {
.display-none {
display: none;
}

#nprogress .peg {
box-shadow: none;
}
#nprogress .bar {
background: var(--color-link);
}
12 changes: 12 additions & 0 deletions packages/web/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ResultMessage } from "../worker/worker.ts";
import { subscribeRenderer } from "./renderer.ts";
import { updateState, type PackageInfo, type ParsedPackageSpec, getState, subscribe, type State } from "./state.ts";
import { shallowEqual } from "./utils/shallowEqual.ts";
import NProgress from "nprogress";

// Good grief https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
const semverRegex =
Expand All @@ -28,6 +29,8 @@ worker.onmessage = async (event: MessageEvent<ResultMessage>) => {
}
};

NProgress.configure({ showSpinner: false });

subscribeRenderer({
onPackageNameInput,
onCheck,
Expand All @@ -40,6 +43,15 @@ subscribeRenderer({

subscribe(debounce(getPackageInfo, 300));

subscribe((prevState) => {
const state = getState();
if (state.isLoading && !prevState.isLoading) {
NProgress.start();
} else if (!state.isLoading && prevState.isLoading) {
NProgress.done();
}
});

if (location.search) {
const packageNameInput = document.getElementById("package-spec") as HTMLInputElement;
const params = new URLSearchParams(location.search);
Expand Down

0 comments on commit baf720c

Please sign in to comment.