Skip to content

Commit

Permalink
fear(NcSettingsSelectGroup): Cache initial groups to reduce API calls
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed May 15, 2023
1 parent 48f5f45 commit c5c8a76
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/components/NcSettingsSelectGroup/NcSettingsSelectGroup.vue
Expand Up @@ -61,7 +61,8 @@ section * {
:close-on-select="false"
:disabled="disabled"
@input="update"
@search="findGroup" />
@search="findGroup"
@open="initGroups" />
</div>
</template>

Expand Down Expand Up @@ -162,6 +163,21 @@ export default {
/** Emitted when the groups selection changes<br />**Payload:** `value` (`Array`) - *Ids of selected groups */
this.$emit('input', value)
},
/**
* Load initial groups if not already loaded
*/
async initGroups() {
if (Object.keys(this.groups).length === 0) {
// version scoped to prevent issues with different library versions
const savedGroups = window.sessionStorage.getItem(`${appName}:${appVersion}/initialGroups`)
if (savedGroups) {
this.groups = JSON.parse(savedGroups)
} else {
await this.findGroup('')
window.sessionStorage.setItem(`${appName}:${appVersion}/initialGroups`, JSON.stringify(this.groups))
}
}
},
async findGroup(query) {
try {
query = typeof query === 'string' ? encodeURI(query) : ''
Expand Down

0 comments on commit c5c8a76

Please sign in to comment.