Skip to content

Commit

Permalink
Persist all tags collapsed
Browse files Browse the repository at this point in the history
  • Loading branch information
thsparks committed May 7, 2024
1 parent 0ae19f3 commit a2183f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
9 changes: 4 additions & 5 deletions teachertool/src/components/CatalogOverlay.tsx
Expand Up @@ -140,12 +140,11 @@ const CatalogList: React.FC = () => {
return null;
}

const expandedTags = getExpandedCatalogTags();

// If no tags are expanded, expand the first one.
if (expandedTags.length === 0) {
let expandedTags = getExpandedCatalogTags();
if (!expandedTags) {
// If we haven't saved an expanded set, default expand the first one.
addExandedCatalogTagAsync(tags[0]);
expandedTags.push(tags[0]);
expandedTags = [tags[0]];
}

const expandedIds = expandedTags.map(t => getItemIdForTag(t));
Expand Down
27 changes: 18 additions & 9 deletions teachertool/src/services/storageService.ts
Expand Up @@ -194,13 +194,15 @@ export async function deleteChecklistAsync(name: string) {
}
}

export function getExpandedCatalogTags(): string[] {
// Returns undefined if it has not been set or if there was an issue.
// Empty list means it was explicitly set to empty.
export function getExpandedCatalogTags(): string[] | undefined {
try {
const tags = getValue(EXPANDED_CATALOG_TAGS_KEY);
return tags ? JSON.parse(tags) : [];
return tags ? JSON.parse(tags) : undefined;
} catch (e) {
logError(ErrorCode.localStorageReadError, e);
return [];
return undefined;
}
}

Expand All @@ -213,17 +215,24 @@ export async function setExpandedCatalogTags(tags: string[]) {
}

export async function addExandedCatalogTagAsync(tag: string) {
const expandedTags = getExpandedCatalogTags();
let expandedTags = getExpandedCatalogTags();
if (!expandedTags) {
expandedTags = [];
}
expandedTags.push(tag);
await setExpandedCatalogTags(expandedTags);
}

export async function removeExpandedCatalogTagAsync(tag: string) {
const expandedTags = getExpandedCatalogTags();
const index = expandedTags.indexOf(tag);
if (index !== -1) {
expandedTags.splice(index, 1);
await setExpandedCatalogTags(expandedTags);
let expandedTags = getExpandedCatalogTags();
if (!expandedTags) {
await setExpandedCatalogTags([]);
} else {
const index = expandedTags.indexOf(tag);
if (index !== -1) {
expandedTags.splice(index, 1);
await setExpandedCatalogTags(expandedTags);
}
}
}

0 comments on commit a2183f5

Please sign in to comment.