(ts) migrate remaining .js files in ~/src to typescript

This commit is contained in:
Valentyne Stigloher 2025-01-02 23:12:37 +01:00
parent 4edd90af7d
commit 374f8b8120
13 changed files with 56 additions and 45 deletions

View File

@ -40,8 +40,8 @@
import { mapState } from 'pinia';
import useConfig from '../composables/useConfig.ts';
import adPlaceholders from '../src/adPlaceholders.js';
import getAdsInternal from '../src/adsInternal.js';
import adPlaceholders from '../src/adPlaceholders.ts';
import getAdsInternal from '../src/adsInternal.ts';
import { randomItemWeighted } from '../src/helpers.ts';
import { useMainStore } from '../store/index.ts';

View File

@ -67,7 +67,7 @@
<script>
import useConfig from '../composables/useConfig.ts';
import { socialLinks } from '../src/contact.js';
import { socialLinks } from '../src/contact.ts';
import { clearUrl } from '../src/helpers.ts';
export default {

View File

@ -194,7 +194,7 @@ import { useFetch } from 'nuxt/app';
import useConfig from '../composables/useConfig.ts';
import useDialogue from '../composables/useDialogue.ts';
import { getContactLinks, getSocialLinks, getSupportLinks } from '../src/contact.js';
import { getContactLinks, getSocialLinks, getSupportLinks } from '../src/contact.ts';
import { sessionCookieSetting } from '../src/cookieSettings.ts';
import { groupBy } from '../src/helpers.ts';
import { useMainStore } from '../store/index.ts';

View File

@ -29,7 +29,7 @@
<script>
import ClipboardJS from 'clipboard';
import { COLOURS } from '../src/contact.js';
import { COLOURS } from '../src/contact.ts';
// adapted from https://shareon.js.org (MIT)
// can't use from yarn, because window.onload conflicts with SSR

View File

@ -21,18 +21,15 @@
import { defineComponent } from 'vue';
import useConfig from '../composables/useConfig.ts';
import { getSocialLinks } from '../src/contact.js';
import { getSocialLinks } from '../src/contact.ts';
import { groupBy } from '../src/helpers.ts';
export default defineComponent({
setup() {
const config = useConfig();
return {
config: useConfig(),
};
},
data() {
return {
socials: groupBy([...getSocialLinks(this.config)], (l) => l.group),
config,
socials: groupBy([...getSocialLinks(config)], (l) => l.group),
};
},
});

View File

@ -29,7 +29,7 @@
</template>
<script>
import { getSupportLinks } from '../src/contact.js';
import { getSupportLinks } from '../src/contact.ts';
export default {
data() {

View File

@ -151,7 +151,7 @@ import { useNuxtApp } from 'nuxt/app';
import useDialogue from '~/composables/useDialogue.ts';
import useSimpleHead from '~/composables/useSimpleHead.ts';
import { min, max, closed, MONTHS, AREAS, TRANSFER_METHODS } from '~/src/timesheets.js';
import { min, max, closed, MONTHS, AREAS, TRANSFER_METHODS } from '~/src/timesheets.ts';
export default {
async setup() {

View File

@ -108,7 +108,7 @@ import { DateTime } from 'luxon';
import { useNuxtApp } from 'nuxt/app';
import useSimpleHead from '~/composables/useSimpleHead.ts';
import { min, max, MONTHS, PERIODS } from '~/src/timesheets.js';
import { min, max, MONTHS, PERIODS } from '~/src/timesheets.ts';
function* range(start, end) {
for (let i = start; i <= end; i++) {

View File

@ -98,7 +98,7 @@ import { defineComponent } from 'vue';
import useConfig from '../composables/useConfig.ts';
import useSimpleHead from '../composables/useSimpleHead.ts';
import { getContactLinks, getSocialLinks } from '../src/contact.js';
import { getContactLinks, getSocialLinks } from '../src/contact.ts';
import { groupBy } from '../src/helpers.ts';
export default defineComponent({
@ -111,14 +111,12 @@ export default defineComponent({
useSimpleHead({
title: translator.translate('contact.header'),
}, translator);
const config = useConfig();
return {
config: useConfig(),
};
},
data() {
return {
config,
links: groupBy(
[...getContactLinks(this.config, this.$translator), ...getSocialLinks(this.config)],
[...getContactLinks(config, translator), ...getSocialLinks(config)],
(l) => l.group,
),
};

View File

@ -1,4 +1,14 @@
export const adsInternal = [
interface Ad {
enabled: boolean;
locale: string;
image: string;
placeholders: string[];
link: string;
display: string;
alt: string;
}
export const adsInternal: Ad[] = [
{
enabled: false,
locale: 'en',
@ -72,8 +82,8 @@ export const adsInternal = [
// },
];
export default (locale) => {
const adsInternalPerPlaceholder = {};
export default (locale: string): Record<string, (Ad & { chance: number })[]> => {
const adsInternalPerPlaceholder: Record<string, (Ad & { chance: number })[]> = {};
for (const ad of adsInternal) {
const rightLocale = ad.locale === null || ad.locale === locale;
if (ad.enabled === false || !rightLocale) {

View File

@ -1,4 +1,16 @@
export const contact = {
import type { Config, Link } from '~/locale/config.ts';
import type { Translator } from '~/src/translator.ts';
interface ContactLink extends Link {
group: string;
colour: string;
avatar?: string | undefined;
}
type Group = 'all' | 'calendar' | 'polish' | 'shop';
type GroupedLinks = Partial<Record<Group, Record<string, Link>>>;
export const contact: GroupedLinks = {
all: {
discord_community: {
icon: 'b:discord',
@ -40,7 +52,7 @@ export const contact = {
},
};
export const socialLinks = {
export const socialLinks: GroupedLinks = {
all: {
mastodon: {
icon: 'mastodon',
@ -50,7 +62,6 @@ export const socialLinks = {
},
bluesky: {
icon: 'bluesky',
iconSet: '',
url: 'https://bsky.app/profile/pronouns.page',
headline: 'pronouns.page',
},
@ -71,7 +82,6 @@ export const socialLinks = {
},
bluesky: {
icon: 'bluesky',
iconSet: '',
url: 'https://bsky.app/profile/zaimki.pl',
headline: 'zaimki.pl',
},
@ -110,7 +120,6 @@ export const socialLinks = {
},
bluesky: {
icon: 'bluesky',
iconSet: '',
url: 'https://bsky.app/profile/calendar.pronouns.page',
headline: 'calendar.pronouns.page',
},
@ -131,7 +140,7 @@ export const socialLinks = {
},
};
export const COLOURS = {
export const COLOURS: Record<string, string> = {
mastodon: '#3188d4',
facebook: '#1877F2',
linkedin: '#2867B2',
@ -152,13 +161,13 @@ export const COLOURS = {
workshops: '#C71585',
};
const AVATARS = {
const AVATARS: Partial<Record<Group, string>> = {
all: 'pronounspage.png',
polish: 'neutratywy.png',
calendar: 'calendarqueer.png',
};
const supportLinks = (translator) => {
const supportLinks = (translator: Translator): GroupedLinks => {
return {
all: {
bank: {
@ -182,15 +191,12 @@ const supportLinks = (translator) => {
};
};
function* getLink(links, group) {
function* getLink(links: GroupedLinks, group: Group): Generator<ContactLink> {
const featureLinks = links[group] || {};
for (const key in featureLinks) {
if (!featureLinks.hasOwnProperty(key)) {
continue;
}
let avatar = AVATARS[group];
if (featureLinks[key].url.startsWith('mailto:')) {
avatar = null;
for (const [key, link] of Object.entries(featureLinks)) {
let avatar: string | undefined = AVATARS[group];
if (link.url?.startsWith('mailto:')) {
avatar = undefined;
}
yield {
...featureLinks[key],
@ -201,7 +207,7 @@ function* getLink(links, group) {
}
}
export function* getContactLinks(config, translator) {
export function* getContactLinks(config: Config, translator: Translator): Generator<ContactLink> {
if (config.faq.enabled) {
yield {
url: `/${config.faq.route}`,
@ -226,7 +232,7 @@ export function* getContactLinks(config, translator) {
}
}
export function* getSocialLinks(config) {
export function* getSocialLinks(config: Config) {
yield * getLink(socialLinks, 'all');
if (config.locale === 'pl') {
yield * getLink(socialLinks, 'polish');
@ -237,6 +243,6 @@ export function* getSocialLinks(config) {
yield * getLink(socialLinks, 'shop');
}
export function* getSupportLinks(translator) {
export function* getSupportLinks(translator: Translator) {
yield * getLink(supportLinks(translator), 'all');
}

View File

@ -26,7 +26,7 @@ export const AREAS = [
'documentation',
'community',
'other',
];
] as const;
export const MONTHS = {
1: 'Jan',