Skip to content

Commit

Permalink
[Glitch] Enable stricter Typescript options
Browse files Browse the repository at this point in the history
Port 3750e80 to glitch-soc

Signed-off-by: Claire <[email protected]>
  • Loading branch information
renchap authored and ClearlyClaire committed May 29, 2024
1 parent 6b4c182 commit 2e3d6e4
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 16 deletions.
5 changes: 3 additions & 2 deletions app/javascript/flavours/glitch/components/animated_number.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ export const AnimatedNumber: React.FC<Props> = ({ value, obfuscate }) => {
<span
key={key}
style={{
position: direction * style.y > 0 ? 'absolute' : 'static',
transform: `translateY(${style.y * 100}%)`,
position:
direction * (style.y ?? 0) > 0 ? 'absolute' : 'static',
transform: `translateY(${(style.y ?? 0) * 100}%)`,
}}
>
{obfuscate ? (
Expand Down
7 changes: 5 additions & 2 deletions app/javascript/flavours/glitch/components/hashtag_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ function uniqueHashtagsWithCaseHandling(hashtags: string[]) {
);

return Object.values(groups).map((tags) => {
if (tags.length === 1) return tags[0];
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we know that the array has at least one element
const firstTag = tags[0]!;

if (tags.length === 1) return firstTag;

// The best match is the one where we have the less difference between upper and lower case letter count
const best = minBy(tags, (tag) => {
Expand All @@ -66,7 +69,7 @@ function uniqueHashtagsWithCaseHandling(hashtags: string[]) {
return Math.abs(lowerCase - upperCase);
});

return best ?? tags[0];
return best ?? firstTag;
});
}

Expand Down
2 changes: 1 addition & 1 deletion app/javascript/flavours/glitch/components/short_number.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const ShortNumberCounter: React.FC<ShortNumberCounterProps> = ({ value }) => {

const count = (
<FormattedNumber
value={rawNumber}
value={rawNumber ?? 0}
maximumFractionDigits={maxFractionDigits}
/>
);
Expand Down
12 changes: 6 additions & 6 deletions app/javascript/flavours/glitch/entrypoints/public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ window.addEventListener('message', (e) => {
{
type: 'setHeight',
id: data.id,
height: document.getElementsByTagName('html')[0].scrollHeight,
height: document.getElementsByTagName('html')[0]?.scrollHeight,
},
'*',
);
Expand Down Expand Up @@ -135,7 +135,7 @@ function loaded() {
);
};
const todayFormat = new IntlMessageFormat(
localeData['relative_format.today'] || 'Today at {time}',
localeData['relative_format.today'] ?? 'Today at {time}',
locale,
);

Expand Down Expand Up @@ -288,13 +288,13 @@ function loaded() {
if (statusEl.dataset.spoiler === 'expanded') {
statusEl.dataset.spoiler = 'folded';
this.textContent = new IntlMessageFormat(
localeData['status.show_more'] || 'Show more',
localeData['status.show_more'] ?? 'Show more',
locale,
).format() as string;
} else {
statusEl.dataset.spoiler = 'expanded';
this.textContent = new IntlMessageFormat(
localeData['status.show_less'] || 'Show less',
localeData['status.show_less'] ?? 'Show less',
locale,
).format() as string;
}
Expand All @@ -316,8 +316,8 @@ function loaded() {

const message =
statusEl.dataset.spoiler === 'expanded'
? localeData['status.show_less'] || 'Show less'
: localeData['status.show_more'] || 'Show more';
? localeData['status.show_less'] ?? 'Show less'
: localeData['status.show_more'] ?? 'Show more';
spoilerLink.textContent = new IntlMessageFormat(
message,
locale,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ const fetchInteractionURLFailure = () => {
);
};

const isValidDomain = (value: string) => {
const isValidDomain = (value: unknown) => {
if (typeof value !== 'string') return false;

const url = new URL('https:///path');
url.hostname = value;
return url.hostname === value;
Expand Down Expand Up @@ -124,6 +126,11 @@ const fromAcct = (acct: string) => {
const domain = segments[1];
const fallbackTemplate = `https://${domain}/authorize_interaction?uri={uri}`;

if (!domain) {
fetchInteractionURLFailure();
return;
}

axios
.get(`https://${domain}/.well-known/webfinger`, {
params: { resource: `acct:${acct}` },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ const emojis: Emojis = {};

// decompress
Object.keys(shortCodesToEmojiData).forEach((shortCode) => {
const [_filenameData, searchData] = shortCodesToEmojiData[shortCode];
const emojiData = shortCodesToEmojiData[shortCode];
if (!emojiData) return;

const [_filenameData, searchData] = emojiData;
const [native, short_names, search, unified] = searchData;

emojis[shortCode] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ function processEmojiMapData(
Object.keys(shortCodesToEmojiData).forEach(
(shortCode: ShortCodesToEmojiDataKey) => {
if (shortCode === undefined) return;
const [filenameData, _searchData] = shortCodesToEmojiData[shortCode];

const emojiData = shortCodesToEmojiData[shortCode];
if (!emojiData) return;
const [filenameData, _searchData] = emojiData;
filenameData.forEach((emojiMapData) => {
processEmojiMapData(emojiMapData, shortCode);
});
Expand Down
5 changes: 3 additions & 2 deletions app/javascript/flavours/glitch/store/middlewares/sounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ export const soundsMiddleware = (): Middleware<
if (isActionWithMetaSound(action)) {
const sound = action.meta.sound;

if (sound && Object.hasOwn(soundCache, sound)) {
play(soundCache[sound]);
if (sound) {
const s = soundCache[sound];
if (s) play(s);
}
}

Expand Down

0 comments on commit 2e3d6e4

Please sign in to comment.