Skip to content

Commit

Permalink
fix: port to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa committed Nov 15, 2021
1 parent 9263b63 commit c120d72
Show file tree
Hide file tree
Showing 27 changed files with 14,713 additions and 11,325 deletions.
14 changes: 0 additions & 14 deletions .babelrc

This file was deleted.

6 changes: 4 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ module.exports = {
env: {
browser: true
// es2020: true,
// node: true
},
extends: [
'eslint:recommended',
'semistandard',
'prettier:recommended',
'prettier:recat',
'plugin:react/recommended'
],
settings: {
Expand All @@ -17,6 +17,7 @@ module.exports = {
}
},
rules: {
/*
'brace-style': ['error', '1tbs'],
'no-return-assign': 'off',
'no-var': ['error'],
Expand All @@ -28,5 +29,6 @@ module.exports = {
eqeqeq: 'off',
'import/no-absolute-path': 'off',
'react/prop-types': 'off' // TODO: Enable this
*/
}
};
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"arrowParens" : "avoid",
"singleQuote" : true
}
3 changes: 0 additions & 3 deletions .stylelintrc.json

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
gtag('config', window.GA_TRACKING_ID);
</script>

<script type="module" src="/js/index.js"></script>
<script type="module" src="/js/index.tsx"></script>
<script>
window.addEventListener('DOMContentLoaded', function() {
// Detect load failure. `indexLoaded` gets set by index.js if it loads properly
Expand Down
2 changes: 1 addition & 1 deletion js/App.js → js/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Splitter({ onClick, isOpen }) {

// Parse `q` query param from browser location
function queryFromLocation() {
const q = new URL(location).searchParams.get('q');
const q = new URL(location.href).searchParams.get('q');
return (q ?? '').split(',').map(v => v.trim()).filter(Boolean);
}

Expand Down
73 changes: 0 additions & 73 deletions js/Components.js

This file was deleted.

95 changes: 95 additions & 0 deletions js/Components.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import React, { HTMLAttributes } from 'react';
import { LoadActivity } from './util';
import '/css/Components.scss';

export function Loader({
activity,
...props
}: { activity: LoadActivity } & HTMLAttributes<HTMLDivElement>) {
return (
<div className="loader">
<div className="bg" />
{activity.title} ...
</div>
);
}

export function Toggle({
checked = false,
value = true,
onChange,
style,
children,
...props
}: HTMLAttributes<HTMLInputElement>) {
return (
<label style={style} {...props}>
<div
onClick={() => onChange(checked ? false : value)}
style={{
display: 'inline-block',
width: '4em',
backgroundColor: '#ccc',
borderRadius: '.5em',
marginRight: '.5em',
}}
>
<div
style={{
width: '3em',
borderRadius: '.5em',
textAlign: 'center',
transition: '.15s',
marginLeft: checked ? '0' : '1em',
backgroundColor: checked ? '#090' : '#aaa',
color: '#fff',
}}
>
{checked ? 'On' : 'Off'}
</div>
</div>
{children}
</label>
);
}

export function Flash(o, bg = '#f80') {
const SPACE = 10;

const graph = document.querySelector('#graph') as HTMLDivElement;
const prev = document.querySelector('.flash:last-of-type') as HTMLElement;
const el = document.createElement('div');

if (o instanceof Error) {
el.classList.add('error');
el.innerText = o.message;
} else if (o instanceof Document) {
el.append.apply(el, o.querySelector('body').children);
} else if (o instanceof Element || o instanceof DocumentFragment) {
el.append(o);
} else if (typeof o == 'string') {
el.innerText = o;
} else {
el.innerText = JSON.stringify(o, null, 2);
}

document.body.appendChild(el);
el.classList.add('flash');
const prevBottom = prev ? prev.offsetTop + prev.offsetHeight : 0;

const top =
prevBottom < window.innerHeight - el.offsetHeight ? prevBottom : 0;
el.style.top = `${top + SPACE / 2}px`;
el.style.left = `${-el.offsetWidth - SPACE}px`;
el.style.maxWidth = graph ? `${graph.offsetWidth - SPACE}px` : '100%';
el.style.backgroundColor = bg;

setTimeout(() => {
el.style.left = `${SPACE}px`;

setTimeout(() => {
el.addEventListener('transitionend', () => el.remove());
el.style.left = `${-el.offsetWidth - SPACE}px`;
}, 5e3);
}, 0);
}

0 comments on commit c120d72

Please sign in to comment.