Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: namespace check issue #1725

Merged
merged 1 commit into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2021-04-23T09:46:24.658Z\n"
"PO-Revision-Date: 2021-04-23T09:46:24.658Z\n"
"POT-Creation-Date: 2021-04-27T09:00:25.929Z\n"
"PO-Revision-Date: 2021-04-27T09:00:25.929Z\n"

msgid "Untitled dashboard"
msgstr ""
Expand Down Expand Up @@ -281,9 +281,6 @@ msgid ""
"print dialog"
msgstr ""

msgid "Not available offline"
msgstr ""

msgid "Create a new dashboard"
msgstr ""

Expand Down
19 changes: 11 additions & 8 deletions src/api/userDataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,33 @@ import { getInstance } from 'd2'

export const NAMESPACE = 'dashboard'

export const hasNamespace = async d2 =>
export const hasDashboardNamespace = async d2 =>
await d2.currentUser.dataStore.has(NAMESPACE)

export const getNamespace = async (d2, hasNamespace) =>
hasNamespace
export const getNamespace = async d2 => {
const hasNamespace = await hasDashboardNamespace(d2)

return hasNamespace
? await d2.currentUser.dataStore.get(NAMESPACE)
: await d2.currentUser.dataStore.create(NAMESPACE)
}

export const apiPostUserDataStoreValue = async (key, value) => {
const d2 = await getInstance()
const ns = await getNamespace(d2, hasNamespace)
const ns = await getNamespace(d2)

return ns.set(key, value)
}

export const apiGetUserDataStoreValue = async (key, defaultValue) => {
const d2 = await getInstance()
const namespace = await getNamespace(d2, await hasNamespace(d2))
const hasKey = namespace?.keys?.find(k => k === key)
const ns = await getNamespace(d2)
const hasKey = ns?.keys?.find(k => k === key)

if (hasKey) {
return await namespace.get(key)
return await ns.get(key)
} else {
await apiPostUserDataStoreValue(key, defaultValue, namespace)
await apiPostUserDataStoreValue(key, defaultValue, ns)
console.log('(These errors to /userDataStore can be ignored)')
return defaultValue
}
Expand Down