Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
#1940 topics and mediapicker
Browse files Browse the repository at this point in the history
  • Loading branch information
cindyb committed Aug 26, 2020
1 parent 162a579 commit fd219bd
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 49 deletions.
1 change: 0 additions & 1 deletion src/components/common/FaqItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class FaqItem extends React.Component {
return nextState;
}


toggleVisible = (evt) => {
evt.preventDefault();
this.setState(prevState => ({ showAnswer: !prevState.showAnswer }));
Expand Down
29 changes: 15 additions & 14 deletions src/components/common/mediaPicker/MediaPickerDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,11 @@ class MediaPickerDialog extends React.Component {
}
}

handleModifyClick = (initMedia) => {
const { setQueryFormChildDialogOpen, handleInitialSelectionOfMedia } = this.props;
this.setState({ open: true });
handleInitialSelectionOfMedia(initMedia); // push into selectedMedia in store
componentWillUnmount() {
const { reset } = this.props;
reset();
}

// document.body.style.overflow = 'hidden';
if (setQueryFormChildDialogOpen) { // way to tell parent that a dialog is open - focus issue stuff
setQueryFormChildDialogOpen(true);
}
// need to set body to overflow: hidden somehow...
};

handleRemoveDialogClose = (confirm) => {
const { onConfirmSelection, selectedMedia, setQueryFormChildDialogOpen, reset } = this.props;
Expand All @@ -76,10 +70,17 @@ class MediaPickerDialog extends React.Component {
}
};

componentWillUnmount() {
const { reset } = this.props;
reset();
}
handleModifyClick = (initMedia) => {
const { setQueryFormChildDialogOpen, handleInitialSelectionOfMedia } = this.props;
this.setState({ open: true });
handleInitialSelectionOfMedia(initMedia); // push into selectedMedia in store

// document.body.style.overflow = 'hidden';
if (setQueryFormChildDialogOpen) { // way to tell parent that a dialog is open - focus issue stuff
setQueryFormChildDialogOpen(true);
}
// need to set body to overflow: hidden somehow...
};

render() {
const { initMedia } = this.props;
Expand Down
19 changes: 6 additions & 13 deletions src/components/common/mediaPicker/MediaPickerSidebarContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,14 @@ import { initializePreviouslySelectedMedia, clearSelectedMedia, resetMetadataSho
function composeMediaPickerSidebarContainer() {
return (ChildComponent) => {
class MediaPickerSidebarContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
initMedia: {},
};
}
static getDerivedStateFromProps(nextState, prevState) {
// select the media so we fill the reducer with the previously selected media
const { initMedia } = prevState;
if (JSON.stringify(initMedia) !== JSON.stringify(nextState.initMedia)) {
if (nextState.initMedia) { // expects an array of media from caller
nextState.handleInitialSelectionOfMedia(nextState.initMedia);
componentDidUpdate(prevProps) {
// compare and select incoming media
const { initMedia } = this.props;
if (JSON.stringify(initMedia) !== JSON.stringify(prevProps.initMedia)) {
if (initMedia) { // expects an array of media from caller
this.props.handleInitialSelectionOfMedia(initMedia);
}
}
return nextState;
}

componentWillUnmount() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/topic/TopicStoryTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class TopicStoryTable extends React.Component {

render() {
const { stories, showTweetCounts, onChangeFocusSelection, topicId, maxTitleLength, usingUrlSharingSubtopic, hasAUrlSharingFocalSet, intl } = this.props;
let urlSharingSubtopicNames = null;
let urlSharingSubtopicNames = [];
if (hasAUrlSharingFocalSet && (stories.length > 0)) {
// intuit a list of the subtopics from the url sharing counts on the first story
// alternatively, we could pass in the subtopics and use those, but this information is already here
Expand All @@ -71,7 +71,7 @@ class TopicStoryTable extends React.Component {
<div className="story-table">
<table>
<tbody>
<tr>
<tr key={0} >
<th><FormattedMessage {...messages.storyTitle} /></th>
<th><FormattedMessage {...messages.media} /></th>
<th>
Expand Down
10 changes: 3 additions & 7 deletions src/components/topic/controlbar/QuerySelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ class QuerySelector extends React.Component {
};
}

componentDidMount() {
this.setState({ value: this.props.query || '' });
}

static getDerivedStateFromProps(nextState, prevState) {
if (nextState.query !== prevState.query) {
if (prevState.query && nextState.query !== prevState.query) {
// if filters are open and user deletes chip, gotta remove the query here
this.setState({ value: nextState.query });
return { value: nextState.query };
}
return nextState;
return null;
}

valueHasChanged = () => {
Expand Down
7 changes: 3 additions & 4 deletions src/components/topic/stories/StoryContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ class StoryContainer extends React.Component {
selectedTab: 0,
};

static getDerivedStateFromProps(nextState) {
componentWillUpdate(prevProps) {
// select the media so we fill the reducer with the previously selected media
const { refetchAsyncData } = this.props;
if (nextState.storiesId !== this.props.storiesId) {
refetchAsyncData(nextState);
if (prevProps.storiesId !== this.props.storiesId) {
refetchAsyncData(this.props.storiesId);
}
return nextState;
}

render() {
Expand Down
7 changes: 4 additions & 3 deletions src/components/topic/stories/StoryUpdateContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ const localMessages = {
};

class StoryUpdateContainer extends React.Component {
static getDerivedStateFromProps(nextState) {
componentWillUpdate(prevProps) {
// select the media so we fill the reducer with the previously selected media
const { refetchAsyncData } = this.props;
if (nextState.storiesId !== this.props.storiesId) {
refetchAsyncData(nextState);
if (prevProps.storiesId !== this.props.storiesId) {
refetchAsyncData(this.props.storiesId);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/components/topic/words/WordContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class WordContainer extends React.Component {
saveParamsToStore(this.props, this);
}

static getDerivedStateFromProps(nextState) {
if (nextState.params.word !== this.props.params.word) {
const { saveParamsToStore } = nextState;
saveParamsToStore(nextState, this);
componentDidUpdate(prevProps) {
// select the media so we fill the reducer with the previously selected media
const { saveParamsToStore } = this.props;
if (prevProps.params.word !== this.props.params.word) {
saveParamsToStore(this.props.params.word, this);
}
return nextState;
}

render() {
Expand Down

0 comments on commit fd219bd

Please sign in to comment.