Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Perkovec committed Aug 16, 2016
1 parent f853ded commit 44e0db2
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"material-ui": "^0.15.3",
"react": "^15.3.0",
"react-addons-shallow-compare": "^15.3.0",
"react-deep-force-update": "^2.0.1",
"react-dom": "^15.3.0",
"react-layout-pane": "^0.1.16",
"react-tap-event-plugin": "^1.0.0",
Expand Down
38 changes: 25 additions & 13 deletions src/content/Chad.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const darkBaseTheme = require('material-ui/styles/baseThemes/darkBaseTheme').def
const lightBaseTheme = require('material-ui/styles/baseThemes/lightBaseTheme').default;
const SideBar = require('./components/SideBar');
const ContentBar = require('./components/ContentBar');
const langs = {
ru: require('./langs/ru'),
en: require('./langs/en'),
};

const TGAPI = require('./js/API');
const Signal = require('./js/Signal');
Expand Down Expand Up @@ -32,14 +36,13 @@ class Chad extends React.Component {
botavatar: (localStorage.getItem('botavatar') || './assets/botavatar.png'),
bot: JSON.parse(localStorage.getItem('bot') || '{}'),
channels: JSON.parse(localStorage.getItem('channels') || '[]'),
sideBarOpen: false,
snackbar: {
open: false,
text: '',
},
};

this.local = require('./langs/' + this.state.settings.lang);
this.local = langs[this.state.settings.lang];
this.signal = new Signal();

this.token = this.state.bot.token || null;
Expand All @@ -50,12 +53,12 @@ class Chad extends React.Component {
this.signal.register('PostWriteDefaultsChange', (v) => this.postWriteDefaultsChange(v));
this.signal.register('SendPost', (d) => this.sendPost(d));
this.signal.register('NewChannel', (d) => this.newChannel(d));
this.signal.register('RemoveChannel', (i) => this.removeChannel(i));
this.signal.register('RemoveChannel', (i, h) => this.removeChannel(i, h));
this.signal.register('SetAdminBot', (t, o) => this.setAdminBot(t, o));
this.signal.register('RemoveAdminBot', () => this.removeAdminBot());
this.signal.register('DeletePost', (i) => this.deletePost(i));
this.signal.register('DeletePost', (i, h) => this.deletePost(i, h));
this.signal.register('ChangePost', (d) => this.changePost(d));
this.signal.register('DeleteDraft', (i) => this.deleteDraft(i));
this.signal.register('DeleteDraft', (i, h) => this.deleteDraft(i, h));
this.signal.register('SaveDraft', (d) => this.saveDraft(d));
this.signal.register('ChangeDraft', (d) => this.changeDraft(d));

Expand All @@ -67,15 +70,15 @@ class Chad extends React.Component {
let state = this.state;
state.settings.lang = value;
localStorage.setItem('settings', JSON.stringify(state.settings));
this.local = require('./langs/' + value);
this.local = langs[value];
this.setState(state);
}

darkThemeChange(value) {
let state = this.state;
state.settings.darkTheme = value;
localStorage.setItem('settings', JSON.stringify(state.settings));
this.setState(state);
this.setState(state, this.props.deepForceUpdate);
}

postWriteDefaultsChange(value) {
Expand Down Expand Up @@ -269,15 +272,18 @@ class Chad extends React.Component {
}, () => localStorage.setItem('channels', JSON.stringify(channels)));
}

removeChannel(id) {
removeChannel(id, onRemove) {
let channels = this.state.channels;

for (let i = 0; i < channels.length; ++i) {
if (channels[i].uid === id) {
channels.splice(i, 1);
return this.setState({
channels: channels,
}, () => localStorage.setItem('channels', JSON.stringify(channels)));
}, () => {
localStorage.setItem('channels', JSON.stringify(channels));
onRemove();
});
}
}
}
Expand Down Expand Up @@ -339,26 +345,32 @@ class Chad extends React.Component {
});
}

deletePost(uid) {
deletePost(uid, onDelete) {
let posts = this.state.posts;
for (let i = 0; i < posts.length; ++i) {
if (posts[i].uid === uid) {
posts.splice(i, 1);
return this.setState({
posts: posts,
}, () => localStorage.setItem('posts', JSON.stringify(posts)));
}, () => {
localStorage.setItem('posts', JSON.stringify(posts));
onDelete();
});
}
}
}

deleteDraft(uid) {
deleteDraft(uid, onDelete) {
let drafts = this.state.drafts;
for (let i = 0; i < drafts.length; ++i) {
if (drafts[i].uid === uid) {
drafts.splice(i, 1);
return this.setState({
drafts: drafts,
}, () => localStorage.setItem('drafts', JSON.stringify(drafts)));
}, () => {
localStorage.setItem('drafts', JSON.stringify(drafts));
onDelete();
});
}
}
}
Expand Down
Binary file removed src/content/assets/reload.png
Binary file not shown.
2 changes: 1 addition & 1 deletion src/content/components/ContentBarDrafts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ContentBarDraft extends React.Component {
}

deleteDraft(uid) {
this.props.signal.call('DeleteDraft', [uid]);
this.props.signal.call('DeleteDraft', [uid, () => this.forceUpdate()]);
}

editDraft(uid) {
Expand Down
2 changes: 1 addition & 1 deletion src/content/components/ContentBarPosts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ContentBarPosts extends React.Component {
}

deletePost(uid) {
this.props.signal.call('DeletePost', [uid]);
this.props.signal.call('DeletePost', [uid, () => this.forceUpdate()]);
}

cancelEditPost() {
Expand Down
2 changes: 1 addition & 1 deletion src/content/components/SideBarChannels.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SideBarChannels extends React.Component {
}

removeChannel(uid) {
this.props.signal.call('RemoveChannel', [uid]);
this.props.signal.call('RemoveChannel', [uid, () => this.forceUpdate()]);
}

render() {
Expand Down
4 changes: 0 additions & 4 deletions src/content/components/WPostWrite.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ class WPostWrite extends React.Component {

let state = {
parser: 'none',
postText: this.props.text || '',
disablePreview: false,
disableNotification: false,
preview: '',
settingsDialog: false,
insertLinkDialog: false,
insertLinkTitle: '',
insertLinkURL: '',
};

if (this.props.settings) {
Expand Down
2 changes: 1 addition & 1 deletion src/content/components/WPostWriteInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class WPostWriteInput extends React.Component {
let selStart = this.inputRef.selectionStart;
let selEnd = this.inputRef.selectionEnd;

let title = (selStart === selEnd) ? this.state.text.substring(selStart, selEnd) : '';
let title = (selStart === selEnd) ? '' : this.state.text.substring(selStart, selEnd);
let state = this.state;

this.setState({
Expand Down
14 changes: 11 additions & 3 deletions src/content/main.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
const overlay = document.getElementById('overlay');
let instance = null;

setTimeout(() => {
window.React = require('react');
const ReactDOM = require('react-dom');
const { render } = require('react-dom');
const injectTapEventPlugin = require('react-tap-event-plugin');
const deepForceUpdate = require('react-deep-force-update');
const Velocity = require('velocity-animate');
require('./js/DataRepair')();

injectTapEventPlugin();

function deepUpdate() {
deepForceUpdate(instance);
}

const Chad = require('./Chad');
ReactDOM.render(
<Chad />,

instance = render(
<Chad deepForceUpdate={deepUpdate}/>,
document.getElementById('container')
);

Velocity(overlay, 'fadeOut', { duration: 500 });
}, 10);

0 comments on commit 44e0db2

Please sign in to comment.