diff --git a/pkg/extension/src/manifest.json b/pkg/extension/src/manifest.json
index 213f4ce8c..ae345048e 100644
--- a/pkg/extension/src/manifest.json
+++ b/pkg/extension/src/manifest.json
@@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "process.env.EXTENSION_NAME",
"short_name": "process.env.EXTENSION_NAME",
- "version": "0.1.26",
+ "version": "2.0.1",
"description": "Save articles to your Omnivore library",
"author": "Omnivore Media, Inc",
"default_locale": "en",
diff --git a/pkg/extension/src/scripts/background.js b/pkg/extension/src/scripts/background.js
index eaef4a328..bc8dcaa3a 100644
--- a/pkg/extension/src/scripts/background.js
+++ b/pkg/extension/src/scripts/background.js
@@ -177,62 +177,6 @@ function clearClickCompleteState() {
)
}
-function handleSaveResponse(tab, field, xhr) {
- if (xhr.readyState === 4) {
- if (xhr.status === 200) {
- const { data } = JSON.parse(xhr.response)
- console.log('response data: ', data)
- const item = data[field]
- if (!item) {
- return undefined
- }
-
- if ('errorCodes' in item) {
- const messagePayload = {
- text:
- descriptions[data.createArticle.errorCodes[0]] ||
- 'Unable to save page',
- type: 'error',
- }
-
- if (item.errorCodes[0] === 'UNAUTHORIZED') {
- messagePayload.errorCode = 401
- messagePayload.url = omnivoreURL
- clearClickCompleteState()
- }
-
- browserApi.tabs.sendMessage(tab.id, {
- action: ACTIONS.ShowMessage,
- payload: messagePayload,
- })
-
- return undefined
- }
-
- const url = item['url']
- browserApi.tabs.sendMessage(tab.id, {
- action: ACTIONS.UpdateStatus,
- payload: {
- status: 'success',
- target: 'page',
- link: url ?? omnivoreURL + '/home',
- },
- })
-
- return item
- } else if (xhr.status === 400) {
- browserApi.tabs.sendMessage(tab.id, {
- action: ACTIONS.ShowMessage,
- payload: {
- text: 'Unable to save page',
- type: 'error',
- },
- })
- return undefined
- }
- }
-}
-
async function saveUrl(currentTab, url) {
const requestId = uuidv4()
await saveApiRequest(currentTab, SAVE_URL_QUERY, 'saveUrl', {
@@ -244,7 +188,8 @@ async function saveUrl(currentTab, url) {
async function saveApiRequest(currentTab, query, field, input) {
const toolbarCtx = {
- originalUrl: input.url,
+ omnivoreURL,
+ originalURL: input.url,
requestId: input.clientRequestId,
}
completedRequests[toolbarCtx.requestId] = undefined
@@ -264,13 +209,6 @@ async function saveApiRequest(currentTab, query, field, input) {
},
})
- const wait = await new Promise((resolve, reject) => {
- setTimeout(() => {
- console.log(' -- resolving timeout.')
- resolve()
- }, 5000)
- })
-
try {
const result = await gqlRequest(omnivoreGraphqlURL + 'graphql', requestBody)
if (result[field]['errorCodes']) {
@@ -283,8 +221,6 @@ async function saveApiRequest(currentTab, query, field, input) {
ctx: toolbarCtx,
},
})
- // messagePayload.errorCode = 401
- // messagePayload.url = omnivoreURL
clearClickCompleteState()
} else {
browserApi.tabs.sendMessage(currentTab.id, {
@@ -302,80 +238,29 @@ async function saveApiRequest(currentTab, query, field, input) {
const requestId = result[field]
? result[field]['clientRequestId']
: undefined
- console.log(' got requestId', requestId, 'from', result[field])
browserApi.tabs.sendMessage(currentTab.id, {
action: ACTIONS.UpdateStatus,
payload: {
status: 'success',
target: 'page',
ctx: {
- requestId: toolbarCtx.requestId,
+ readerURL: url,
responseId: requestId,
- link: url,
+ requestId: toolbarCtx.requestId,
},
},
})
completedRequests[toolbarCtx.requestId] = {
- url,
- requestId,
+ readerURL: url,
+ responseId: requestId,
+ requestId: toolbarCtx.requestId,
}
} catch (err) {
console.log('error saving: ', err)
}
processPendingRequests(currentTab.id)
- // if (pendingRequests) {
- // pendingRequests.map((pr) => {
- // console.log(
- // 'pending request: ',
- // pr,
- // pr.clientRequestId,
- // completedRequests[pr.clientRequestId]
- // )
- // })
- // }
-
- return new Promise((resolve, reject) => {
- const xhr = new XMLHttpRequest()
- xhr.open('POST', omnivoreGraphqlURL + 'graphql', true)
- setupConnection(xhr)
-
- xhr.onerror = (err) => {
- reject(err)
- }
-
- xhr.onload = () => {
- try {
- const res = handleSaveResponse(currentTab, field, xhr)
- if (!res) {
- return reject()
- }
- resolve(res)
- } catch (err) {
- reject(err)
- }
- }
-
- const data = JSON.stringify({
- query,
- variables: {
- input,
- },
- })
-
- xhr.send(data)
- }).catch((err) => {
- console.log('error saving page', err)
- browserApi.tabs.sendMessage(currentTab.id, {
- action: ACTIONS.ShowMessage,
- payload: {
- text: 'Unable to save page',
- type: 'error',
- },
- })
- return undefined
- })
}
function updateClientStatus(tabId, target, status, message) {
@@ -389,10 +274,10 @@ function updateClientStatus(tabId, target, status, message) {
})
}
-async function editTitleRequest(tabId, request, compeledResponse) {
+async function editTitleRequest(tabId, request, completedResponse) {
return updatePageTitle(
omnivoreGraphqlURL + 'graphql',
- compeledResponse.requestId,
+ completedResponse.responseId,
request.title
)
.then(() => {
@@ -409,7 +294,7 @@ async function editTitleRequest(tabId, request, compeledResponse) {
async function setLabelsRequest(tabId, request, completedResponse) {
return setLabels(
omnivoreGraphqlURL + 'graphql',
- completedResponse.requestId,
+ completedResponse.responseId,
request.labelIds
)
.then(() => {
@@ -438,15 +323,9 @@ async function processPendingRequests(tabId) {
break
}
}
- console.log('processing: ', pr)
- console.log(
- ' -- completed request: ',
- completedRequests[pr.clientRequestId]
- )
- console.log(' ----- all requests', completedRequests)
+
if (handled) {
const idx = pendingRequests.findIndex((opr) => pr.id === opr.id)
- console.log(' -- idx: ', idx)
if (idx > -1) {
pendingRequests.splice(idx, 1)
}
@@ -454,6 +333,8 @@ async function processPendingRequests(tabId) {
})
console.log('updated pending requests: ', pendingRequests)
+
+ // TODO: need to handle clearing completedRequests also
}
async function saveArticle(tab) {
diff --git a/pkg/extension/src/scripts/common.js b/pkg/extension/src/scripts/common.js
index 57dbf57e2..36303f828 100644
--- a/pkg/extension/src/scripts/common.js
+++ b/pkg/extension/src/scripts/common.js
@@ -39,8 +39,6 @@ window.ACTIONS = {
SetLabels: 'SET_LABELS',
}
-window.DONT_REMOVE_ELEMENTS = ['meta', 'script', 'title']
-
window.SAVE_URL_QUERY = `mutation SaveUrl ($input: SaveUrlInput!) {
saveUrl(input:$input){
... on SaveSuccess {
diff --git a/pkg/extension/src/scripts/content/toast.js b/pkg/extension/src/scripts/content/toast.js
index a5bdc608d..39cefb478 100644
--- a/pkg/extension/src/scripts/content/toast.js
+++ b/pkg/extension/src/scripts/content/toast.js
@@ -2,9 +2,10 @@
;('use strict')
;(function () {
let currentToastEl
- let hideToastTimeout
let labels = []
let ctx = undefined
+ let doNotHide = false
+ let hideToastTimeout = undefined
const systemIcons = {
spinner: `
@@ -94,15 +95,8 @@
return fragment
}
- function hideToastAfter(timeInMs) {
- if (hideToastTimeout) clearTimeout(hideToastTimeout)
- hideToastTimeout = setTimeout(function () {
- currentToastEl.remove()
- currentToastEl = undefined
- }, timeInMs)
- }
-
function cancelAutoDismiss() {
+ doNotHide = true
if (hideToastTimeout) clearTimeout(hideToastTimeout)
}
@@ -112,6 +106,11 @@
return
}
+ if (payload.ctx) {
+ ctx = { ...ctx, ...payload.ctx }
+ }
+ console.log('updated ctx: ', ctx)
+
switch (payload.target) {
case 'page':
{
@@ -123,6 +122,15 @@
statusBox.innerHTML = systemIcons.animatedLoader
break
case 'success':
+ // Auto hide if everything went well and the user
+ // has not initiated any interaction.
+ hideToastTimeout = setTimeout(function () {
+ console.log('hiding: ', currentToastEl, doNotHide)
+ if (!doNotHide) {
+ currentToastEl.remove()
+ currentToastEl = undefined
+ }
+ }, 2500)
statusBox.innerHTML = systemIcons.success
break
case 'failure':
@@ -170,39 +178,17 @@
const bodyEl = document.body
if (!bodyEl) return
- let duration = 5e3
-
if (!currentToastEl) {
currentToastEl = await createToastContainer()
}
- // let styleAsError = false
if (payload.type === 'loading') {
- duration = 5000
updateStatus({
status: 'loading',
target: 'page',
})
}
- // } else if (payload.type !== 'error') {
- // currentIconEl.innerHTML = systemIcons.success
- // updateToastText(payload)
- // } else if (payload.errorCode && payload.errorCode === 401) {
- // currentToastEl.textContent = ''
- // currentIconEl = null
- // currentTextEl = null
- // const ctaModalEl = createCtaModal(payload.url)
- // currentToastEl.appendChild(ctaModalEl)
- // duration = 8e3
- // } else {
- // styleAsError = true
- // currentIconEl.innerHTML = systemIcons.failed
- // updateToastText(payload)
- // }
- hideToastAfter(duration)
-
- // remove any existing toasts not created by current content script
document.querySelectorAll('#omnivore-toast').forEach((toastEl) => {
if (toastEl !== currentToastEl) {
console.log('removing current toast el: ', currentToastEl)
@@ -239,7 +225,6 @@
function toggleRow(rowId) {
const container = currentToastEl.shadowRoot.querySelector(rowId)
- console.log(' toggling', rowId, container)
const initialState = container?.getAttribute('data-state')
const rows = currentToastEl.shadowRoot.querySelectorAll(
'.omnivore-toast-func-row'
@@ -265,9 +250,7 @@
]
for (const btnInfo of btns) {
- console.log('root', root, 'shadowRoot', root.shadowRoot)
const btn = root.shadowRoot.querySelector(btnInfo.id)
- console.log(' connecting btn', btn, 'tp', btnInfo.func)
if (btn) {
btn.addEventListener('click', btnInfo.func)
}
@@ -404,7 +387,6 @@
'Updating title...'
)
- console.log('submitting EDIT TITLE')
browserApi.runtime.sendMessage({
action: ACTIONS.EditTitle,
payload: {
@@ -462,7 +444,6 @@
`button[data-label-selected="on"]`
)
).map((e) => e.getAttribute('data-label-id'))
- console.log('selected label ids: ', labelIds)
browserApi.runtime.sendMessage({
action: ACTIONS.SetLabels,
@@ -505,11 +486,12 @@
)
container.setAttribute('data-state', 'open')
- if (ctx && ctx.finalURL) {
- window.open(finalURL)
+ if (ctx && ctx.readerURL) {
+ window.open(ctx.readerURL, '_blank')
} else if (ctx) {
window.open(
- `https://demo.omnivore.app/article?url=${encodeURI(ctx.originalUrl)}`
+ new URL(`/article?url=${encodeURI(ctx.originalURL)}`, ctx.omnivoreURL),
+ '_blank'
)
} else {
alert('Error no URL found.')
diff --git a/pkg/extension/src/views/toast.html b/pkg/extension/src/views/toast.html
index 6eb1b541c..01177c5d7 100644
--- a/pkg/extension/src/views/toast.html
+++ b/pkg/extension/src/views/toast.html
@@ -264,7 +264,7 @@
Read Now
-
+