mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Sync label changes
This commit is contained in:
parent
901bdd2564
commit
db4604e21f
1 changed files with 35 additions and 1 deletions
|
|
@ -54,6 +54,7 @@ async function updateLabelsCache(apiUrl, tab) {
|
|||
console.log(!data.labels, data.labels['errorCodes'], !data.labels['labels'])
|
||||
return []
|
||||
}
|
||||
|
||||
await setStorage({
|
||||
labels: data.labels.labels,
|
||||
labelsLastUpdated: new Date().toISOString(),
|
||||
|
|
@ -97,13 +98,20 @@ async function updatePageTitle(apiUrl, pageId, title) {
|
|||
return data.updatePage.updatePage
|
||||
}
|
||||
|
||||
async function setLabels(apiUrl, pageId, labelIds) {
|
||||
async function setLabels(apiUrl, pageId, labelIds, createdLabels) {
|
||||
console.log(
|
||||
'setLabels(apiUrl, pageId, labelIds, createdLabels)',
|
||||
labelIds,
|
||||
createdLabels
|
||||
)
|
||||
const mutation = JSON.stringify({
|
||||
query: `mutation SetLabels($input: SetLabelsInput!) {
|
||||
setLabels(input: $input) {
|
||||
... on SetLabelsSuccess {
|
||||
labels {
|
||||
id
|
||||
name
|
||||
color
|
||||
}
|
||||
}
|
||||
... on SetLabelsError {
|
||||
|
|
@ -116,6 +124,7 @@ async function setLabels(apiUrl, pageId, labelIds) {
|
|||
input: {
|
||||
pageId,
|
||||
labelIds,
|
||||
labels: createdLabels,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
@ -129,9 +138,34 @@ async function setLabels(apiUrl, pageId, labelIds) {
|
|||
console.log('GQL Error setting labels:', data)
|
||||
throw new Error('Error setting labels.')
|
||||
}
|
||||
|
||||
await appendLabelsToCache(data.setLabels.labels)
|
||||
|
||||
return data.setLabels.labels
|
||||
}
|
||||
|
||||
async function appendLabelsToCache(labels) {
|
||||
const cachedLabels = await getStorageItem('labels')
|
||||
if (cachedLabels) {
|
||||
labels.forEach((l) => {
|
||||
const existing = cachedLabels.find((cached) => cached.name === l.name)
|
||||
if (!existing) {
|
||||
cachedLabels.unshift(l)
|
||||
}
|
||||
})
|
||||
|
||||
await setStorage({
|
||||
labels: cachedLabels,
|
||||
labelsLastUpdated: new Date().toISOString(),
|
||||
})
|
||||
} else {
|
||||
await setStorage({
|
||||
labels: labels,
|
||||
labelsLastUpdated: new Date().toISOString(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function addNote(apiUrl, pageId, noteId, shortId, note) {
|
||||
const query = JSON.stringify({
|
||||
query: `query GetArticle(
|
||||
|
|
|
|||
Loading…
Reference in a new issue