mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-13 17:27:09 +00:00
* Add filename to the document.title * minor fixes * no-space-before-colon
This commit is contained in:
@@ -162,6 +162,8 @@ const resultTitles = ['Top', 'Bottom'];
|
|||||||
const buttonPositions =
|
const buttonPositions =
|
||||||
['download-left', 'download-right'] as ('download-left' | 'download-right')[];
|
['download-left', 'download-right'] as ('download-left' | 'download-right')[];
|
||||||
|
|
||||||
|
const originalDocumentTitle = document.title;
|
||||||
|
|
||||||
export default class Compress extends Component<Props, State> {
|
export default class Compress extends Component<Props, State> {
|
||||||
widthQuery = window.matchMedia('(max-width: 599px)');
|
widthQuery = window.matchMedia('(max-width: 599px)');
|
||||||
|
|
||||||
@@ -226,12 +228,22 @@ export default class Compress extends Component<Props, State> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private updateDocumentTitle(filename: string = '') {
|
||||||
|
const newTitle: string = filename ? `${filename} - ${originalDocumentTitle}` : originalDocumentTitle;
|
||||||
|
|
||||||
|
document.title = newTitle;
|
||||||
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps: Props): void {
|
componentWillReceiveProps(nextProps: Props): void {
|
||||||
if (nextProps.file !== this.props.file) {
|
if (nextProps.file !== this.props.file) {
|
||||||
this.updateFile(nextProps.file);
|
this.updateFile(nextProps.file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillUnmount(): void {
|
||||||
|
this.updateDocumentTitle();
|
||||||
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps: Props, prevState: State): void {
|
componentDidUpdate(prevProps: Props, prevState: State): void {
|
||||||
const { source, images } = this.state;
|
const { source, images } = this.state;
|
||||||
|
|
||||||
@@ -328,6 +340,7 @@ export default class Compress extends Component<Props, State> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.updateDocumentTitle(file.name);
|
||||||
this.setState(newState);
|
this.setState(newState);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.name === 'AbortError') return;
|
if (err.name === 'AbortError') return;
|
||||||
|
|||||||
Reference in New Issue
Block a user