Skip to content

Commit

Permalink
create fallback mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Feb 28, 2024
1 parent a7c21ef commit 29363ce
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/gazzodown/src/elements/InlineElements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const CodeElement = lazy(() => import('../code/CodeElement'));
const KatexElement = lazy(() => import('../katex/KatexElement'));

type InlineElementsProps = {
children: MessageParser.Inlines[];
children: (MessageParser.Inlines | { fallback: MessageParser.Plain; type: undefined })[];
};

const InlineElements = ({ children }: InlineElementsProps): ReactElement => (
Expand Down Expand Up @@ -75,8 +75,12 @@ const InlineElements = ({ children }: InlineElementsProps): ReactElement => (
return <Timestamp key={index} children={child} />;
}

default:
default: {
if ('fallback' in child) {
return <InlineElements key={index} children={[child.fallback]} />;
}
return null;
}
}
})}
</>
Expand Down
1 change: 1 addition & 0 deletions packages/message-parser/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export type Timestamp = {
timestamp: string;
format: 't' | 'T' | 'd' | 'D' | 'f' | 'F' | 'R';
};
fallback?: Plain;
};

export type Types = {
Expand Down
1 change: 1 addition & 0 deletions packages/message-parser/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,6 @@ export const timestamp = (
timestamp: value,
format: type || 't',
},
fallback: plain(`<t:${value}:${type || 't'}>`),
};
};

0 comments on commit 29363ce

Please sign in to comment.