diff --git a/client/app.jsx b/client/app.jsx
index b675257..769089b 100644
--- a/client/app.jsx
+++ b/client/app.jsx
@@ -1,5 +1,5 @@
/* global React */
-import { loadSites, getAuthUrl, deleteSite, refreshSite } from './services';
+import { loadSites, getAuthUrl, deleteSite, refreshSite, unlinkPost } from './services';
import Site from './site.jsx';
import ErrorMessage from './error-message.jsx'
@@ -65,6 +65,16 @@ export default class App extends React.Component {
this.setState( { sites } )
}
+ unlinkPost( blog_id ) {
+ return unlinkPost( blog_id )
+ .then( ( success ) => {
+ if ( success ) {
+ this.setPost( blog_id, null );
+ }
+ } )
+ .catch( this.errorHandler )
+ }
+
/**
* @param {number} blog_id unique id for the site
* @returns {Promise} for new site information
@@ -106,6 +116,7 @@ export default class App extends React.Component {
setPost={ this.setPost.bind( this, site.blog_id ) }
removeSite={ this.removeSite.bind( this, site.blog_id ) }
refreshSite={ this.updateSite.bind( this, site.blog_id ) }
+ unlinkPost={ this.unlinkPost.bind( this, site.blog_id ) }
updateSiteList={ this.updateSiteList } /> ) }
Add WordPress Site
diff --git a/client/services.js b/client/services.js
index 24aa4ec..7434e89 100644
--- a/client/services.js
+++ b/client/services.js
@@ -49,3 +49,12 @@ export function getAuthUrl() {
.getAuthUrl();
} )
}
+
+export function unlinkPost( blogId ) {
+ return new Promise( ( resolve, reject ) => {
+ google.script.run
+ .withSuccessHandler( resolve )
+ .withFailureHandler( reject )
+ .unlinkPost( blogId );
+ } )
+}
\ No newline at end of file
diff --git a/client/site.jsx b/client/site.jsx
index a98bd20..d854c5c 100644
--- a/client/site.jsx
+++ b/client/site.jsx
@@ -95,6 +95,7 @@ export default class Site extends React.Component {
const postTypes = site.postTypes || []
const blavatar = ( site.info.icon && site.info.icon.img ) ? site.info.icon.img : 'https://secure.gravatar.com/blavatar/e6392390e3bcfadff3671c5a5653d95b'
const previewLink = ( hasBeenPosted ) ? Preview on { site.info.name } : null;
+ const unlinkLink = ( hasBeenPosted ) ? Unlink : null;
const extendedStyle = ( ! this.state.optionsExpanded ) ? { display: 'none' } : {}
const extendedToggled = ( ! this.state.optionsExpanded ) ? 'sites-list__extended-toggle' : 'sites-list__extended-toggle is-toggled'
const refreshClasses = 'sites-list__update-site' + ( this.state.siteRefreshing ? ' sites-list__update-site--updating' : '' )
@@ -115,6 +116,7 @@ export default class Site extends React.Component {
{ previewLink }
+ { unlinkLink }
@@ -122,7 +124,7 @@ export default class Site extends React.Component {
diff --git a/server/code.js b/server/code.js
index cdd80ec..95e2ef4 100644
--- a/server/code.js
+++ b/server/code.js
@@ -14,7 +14,8 @@ import {
clearSiteData,
refreshSite,
include,
- getAuthUrl
+ getAuthUrl,
+ unlinkPost
} from './index'
global.onOpen = onOpen;
@@ -29,3 +30,4 @@ global.refreshSite = refreshSite;
global.clearSiteData = clearSiteData;
global.include = include;
global.getAuthUrl = getAuthUrl;
+global.unlinkPost = unlinkPost;
diff --git a/server/index.js b/server/index.js
index fcc9852..07e5f19 100644
--- a/server/index.js
+++ b/server/index.js
@@ -225,6 +225,22 @@ export function deleteSite( site_id ) {
return;
}
+export function unlinkPost( site_id ) {
+ const ui = DocumentApp.getUi();
+ const promptResponse = ui.alert(
+ 'Are you sure you want to unlink this document from the WordPress post?',
+ 'If you choose "Yes" you can create a new post for this document.',
+ ui.ButtonSet.YES_NO
+ );
+
+ if ( promptResponse !== ui.Button.YES ) {
+ return false;
+ }
+
+ store.removePostFromSite( site_id );
+ return true;
+}
+
export function devTest() {
// const doc = DocumentApp.getActiveDocument();
// const body = doc.getBody();
diff --git a/server/persistance.js b/server/persistance.js
index ccb8b29..93a6e94 100644
--- a/server/persistance.js
+++ b/server/persistance.js
@@ -115,6 +115,12 @@ export function Persistance( propertieService ) {
return postData[ blog_id ]
}
+ function removePostFromSite( blog_id ) {
+ const postData = getPostStatus();
+ delete postData[ blog_id ];
+ docProps().setProperty( POST_PERSISTANCE_KEY, JSON.stringify( postData ) )
+ }
+
function postIdentity( post ) {
const { date, URL, ID, modified, type, categories, tags } = post
const postCategories = Object.keys( categories )
@@ -145,6 +151,7 @@ export function Persistance( propertieService ) {
findSite,
deleteSite,
savePostToSite,
+ removePostFromSite,
getPostStatus
}
}