diff --git a/src/components/index.js b/src/components/index.js index 2da17a2..c9e2ac9 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -23,7 +23,13 @@ import ReactGA from 'react-ga'; ReactGA.initialize(config.trackingId); function checkPathForBlocks(blockedPages, path) { - return true; + for (var i in blockedPages) { + var page = blockedPages[i]; + if (path.startsWith(page)) { + return true; + } + } + return false; } export default class App extends Component { @@ -32,9 +38,15 @@ export default class App extends Component { this.state = { currentUser: null, displayName: "", + networkAdminExists: false, + isNetworkAdmin: false, ip: "", + blockedPages: [], loading: true } + + this.unblockPage = this.unblockPage.bind(this); + this.blockPage = this.blockPage.bind(this); } componentDidMount () { @@ -57,11 +69,40 @@ export default class App extends Component { fetch('https://api.ipify.org?format=json').then((response) => { return response.json(); }).then((data) => { + firebase.firestore().collection("network-admin").doc(data.ip).get().then((documentSnapshot) => { + var docData = documentSnapshot.data(); + this.setState({ + ip: data.ip, + networkAdminExists: documentSnapshot.exists, + networkAdminUID: documentSnapshot.exists ? docData['admin-uid'] : "", + blockedPages: documentSnapshot.exists ? docData.blockedPages : [], + loading: false + }) + }); + }); + } + + blockPage (event) { + var newBlockedPages = this.state.blockedPages.slice(); + newBlockedPages.push(window.location.pathname); + firebase.firestore().collection("network-admin").doc(this.state.ip).update({ + blockedPages: newBlockedPages + }).then(() => { this.setState({ - ip: data, - loading: false + blockedPages: newBlockedPages }) - }); + }) + } + unblockPage (event) { + var newBlockedPages = this.state.blockedPages.slice(); + newBlockedPages.splice(newBlockedPages.indexOf(window.location.pathname), 1); + firebase.firestore().collection("network-admin").doc(this.state.ip).update({ + blockedPages: newBlockedPages + }).then(() => { + this.setState({ + blockedPages: newBlockedPages + }) + }) } componentDidUpdate () { @@ -86,9 +127,10 @@ export default class App extends Component {
Are you network admin and would like to control what pages users can view on the site? If so, please contact network@claytondoesthings.xyz with adequate proof of position as well as a valid IP address.
-