Skip to content

Commit

Permalink
chocolate-curry-13 Implement quick-select templates
Browse files Browse the repository at this point in the history
- Reintroduce label sharing
  • Loading branch information
infinia-yzl committed Jul 11, 2024
1 parent 5a55a42 commit 2dba50d
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/tierStateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ const typedImageSetConfig = imagesetConfig as ImageSetConfig;
interface SimplifiedTier {
i: string; // id
n: string; // name
t: string[]; // items (array of item ids)
t: SimplifiedItem[]; // items
}

interface SimplifiedItem {
i: string; // id
c: string; // content
}

interface StoredCustomItem {
Expand Down Expand Up @@ -52,7 +57,10 @@ export function encodeTierStateForURL(tiers: Tier[]): string {
const simplifiedTiers: SimplifiedTier[] = tiers.map(tier => ({
i: tier.id,
n: tier.name,
t: tier.items.map(item => item.id)
t: tier.items.map(item => ({
i: item.id,
c: item.content
}))
}));
const jsonString = JSON.stringify(simplifiedTiers);
return LZString.compressToEncodedURIComponent(jsonString);
Expand All @@ -69,15 +77,15 @@ export function decodeTierStateFromURL(encodedState: string): Tier[] | null {
return simplifiedTiers.map(simplifiedTier => ({
id: simplifiedTier.i,
name: simplifiedTier.n,
items: simplifiedTier.t.map(itemId => resolveItem(itemId))
items: simplifiedTier.t.map(item => resolveItem(item.i, item.c))
}));
} catch (error) {
console.error('Failed to decode tier state from URL:', error);
return null;
}
}

function resolveItem(itemId: string): Item {
function resolveItem(itemId: string, content: string): Item {
// 1. Check package items
const packageItem = packageItemLookup[itemId];
if (packageItem) return packageItem;
Expand All @@ -87,13 +95,17 @@ function resolveItem(itemId: string): Item {
if (customItem) {
return {
id: customItem.i,
content: customItem.c,
content: content, // Use the content from the encoded URL
imageUrl: customItem.d,
};
}

// 3. Create a placeholder
return createPlaceholderItem(itemId, 'Unavailable Item');
// 3. Create an item with the provided content
return {
id: itemId,
content: content,
imageUrl: '/placeholder-image.jpg',
};
}

function createPlaceholderItem(itemId: string, content: string): Item {
Expand Down

0 comments on commit 2dba50d

Please sign in to comment.