Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: migrate deprecated componentWillReceiveProps to componentDidUpdate#798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
18vikastg wants to merge1 commit intoalgorithm-visualizer:master
base:master
Choose a base branch
Loading
from18vikastg:fix/deprecated-lifecycle-methods
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletionssrc/components/App/index.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,6 +54,23 @@ class App extends BaseComponent {
.catch(this.handleError);

this.toggleHistoryBlock(true);

// Load saved workspace preferences
const savedNavigatorOpened = localStorage.getItem('navigatorOpened');
if (savedNavigatorOpened !== null) {
const isOpened = JSON.parse(savedNavigatorOpened);
this.toggleNavigatorOpened(isOpened);
}

const savedWeights = localStorage.getItem('workspaceWeights');
if (savedWeights) {
try {
const weights = JSON.parse(savedWeights);
this.setState({ workspaceWeights: weights });
} catch (e) {
// Invalid saved data, ignore
}
}
}

componentWillUnmount() {
Expand All@@ -63,16 +80,33 @@ class App extends BaseComponent {
this.toggleHistoryBlock(false);
}

componentWillReceiveProps(nextProps) {
const { params } = nextProps.match;
const { search } = nextProps.location;
if (params !== this.props.match.params || search !== this.props.location.search) {
componentDidUpdate(prevProps, prevState) {
const { params } = this.props.match;
const { search } = this.props.location;
const { params: prevParams } = prevProps.match;
const { search: prevSearch } = prevProps.location;

if (params !== prevParams || search !== prevSearch) {
const { categoryKey, algorithmKey, gistId } = params;
const { algorithm, scratchPaper } =nextProps.current;
const { algorithm, scratchPaper } =this.props.current;
if (algorithm && algorithm.categoryKey === categoryKey && algorithm.algorithmKey === algorithmKey) return;
if (scratchPaper && scratchPaper.gistId === gistId) return;
this.loadAlgorithm(params, queryString.parse(search));
}

// Persist navigator state
const { workspaceVisibles } = this.state;
const { workspaceVisibles: prevVisibles } = prevState;
if (workspaceVisibles[0] !== prevVisibles[0]) {
localStorage.setItem('navigatorOpened', JSON.stringify(workspaceVisibles[0]));
}

// Persist workspace weights
const { workspaceWeights } = this.state;
const { workspaceWeights: prevWeights } = prevState;
if (workspaceWeights !== prevWeights) {
localStorage.setItem('workspaceWeights', JSON.stringify(workspaceWeights));
}
}

toggleHistoryBlock(enable = !this.unblock) {
Expand Down
6 changes: 4 additions & 2 deletionssrc/components/FoldableAceEditor/index.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,8 +22,10 @@ class FoldableAceEditor extends AceEditor {
super.componentDidUpdate(prevProps, prevState, snapshot);

const { editingFile, shouldBuild } = this.props.current;
if (editingFile !== prevProps.current.editingFile) {
if (shouldBuild) this.foldTracers();
const { editingFile: prevEditingFile } = prevProps.current;

if (editingFile !== prevEditingFile && shouldBuild) {
this.foldTracers();
}
}

Expand Down
8 changes: 5 additions & 3 deletionssrc/components/Navigator/index.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,9 +28,11 @@ class Navigator extends React.Component {
}
}

componentWillReceiveProps(nextProps) {
const { algorithm } = nextProps.current;
if (algorithm) {
componentDidUpdate(prevProps) {
const { algorithm } = this.props.current;
const { algorithm: prevAlgorithm } = prevProps.current;

if (algorithm && (!prevAlgorithm || algorithm.categoryKey !== prevAlgorithm.categoryKey)) {
this.toggleCategory(algorithm.categoryKey, true);
}
}
Expand Down
37 changes: 34 additions & 3 deletionssrc/components/Player/index.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,15 +31,46 @@ class Player extends BaseComponent {
componentDidMount() {
const { editingFile, shouldBuild } = this.props.current;
if (shouldBuild) this.build(editingFile);
window.addEventListener('resize', this.handleResize);
document.addEventListener('keydown', this.handleKeyDown);
}

componentWillReceiveProps(nextProps) {
const { editingFile, shouldBuild } =nextProps.current;
if (editingFile !==this.props.current.editingFile) {
componentDidUpdate(prevProps) {
const { editingFile, shouldBuild } =this.props.current;
if (editingFile !==prevProps.current.editingFile) {
if (shouldBuild) this.build(editingFile);
}
}

componentWillUnmount() {
window.removeEventListener('resize', this.handleResize);
document.removeEventListener('keydown', this.handleKeyDown);
}

handleResize = () => {
// Implement resize logic if needed
}

handleKeyDown = (e) => {
const { playing } = this.state;

// Space: play/pause
if (e.code === 'Space' && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA') {
e.preventDefault();
playing ? this.pause() : this.resume(true);
}
// Arrow Left: previous
if (e.code === 'ArrowLeft' && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA') {
e.preventDefault();
this.prev();
}
// Arrow Right: next
if (e.code === 'ArrowRight' && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA') {
e.preventDefault();
this.next();
}
}

reset(commands = []) {
const chunks = [{
commands: [],
Expand Down
26 changes: 21 additions & 5 deletionssrc/components/ToastContainer/index.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,11 +5,27 @@ import { classes } from 'common/util';
import styles from './ToastContainer.module.scss';

class ToastContainer extends React.Component {
componentWillReceiveProps(nextProps) {
const newToasts = nextProps.toast.toasts.filter(toast => !this.props.toast.toasts.includes(toast));
newToasts.forEach(toast => {
window.setTimeout(() => this.props.hideToast(toast.id), 3000);
});
constructor(props) {
super(props);
this.timeout = null;
}

componentDidUpdate(prevProps) {
const { toasts } = this.props.toast;
const { toasts: prevToasts } = prevProps.toast;

if (toasts !== prevToasts) {
clearTimeout(this.timeout);
const newToasts = toasts.filter(toast => !prevToasts.includes(toast));
if (newToasts.length > 0) {
const latestToast = newToasts[newToasts.length - 1];
this.timeout = setTimeout(() => this.props.hideToast(latestToast.id), 3000);
}
}
}

componentWillUnmount() {
clearTimeout(this.timeout);
}

render() {
Expand Down
10 changes: 5 additions & 5 deletionssrc/components/VisualizationViewer/index.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,11 +24,11 @@ class VisualizationViewer extends BaseComponent {
this.update(chunks, cursor);
}

componentWillReceiveProps(nextProps) {
const { chunks, cursor } =nextProps.player;
const { chunks:oldChunks, cursor:oldCursor } =this.props.player;
if (chunks !==oldChunks || cursor !==oldCursor) {
this.update(chunks, cursor,oldChunks, oldCursor);
componentDidUpdate(prevProps) {
const { chunks, cursor } =this.props.player;
const { chunks:prevChunks, cursor:prevCursor } =prevProps.player;
if (chunks !==prevChunks || cursor !==prevCursor) {
this.update(chunks, cursor,prevChunks, prevCursor);
}
}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp