Skip to content

Commit

Permalink
enhance daemon to manage path changs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwiterrion committed Oct 11, 2024
1 parent 4dbacc9 commit 930d46c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
13 changes: 9 additions & 4 deletions otoroshi/javascript/src/components/Drafts/DraftEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
QueryClientProvider,
} from 'react-query'
import { nextClient } from '../../services/BackOfficeServices'
import { Button } from '../Button'
import { draftSignal, draftVersionSignal } from './DraftEditorSignal'
import { draftSignal, draftVersionSignal, resetDraftSignal } from './DraftEditorSignal'
import { useSignalValue } from 'signals-react-safe'
import { PillButton } from '../PillButton'
import { withRouter } from 'react-router-dom'

const queryClient = new QueryClient()

Expand Down Expand Up @@ -117,13 +117,15 @@ export function DraftEditorContainer(props) {
}


export class DraftStateDaemon extends React.Component {
export const DraftStateDaemon = withRouter(class _ extends React.Component {

state = {
initialized: false
}

componentDidMount() {
resetDraftSignal()

this.unsubscribe = draftVersionSignal.subscribe(() => {
const { value, setValue } = this.props

Expand Down Expand Up @@ -164,6 +166,9 @@ export class DraftStateDaemon extends React.Component {
}
}
}
if(prevProps.history.location.pathname !== this.props.history.location.pathname) {
resetDraftSignal()
}
}

componentWillUnmount() {
Expand All @@ -174,4 +179,4 @@ export class DraftStateDaemon extends React.Component {
render() {
return null
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const draftVersionSignal = signal(DRAFT_VERSION_SIGNAL_TEMPLATE)
export const draftSignal = signal(DRAFT_SIGNAL_TEMPLATE)

export const resetDraftSignal = () => {
console.log('reset')
draftSignal.value = DRAFT_SIGNAL_TEMPLATE
draftVersionSignal.value = DRAFT_VERSION_SIGNAL_TEMPLATE
}
6 changes: 5 additions & 1 deletion otoroshi/javascript/src/pages/RouteDesigner/Designer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,11 @@ class Designer extends React.Component {
<DraftStateDaemon
value={this.state.route}
setValue={route => {
this.setState({ route, selectedNode: undefined }, () => this.loadData(this.state.route))
this.props.setValue(route)
this.setState({
route,
selectedNode: undefined
}, () => this.loadData(this.state.route))
}} />
<Container
showTryIt={showTryIt}
Expand Down
7 changes: 1 addition & 6 deletions otoroshi/javascript/src/pages/RouteDesigner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import _ from 'lodash';
import { Button } from '../../components/Button';
import { DraftEditorContainer } from '../../components/Drafts/DraftEditor';
import { dynamicTitleContent } from '../../components/DynamicTitleSignal';
import { draftSignal, draftVersionSignal, resetDraftSignal } from '../../components/Drafts/DraftEditorSignal';
import { draftSignal, draftVersionSignal } from '../../components/Drafts/DraftEditorSignal';
import { useSignalValue } from 'signals-react-safe';
import PageTitle from '../../components/PageTitle';
import { Dropdown } from '../../components/Dropdown';
Expand Down Expand Up @@ -643,14 +643,9 @@ class RouteDesigner extends React.Component {
componentDidUpdate(prevProps) {
if (this.props.match.params.routeId !== prevProps.match.params.routeId) {
this.loadRoute();
resetDraftSignal()
}
}

componentWillUnmount() {
resetDraftSignal()
}

loadRoute = () => {
const { routeId } = this.props.match.params || { routeId: undefined };

Expand Down

0 comments on commit 930d46c

Please sign in to comment.