tlater/nix-flake-rework #2

Manually merged
tlater merged 5 commits from tlater/nix-flake-rework into master 2021-04-07 23:34:18 +01:00
10 changed files with 52 additions and 46 deletions
Showing only changes of commit 7d028fdebd - Show all commits

View file

@ -33,7 +33,8 @@
"off" "off"
], ],
"no-unused-vars": [ "no-unused-vars": [
"warn" "warn",
{ "argsIgnorePattern": "^_" }
] ]
} }
} }

View file

@ -1,4 +1,4 @@
import $ from "jquery"; import jQuery from "jquery";
// Helpers // Helpers
@ -113,7 +113,7 @@ class Typer {
} }
} }
$(document).ready(() => { jQuery(($) => {
let typer = new Typer($(".head-line .typed").get(0), 500, 3000); const typer = new Typer($(".head-line .typed").get(0), 500, 3000);
typer.type(); typer.type();
}); });

View file

@ -1,3 +1,3 @@
import $ from "jquery"; import jQuery from "jquery";
$(document).ready(() => $("html").removeClass("no-js")); jQuery(($) => $("html").removeClass("no-js"));

View file

@ -18,16 +18,16 @@ type MusicPlayerProps = {
source?: string; source?: string;
}; };
class MusicPlayer extends React.Component<MusicPlayerProps, {}> { class MusicPlayer extends React.Component<MusicPlayerProps, State> {
private audioState: AudioState; private audioState: AudioState;
constructor(props: MusicPlayerProps) { constructor(props: MusicPlayerProps) {
super(props); super(props);
let context = new AudioContext(); const context = new AudioContext();
let source = new Audio(); const source = new Audio();
let sourceNode = context.createMediaElementSource(source); const sourceNode = context.createMediaElementSource(source);
let volume = context.createGain(); const volume = context.createGain();
sourceNode.connect(volume); sourceNode.connect(volume);
volume.connect(context.destination); volume.connect(context.destination);
@ -53,9 +53,9 @@ class MusicPlayer extends React.Component<MusicPlayerProps, {}> {
} }
componentDidUpdate() { componentDidUpdate() {
let context = this.audioState.audioContext; const context = this.audioState.audioContext;
let source = this.audioState.audioSource; const source = this.audioState.audioSource;
let volume = this.audioState.audioVolume; const volume = this.audioState.audioVolume;
// First, set the audio source (if it changed) // First, set the audio source (if it changed)
if (this.props.source && source.src != this.props.source) { if (this.props.source && source.src != this.props.source) {

View file

@ -1,16 +1,15 @@
import React from "react"; import React from "react";
import Redux from "redux";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { State } from "../store"; import { State } from "../store";
import { Title, togglePlay } from "../store/music/types"; import { Title } from "../store/music/types";
import Indicator from "./indicator"; import Indicator from "./indicator";
type ControlProps = { type ControlProps = {
title: Title; title: Title;
}; };
class Controls extends React.Component<ControlProps, {}> { class Controls extends React.Component<ControlProps, State> {
render() { render() {
return ( return (
<div id="playerControls" className="container-fluid fixed-bottom"> <div id="playerControls" className="container-fluid fixed-bottom">

View file

@ -2,8 +2,8 @@ import React from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import classNames from "classnames"; import classNames from "classnames";
import { State } from "../store"; import { Dispatch, State } from "../store";
import { MusicState, togglePlay } from "../store/music/types"; import { togglePlay } from "../store/music/types";
type IndicatorProps = { type IndicatorProps = {
muted: boolean; muted: boolean;
@ -16,13 +16,13 @@ type IndicatorDispatch = {
type Props = IndicatorProps & IndicatorDispatch; type Props = IndicatorProps & IndicatorDispatch;
class Indicator extends React.Component<Props, {}> { class Indicator extends React.Component<Props, State> {
click() { click() {
this.props.play(); this.props.play();
} }
render() { render() {
let classes = classNames({ const classes = classNames({
btn: true, btn: true,
"col-auto": true, "col-auto": true,
fas: true, fas: true,
@ -49,7 +49,7 @@ function mapStateToProps(state: State): IndicatorProps {
}; };
} }
function mapDispatchToProps(dispatch: Redux.Dispatch<any>): IndicatorDispatch { function mapDispatchToProps(dispatch: Dispatch): IndicatorDispatch {
return { return {
play: () => { play: () => {
dispatch(togglePlay()); dispatch(togglePlay());

View file

@ -1,6 +1,8 @@
import React from "react"; import React from "react";
import * as three from "three"; import * as three from "three";
import { State } from "../store";
type VisualizerProps = { type VisualizerProps = {
audioContext: AudioContext; audioContext: AudioContext;
audioSource: AudioNode; audioSource: AudioNode;
@ -13,8 +15,8 @@ class CanvasDrawer {
private analyserData: Float32Array; private analyserData: Float32Array;
private boxes: Array<three.Mesh>; private boxes: Array<three.Mesh>;
private camera: three.Camera; private camera: three.PerspectiveCamera;
private renderer: three.Renderer; private renderer: three.WebGLRenderer;
private scene: three.Scene; private scene: three.Scene;
private angle: number; private angle: number;
@ -34,13 +36,13 @@ class CanvasDrawer {
// Make a bunch of boxes to represent the bars // Make a bunch of boxes to represent the bars
this.boxes = Array(analyser.frequencyBinCount); this.boxes = Array(analyser.frequencyBinCount);
let width = 2 / analyser.frequencyBinCount; const width = 2 / analyser.frequencyBinCount;
for (let freq = 0; freq < analyser.frequencyBinCount; freq++) { for (let freq = 0; freq < analyser.frequencyBinCount; freq++) {
let geometry = new three.BoxGeometry(1, 1, 1); const geometry = new three.BoxGeometry(1, 1, 1);
let material = new three.MeshLambertMaterial({ const material = new three.MeshLambertMaterial({
color: new three.Color(0x99d1ce), color: new three.Color(0x99d1ce),
}); });
let cube = new three.Mesh(geometry, material); const cube = new three.Mesh(geometry, material);
cube.scale.set(width, 1e-6, width); cube.scale.set(width, 1e-6, width);
cube.position.set(-1 + freq * width, 0, 0); cube.position.set(-1 + freq * width, 0, 0);
@ -50,10 +52,10 @@ class CanvasDrawer {
} }
// Add lights for shadowing // Add lights for shadowing
let ambientLight = new three.AmbientLight(0xffffff, 0.4); const ambientLight = new three.AmbientLight(0xffffff, 0.4);
this.scene.add(ambientLight); this.scene.add(ambientLight);
let directionalLight = new three.DirectionalLight(0xffffff, 1); const directionalLight = new three.DirectionalLight(0xffffff, 1);
directionalLight.position.set(-1, 0.3, -1); directionalLight.position.set(-1, 0.3, -1);
directionalLight.castShadow = true; directionalLight.castShadow = true;
this.scene.add(directionalLight); this.scene.add(directionalLight);
@ -94,12 +96,12 @@ class CanvasDrawer {
// Set our animation frame to 0, so that if we stop, we don't try to cancel a past animation frame // Set our animation frame to 0, so that if we stop, we don't try to cancel a past animation frame
this.animationFrame = 0; this.animationFrame = 0;
// Update elapsed time // Update elapsed time
let elapsed = time - this.lastTime; const elapsed = time - this.lastTime;
this.lastTime = time; this.lastTime = time;
let camera = this.camera; const camera = this.camera;
let renderer = this.renderer; const renderer = this.renderer;
let scene = this.scene; const scene = this.scene;
this.scaleBoxes(); this.scaleBoxes();
this.rotateCamera(elapsed); this.rotateCamera(elapsed);
@ -109,7 +111,7 @@ class CanvasDrawer {
} }
scaleBoxes() { scaleBoxes() {
let analyser = this.analyser; const analyser = this.analyser;
analyser.getFloatFrequencyData(this.analyserData); analyser.getFloatFrequencyData(this.analyserData);
@ -133,8 +135,8 @@ class CanvasDrawer {
this.angle += 0.1 * (elapsed / 1000); this.angle += 0.1 * (elapsed / 1000);
} }
let camera = this.camera; const camera = this.camera;
let angle = this.angle; const angle = this.angle;
camera.position.x = 1.01 * Math.sin(angle); camera.position.x = 1.01 * Math.sin(angle);
camera.position.z = 1.01 * Math.cos(angle); camera.position.z = 1.01 * Math.cos(angle);
@ -144,7 +146,7 @@ class CanvasDrawer {
} }
resize() { resize() {
let canvas = this.canvas; const canvas = this.canvas;
if (canvas.parentElement === null) { if (canvas.parentElement === null) {
throw Error("Could not access canvas parent for size calculation"); throw Error("Could not access canvas parent for size calculation");
} }
@ -160,7 +162,7 @@ class CanvasDrawer {
} }
// The remaining space we want to fill // The remaining space we want to fill
let remainingHeight = canvas.parentElement.clientHeight - combinedHeight; const remainingHeight = canvas.parentElement.clientHeight - combinedHeight;
canvas.height = remainingHeight; canvas.height = remainingHeight;
canvas.width = canvas.parentElement.clientWidth; canvas.width = canvas.parentElement.clientWidth;
@ -176,7 +178,7 @@ class CanvasDrawer {
} }
} }
class Visualizer extends React.Component<VisualizerProps, {}> { class Visualizer extends React.Component<VisualizerProps, State> {
private analyser: AnalyserNode; private analyser: AnalyserNode;
private canvas: React.RefObject<HTMLCanvasElement>; private canvas: React.RefObject<HTMLCanvasElement>;
private drawer: CanvasDrawer; private drawer: CanvasDrawer;
@ -186,7 +188,7 @@ class Visualizer extends React.Component<VisualizerProps, {}> {
this.canvas = React.createRef(); this.canvas = React.createRef();
} }
render() { render(): React.ReactNode {
return ( return (
<canvas <canvas
id="visualizer" id="visualizer"
@ -196,7 +198,7 @@ class Visualizer extends React.Component<VisualizerProps, {}> {
); );
} }
componentDidMount() { componentDidMount(): void {
if (this.canvas.current === null) { if (this.canvas.current === null) {
throw Error("Failed to create canvas; aborting"); throw Error("Failed to create canvas; aborting");
} }
@ -209,7 +211,7 @@ class Visualizer extends React.Component<VisualizerProps, {}> {
this.drawer = new CanvasDrawer(this.analyser, this.canvas.current); this.drawer = new CanvasDrawer(this.analyser, this.canvas.current);
} }
componentWillUnmount() { componentWillUnmount(): void {
this.drawer.stop(); this.drawer.stop();
this.props.audioSource.disconnect(this.analyser); this.props.audioSource.disconnect(this.analyser);
} }

View file

@ -5,6 +5,7 @@ import { Provider } from "react-redux";
import { store } from "./store"; import { store } from "./store";
import MusicPlayer from "./MusicPlayer"; import MusicPlayer from "./MusicPlayer";
import { setSource, setTitle } from "./store/music/types"; import { setSource, setTitle } from "./store/music/types";
// @ts-ignore - mp3 files have no types.
import mseq from "./Mseq_-_Journey.mp3"; import mseq from "./Mseq_-_Journey.mp3";
const rootElement = document.getElementById("playerUI"); const rootElement = document.getElementById("playerUI");

View file

@ -13,5 +13,8 @@ const rootReducer = combineReducers<State>({
export const store = createStore( export const store = createStore(
rootReducer, rootReducer,
// @ts-ignore - These properties are set by the devtools extension
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
); );
export type Dispatch = typeof store.dispatch;

View file

@ -18,11 +18,11 @@ export interface MusicState {
source?: string; source?: string;
} }
export const setTitle: (title: Title) => Action<null, null> = createAction( export const setTitle: (_title: Title) => Action<null, null> = createAction(
"set currently playing title" "set currently playing title"
); );
export const setPlayTime: (time: number) => Action<null, null> = createAction( export const setPlayTime: (_time: number) => Action<null, null> = createAction(
"set the play time" "set the play time"
); );
@ -30,6 +30,6 @@ export const toggleMute: () => Action<null, null> = createAction("toggle mute");
export const togglePlay: () => Action<null, null> = createAction("toggle play"); export const togglePlay: () => Action<null, null> = createAction("toggle play");
export const setSource: (source: string) => Action<null, null> = createAction( export const setSource: (_source: string) => Action<null, null> = createAction(
"set the title" "set the title"
); );