/*global chrome*/ import React, {Component} from 'react'; import { DataTable } from 'primereact/datatable'; import { Column } from 'primereact/column'; import {Button} from 'primereact/button'; import {InputText} from 'primereact/inputtext'; import _ from 'lodash'; import moment from 'moment'; import './App.css'; class App extends Component { state = { bookMarkDataRaw: [], bookMarks: [] } /* Open port on popup file */ port = chrome.runtime.connect({ name: "bookmarkArranger" }); getBookMarks = () => { this.port.postMessage({ code: "getBookMarks" }); } listenMessages = () => { this.port.onMessage.addListener(message => { if(message.bookMarkData){ this.setState({ bookMarkDataRaw: message.bookMarkData[0] }, ()=>{ let collected = this.iterateBookMarks(this.state.bookMarkDataRaw.children, []); collected = _.map(collected, (nodes)=>{ if(nodes.parentId){ let parentNode = _.find(collected, {id: nodes.parentId}); nodes.parentNode = parentNode ? parentNode.title : ""; } return nodes; }) this.setState({ bookMarks: collected }) }) } }); this.getBookMarks(); } linkTemplate = (rowData, column) => { return {rowData.url} } dateTemplate = (rowData, column) => { if(rowData.dateAdded){ return {moment(rowData.dateAdded).format('MM-DD-YYYY hh:ss A')} }else if(rowData.dateGroupModified){ return {moment(rowData.dateAdded).format('MM-DD-YYYY hh:ss A')} }else { return } } componentDidMount(){ this.listenMessages(); } iterateBookMarks = (children, consolidatedChildrens)=>{ let bookMarkChildren = _.each(children, (child)=>{ if(child.children && child.children.length>0){ let currentNode = child; let currentNodeChildren = currentNode.children; console.log(currentNodeChildren); delete currentNode.children; consolidatedChildrens.push(currentNode); console.log(currentNodeChildren); this.iterateBookMarks(currentNodeChildren, consolidatedChildrens); }else{ consolidatedChildrens.push(child); } }); return consolidatedChildrens; } render(){ var header =