Skip to content

Commit

Permalink
feat: add material design
Browse files Browse the repository at this point in the history
Closes #10
  • Loading branch information
avallete committed Mar 27, 2021
1 parent de163cf commit 2101cc7
Show file tree
Hide file tree
Showing 9 changed files with 1,596 additions and 1,701 deletions.
3,209 changes: 1,543 additions & 1,666 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"js-cookie": "2.2.1",
"lodash.get": "4.4.2",
"preact": "10.5.13",
"preact-material-components": "1.6.1",
"sha1": "1.1.1",
"userscript-metadata": "1.0.0",
"userscripter": "1.4.0"
Expand Down
7 changes: 0 additions & 7 deletions src/components/remove-button.tsx

This file was deleted.

7 changes: 6 additions & 1 deletion src/components/remove-video-enhancer-app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component } from 'preact'
import LinearProgress from 'preact-material-components/LinearProgress'
import U from '~src/userscript'
import RemoveVideoEnhancerContainer from '~components/remove-video-enhancer-container'
import { YTConfigData, Playlist } from '~src/youtube'
Expand Down Expand Up @@ -81,6 +82,10 @@ export default class RemoveVideoEnhancerApp extends Component<Properties, State>
}
return <div id={U.id}>Playlist isn't editable</div>
}
return <div id={U.id}>Loading...</div>
return (
<div id={U.id}>
<LinearProgress indeterminate />
</div>
)
}
}
41 changes: 19 additions & 22 deletions src/components/remove-video-enhancer-container.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { JSX } from 'preact'
import { useState } from 'preact/hooks'
import Button from 'preact-material-components/Button'
import Slider from 'preact-material-components/Slider'
import LinearProgress from 'preact-material-components/LinearProgress'
import U from '~src/userscript'
import RemoveButton from '~components/remove-button'

interface Properties {
removeVideoHandler: (watchTimeValue: number) => Promise<void> | void
Expand All @@ -21,42 +22,38 @@ function validate(value: any): boolean {
return false
}

function RemoveVideoEnhancerContainer({ removeVideoHandler, initialValue = 99 }: Properties) {
function RemoveVideoEnhancerContainer({ removeVideoHandler, initialValue = 100 }: Properties) {
const [inputValue, setValue] = useState(initialValue)
const [isReadyToRemove, setIsReadyToRemove] = useState(true)

function onChange({ currentTarget }: JSX.TargetedEvent<HTMLInputElement, Event>) {
if (validate(currentTarget.value)) {
setValue(Number(currentTarget.value))
} else {
currentTarget.value = inputValue.toString()
function onChange({ detail }: any) {
// eslint-disable-next-line no-underscore-dangle
const value = detail.foundation_.value_
if (validate(value)) {
setValue(value)
}
}

return (
<div id={U.id} className='style-scope ytd-playlist-sidebar-renderer'>
<div className='style-scope ytd-menu-service-item-renderer' role='option' aria-disabled='false'>
<p>Remove all videos who has been watched at more or equal X percent</p>
<input
id='removeVideosEnhancerInput'
type='number'
value={inputValue}
onChange={onChange}
min='0'
max='100'
required
alt={INPUT_ALT}
/>
<RemoveButton
<p>Remove all videos who has been watched at more or equal {inputValue} %</p>
<Slider min={0} max={100} step={5} value={inputValue} onChange={onChange} alt={INPUT_ALT} discrete />
<Button
raised
ripple
secondary
alt={REMOVE_BUTTON_ALT}
disabled={!isReadyToRemove}
id='removeVideosEnhancerButton'
onClick={async () => {
setIsReadyToRemove(false)
await removeVideoHandler(inputValue)
setIsReadyToRemove(true)
}}
/>
>
{!isReadyToRemove && <LinearProgress indeterminate />}
{isReadyToRemove && <div>Remove!</div>}
</Button>
</div>
</div>
)
Expand Down
1 change: 1 addition & 0 deletions src/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import U from './userscript'

export const NAME = U.sitename
export const HOSTNAME = U.hostname
export const APP_ROOT_ID = U.id
export const YT_LOCATION_CHANGE_EVENT: string = 'yt-navigate-finish'
14 changes: 14 additions & 0 deletions src/styles/preact-material.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
##{getGlobal("SITE.APP_ROOT_ID")} {
--mdc-theme-primary: #e10000;
--mdc-theme-on-primary: #fff;
--mdc-theme-accent: #e10000;
--mdc-theme-secondary: #e10000;
--mdc-theme-on-secondary: #fff;
--mdc-theme-background: #fff;
--mdc-theme-surface: #fff;
--mdc-theme-on-surface: #fff;
}

@import '~preact-material-components/Button/style.css';
@import '~preact-material-components/Slider/style.css';
@import '~preact-material-components/LinearProgress/style.css';
11 changes: 9 additions & 2 deletions src/stylesheets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Stylesheets } from 'userscripter/lib/stylesheets'
import { Stylesheets, stylesheet } from 'userscripter/lib/stylesheets'
import preactMaterialStyles from '~src/styles/preact-material.scss'
import isOnPlaylistPage from './operations/conditions/is-on-playlist-page'

const STYLESHEETS = {} as const
const STYLESHEETS = {
preactMaterial: stylesheet({
condition: isOnPlaylistPage,
css: preactMaterialStyles,
}),
} as const

// This trick uncovers type errors in STYLESHEETS
// while retaining the static knowledge of its properties
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"resolveJsonModule": true,
"lib": ["esnext", "dom"],
"jsx": "react-jsx",
"jsxImportSource": "preact"
"jsxImportSource": "preact",
"skipLibCheck": true
},
"include": [
"./src/*.d.ts",
"./src/**/*.tsx",
"./src/**/*.ts",
"./test/**/*.ts",
"./test/**/*.tsx",
"./metadata-config.json",
"test/remove-button.test.ts"
"./metadata-config.json"
]
}

0 comments on commit 2101cc7

Please sign in to comment.