Skip to content

Commit

Permalink
Redo darkmode using MUI's latest CSS variables approach. MUI does mor…
Browse files Browse the repository at this point in the history
…e of the work, no need to pass darkMode around.
  • Loading branch information
rewbs committed Jul 20, 2023
1 parent 755c2ab commit c60e2ae
Show file tree
Hide file tree
Showing 25 changed files with 425 additions and 309 deletions.
10 changes: 3 additions & 7 deletions src/Analyser.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Alert, Box, Button, InputAdornment, MenuItem, Slider, Stack, TextField, Typography } from "@mui/material";
import CssBaseline from '@mui/material/CssBaseline';
import { Link, Alert, Box, Button, InputAdornment, MenuItem, Slider, Stack, TextField, Typography } from "@mui/material";
import Grid from '@mui/material/Unstable_Grid2';
import { PitchMethod } from "aubiojs";
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useSearchParams } from "react-router-dom";
import { WaveForm, WaveSurfer } from "wavesurfer-react";
import Header from './components/Header';
import LinearWithValueLabel from "./components/LinearProgressWithLabel";
//@ts-ignore
import TimelinePlugin from "wavesurfer.js/dist/plugin/wavesurfer.timeline.min";
Expand Down Expand Up @@ -625,7 +623,6 @@ export default function Analyser() {
}

return <>
<Header title="Parseq - audio analyser (Legacy)" />
<Grid container paddingLeft={5} paddingRight={5} spacing={2} sx={{
'--Grid-borderWidth': '1px',
borderTop: 'var(--Grid-borderWidth) solid',
Expand All @@ -638,14 +635,13 @@ export default function Analyser() {
borderColor: 'divider',
},
}}>
<CssBaseline />
<Grid xs={12}>
<a href={'/' + (searchParams.get('refDocId') ? '?docId=' + searchParams.get('refDocId') : '')}>⬅️ Home</a>
<Link href={'/' + (searchParams.get('refDocId') ? '?docId=' + searchParams.get('refDocId') : '')}>⬅️ Home</Link>
<small>
<ul>
<li><strong>This legacy audio analyser is deprecated and will eventually be removed.</strong> All its functionality is now integrated into the main Parseq UI.</li>
<li>⚠️ This feature is experimental. That's why it's quite separate from the main Parseq UI for now. The keyframes generated here can be merged into an existing Parseq document using the "Merge keyframes" button in the main UI.</li>
<li>Tempo, onset event and pitch detection use <a href="https://aubio.org/">Aubio</a>, via <a href="https://github.com/qiuxiang/aubiojs">AubioJS</a>. See the <a href="https://aubio.org/manual/latest/cli.html"> Aubio CLI documentation</a> for the meaning of all parameters.</li>
<li>Tempo, onset event and pitch detection use <Link href="https://aubio.org/">Aubio</Link>, via <Link href="https://github.com/qiuxiang/aubiojs">AubioJS</Link>. See the <Link href="https://aubio.org/manual/latest/cli.html"> Aubio CLI documentation</Link> for the meaning of all parameters.</li>
<li>Not all parameters are exposed by AubioJS. Some look like they should be, but aren't (those are grayed out here).</li>
<li>All processing runs in the browser, using web workers. This seems to be faster in Chrome and Safari compared to Firefox. You can speed things up by increasing the hop sizes to larger multiples of 2 (trading off accuracy).</li>
<li>Expects a constant Tempo. Tempo detection is not perfect, so you can override it before generating keyframes. If the first beat is not at the very beginning of the track, you will need to enter a manual offset for now. </li>
Expand Down
44 changes: 40 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
import { CssBaseline, GlobalStyles } from "@mui/material";
import { Experimental_CssVarsProvider as CssVarsProvider, experimental_extendTheme as extendTheme } from "@mui/material/styles";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import Analyser from "./Analyser";
import Browser from "./Browser";
import Deforum from "./Deforum";
import FunctionDoc from "./FunctionDoc";
import Labs from "./Labs";
import Raw from "./Raw";
import Header from "./components/Header";
import { themeFactory } from "./theme";

const App = () => {
return <>
<Header title="Parseq Legacy – deprecated" />
<a href="/">Go home.</a>
</>;

const theme = extendTheme(themeFactory());

return <CssVarsProvider theme={theme}>
<CssBaseline />
<GlobalStyles
styles={{
code: {
fontFamily: "source-code-pro, Menlo, Monaco, Consolas, 'Courier New',monospace",
background: theme.vars.palette.codeBackground.main,
wordWrap: "break-word",
boxDecorationBreak: "clone",
padding: ".1rem .1rem .1rem",
borderRadius: ".2rem"
}
}}
/>
<BrowserRouter>
<Header />
<Routes>
<Route path="/" element={<Deforum />} />
<Route path="/deforum" element={<Deforum />} />
<Route path="/browser" element={<Browser />} />
<Route path="/analyser" element={<Analyser />} />
<Route path="/labs" element={<Labs />} />
<Route path="/raw" element={<Raw />} />
<Route path="/functionDocs" element={<FunctionDoc />} />
</Routes>
</BrowserRouter>
</CssVarsProvider>;
};

export default App;
24 changes: 10 additions & 14 deletions src/Browser.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Alert, Box, Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Stack, Tab, Tabs, Tooltip, Typography } from '@mui/material';
import { Alert, Box, Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Link, Stack, Tab, Tabs, Tooltip, Typography } from '@mui/material';
import Paper from '@mui/material/Paper';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
Expand All @@ -9,27 +9,24 @@ import TableRow from '@mui/material/TableRow';

import { faBroom, faCopy, faDownload, faTrash, faUpload } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import CssBaseline from '@mui/material/CssBaseline';
import Grid from '@mui/material/Unstable_Grid2';
import { ImportOptions, exportDB, importInto, peakImportFile } from "dexie-export-import";
import { useLiveQuery } from "dexie-react-hooks";
import { saveAs } from 'file-saver';
import _ from 'lodash';
import { useCallback, useEffect, useMemo, useState } from 'react';
import prettyBytes from 'pretty-bytes';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { useSearchParams } from "react-router-dom";
import ReactTimeAgo from 'react-time-ago';
import { useEffectOnce } from 'react-use';
import { AdvancedParseqPrompt, AdvancedParseqPromptsV2, DocId, ParseqDoc, ParseqDocVersion, VersionId } from './ParseqUI';
import Header from './components/Header';
import LinearProgressWithLabel from './components/LinearProgressWithLabel';
import { convertPrompts } from './components/Prompts';
import { SmallTextField } from './components/SmallTextField';
import { TabPanel } from './components/TabPanel';
import { db } from './db';
import { isStoragePersisted, showEstimatedQuota, persist } from './persistance';
import { isStoragePersisted, persist, showEstimatedQuota } from './persistance';
import { navigateToClone, smartTrim } from './utils/utils';
import prettyBytes from 'pretty-bytes';
import React from 'react';
import { convertPrompts } from './components/Prompts';

function VersionCount({ docId }: { docId: DocId }) {
const [versionCount, setVersionCount] = useState(<Typography>loading...</Typography>);
Expand Down Expand Up @@ -267,11 +264,10 @@ export default function Browser() {


return <React.StrictMode>
<Header title="Parseq - local storage browser" />
<Grid container paddingLeft={5} paddingRight={5} spacing={2}>
<CssBaseline />

<Grid xs={12}>
<a href={'/' + (searchParams.get('refDocId') ? '?docId=' + searchParams.get('refDocId') : '')}>⬅️ Home</a>
<Link href={'/' + (searchParams.get('refDocId') ? '?docId=' + searchParams.get('refDocId') : '')}>⬅️ Home</Link>
</Grid>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs value={activeTab} onChange={(_, newValue) => setActiveTab(newValue)}>
Expand All @@ -293,7 +289,7 @@ export default function Browser() {
<Grid xs={12}>
<ul>
<li>Showing {selectedDocVersions?.length} versions for document: <strong>{selectedDocVersions[0]?.docName}</strong></li>
<li><a href={'/Browser?refDocId=' + searchParams.get('refDocId')} >Back to recent docs</a></li>
<li><Link href={'/Browser?refDocId=' + searchParams.get('refDocId')} >Back to recent docs</Link></li>
</ul>
</Grid>
<Grid xs={12}>
Expand Down Expand Up @@ -405,7 +401,7 @@ export default function Browser() {
mostRecentVersions.map((v: VersionSummary) => {
return <TableRow>
<TableCell>
<a href={'/?docId=' + v.docId}>{v.docName}</a>
<Link href={'/?docId=' + v.docId}>{v.docName}</Link>
<Typography fontSize={"0.5em"} fontStyle={'monospace'}>{v.docId}</Typography>
</TableCell>
<TableCell>
Expand All @@ -421,7 +417,7 @@ export default function Browser() {
}
</TableCell>
<TableCell>{v.timeSeriesNames?.length}</TableCell>
<TableCell><VersionCount docId={v.docId} /><a href={'/browser?refDocId=' + searchParams.get('refDocId') + '&selectedDocId=' + v.docId}>show</a></TableCell>
<TableCell><VersionCount docId={v.docId} /><Link href={'/browser?refDocId=' + searchParams.get('refDocId') + '&selectedDocId=' + v.docId}>show</Link></TableCell>
</TableRow>
}) : <></>

Expand Down
41 changes: 3 additions & 38 deletions src/Deforum.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,12 @@
import React, { useCallback, useMemo, useState } from "react";
import Header from "./components/Header";
import ParseqUI from './ParseqUI';
import {createTheme, ThemeOptions, ThemeProvider} from '@mui/material/styles';
import { useMediaQuery } from "@mui/material";
import { UserSettings } from "./UserSettings";

const Deforum = () => {

const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)');
const [darkMode, setDarkMode] = useState(prefersDarkMode);
const theme = useMemo(() => createTheme(themeFactory(darkMode)), [darkMode]);
const updateDarkMode = useCallback((darkMode: boolean) => {
setDarkMode(darkMode);
UserSettings.setDarkMode(darkMode);
}, []);

// Retrieve dark mode setting from local db
UserSettings.getDarkMode().then((darkMode) => {
if (darkMode !== undefined) {
setDarkMode(darkMode);
}
});

return (<ThemeProvider theme={theme}>
<Header title="Parseq for Deforum" darkMode={darkMode} updateDarkMode={updateDarkMode} />

return (<>
{/* @ts-ignore */}
<ParseqUI
defaultTemplate='catduck'
darkMode={darkMode} />

</ThemeProvider>)
defaultTemplate='catduck'/>
</>)
}

export default Deforum;

function themeFactory(darkMode: boolean): ThemeOptions {
return {
palette: {
mode: darkMode ? 'dark' : 'light',
background: {
default: darkMode ? '#252525' : '#fff',
}
}
}
}
17 changes: 11 additions & 6 deletions src/DocManager.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Alert, Autocomplete, Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Divider, FormControlLabel, Radio, RadioGroup, Stack, TextField, Tooltip, Typography } from '@mui/material';
/* eslint-disable react/jsx-no-target-blank */
import { Alert, Autocomplete, Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Divider, FormControlLabel, Link, Radio, RadioGroup, Stack, TextField, Tooltip, Typography } from '@mui/material';
import CircularProgress from '@mui/material/CircularProgress';
import Grid from '@mui/material/Unstable_Grid2';
import { useLiveQuery } from "dexie-react-hooks";
Expand All @@ -19,6 +20,8 @@ import _ from 'lodash';
import { DocId, ParseqDoc, ParseqDocVersion, ParseqPersistableState, VersionId } from './ParseqUI';
import { useUserAuth } from "./UserAuthContext";
import { navigateToClone, navigateToDocId, navigateToTemplateId } from './utils/utils';
import { experimental_extendTheme as extendTheme } from "@mui/material/styles";
import { themeFactory } from "./theme";

export const makeDocId = (): DocId => "doc-" + uuidv4() as DocId
const makeVersionId = (): VersionId => "version-" + uuidv4() as VersionId
Expand Down Expand Up @@ -104,6 +107,7 @@ export function DocManagerUI({ docId, onLoadContent, lastSaved }: MyProps) {
const [parseqShareUrl, setParseqShareUrl] = useState("");
const [uploadStatus, setUploadStatus] = useState(defaultUploadStatus);
const [loadingStatus, setLoadingStatus] = useState(false);
const theme = extendTheme(themeFactory());

//@ts-ignore - this type check is too deep down for me to figure out right now.
const { user } = useUserAuth();
Expand Down Expand Up @@ -185,7 +189,7 @@ export function DocManagerUI({ docId, onLoadContent, lastSaved }: MyProps) {
}
</TextField>
<Typography fontSize={"0.75em"}>
Explore versions of this doc in the <a href={`/browser?refDocId=${activeDoc.docId}&activeDoc.docIdselectedDocId=${activeDoc.docId}`} target='_blank' rel="noreferrer">browser</a>.
Explore versions of this doc in the <Link href={`/browser?refDocId=${activeDoc.docId}&activeDoc.docIdselectedDocId=${activeDoc.docId}`} target='_blank' rel="noopener">browser</Link>.
</Typography>
</DialogContent>
<DialogActions>
Expand Down Expand Up @@ -360,7 +364,7 @@ export function DocManagerUI({ docId, onLoadContent, lastSaved }: MyProps) {
}

/>
<Typography paddingTop="5px" fontSize="0.6em">Remember the prompt but not the doc name? Try the <a href={'/browser?refDocId=' + activeDoc.docId} target='_blank' rel="noreferrer">browser</a>.</Typography>
<Typography paddingTop="5px" fontSize="0.6em">Remember the prompt but not the doc name? Try the <Link href={'/browser?refDocId=' + activeDoc.docId} target='_blank' rel="noopener">browser</Link>.</Typography>
</Grid>
<Grid xs={2} sx={{ display: 'flex', justifyContent: 'right', alignItems: 'end' }}>
<Button size="small" disabled={!selectedDocForLoad} variant="contained" id="load" onClick={handleCloseLoadDialog}>⬇️ Load</Button>
Expand Down Expand Up @@ -430,7 +434,7 @@ export function DocManagerUI({ docId, onLoadContent, lastSaved }: MyProps) {
if (matchRes && matchRes[1]) {
setParseqShareUrl(window.location.href.replace(window.location.search, '') + `?importRemote=${matchRes[1]}&token=${token}`);
setUploadStatus(<Alert severity="success">
<p>Upload <a href={url}>successful</a>. Share the URL above to load it directly into Parseq on another system.</p>
<p>Upload <Link href={url}>successful</Link>. Share the URL above to load it directly into Parseq on another system.</p>
</Alert>);
} else {
setUploadStatus(<Alert severity="error">Unexpected response path: {url}</Alert>);
Expand Down Expand Up @@ -523,7 +527,8 @@ export function DocManagerUI({ docId, onLoadContent, lastSaved }: MyProps) {
value={editingDocName}
InputProps={{
style: { fontSize: '0.75em' },
sx: { background: (editingDocName !== activeDoc.name) ? 'ivory' : '', },
//@ts-ignore
sx: { background: (editingDocName !== activeDoc.name) ? theme.vars.palette.unsavedbg.main : '', },
endAdornment: (editingDocName !== activeDoc.name) ? '🖊️' : ''
}}
size="small"
Expand Down Expand Up @@ -557,7 +562,7 @@ export function DocManagerUI({ docId, onLoadContent, lastSaved }: MyProps) {
<Button size="small" variant="outlined" onClick={handleClickOpenLoadDialog} >⬇️&nbsp;Load...</Button>
<Button size="small" variant="outlined" onClick={handleClickOpenNewDialog} >🆕&nbsp;New...</Button>
<Tooltip title="Explore your Parseq documents.">
<Button size="small" variant="outlined" href={'/browser?refDocId=' + activeDoc.docId} target='_blank' rel="noreferrer">🔎&nbsp;Browse...</Button>
<Button size="small" variant="outlined" href={'/browser?refDocId=' + activeDoc.docId} target='_blank' rel="noopener">🔎&nbsp;Browse...</Button>
</Tooltip>
</Stack>
</Stack>
Expand Down
Loading

0 comments on commit c60e2ae

Please sign in to comment.