export default everything, will fix type errors next

This commit is contained in:
Alec Armbruster 2023-06-19 21:12:42 -04:00
parent b1b0fdf5f8
commit f53d5db007
No known key found for this signature in database
GPG key ID: 0BE3206ADE0F3B3B
20 changed files with 41 additions and 34 deletions

View file

@ -53,12 +53,12 @@ import {
setupTippy, setupTippy,
showScores, showScores,
} from "../../utils"; } from "../../utils";
import { amCommunityCreator } from "../../utils/roles/am-community-creator"; import amCommunityCreator from "../../utils/roles/am-community-creator";
import { canAdmin } from "../../utils/roles/can-admin"; import canAdmin from "../../utils/roles/can-admin";
import { canMod } from "../../utils/roles/can-mod"; import canMod from "../../utils/roles/can-mod";
import { isAdmin } from "../../utils/roles/is-admin"; import isAdmin from "../../utils/roles/is-admin";
import { isBanned } from "../../utils/roles/is-banned"; import isBanned from "../../utils/roles/is-banned";
import { isMod } from "../../utils/roles/is-mod"; import isMod from "../../utils/roles/is-mod";
import { Icon, PurgeWarning, Spinner } from "../common/icon"; import { Icon, PurgeWarning, Spinner } from "../common/icon";
import { MomentTime } from "../common/moment-time"; import { MomentTime } from "../common/moment-time";
import { CommunityLink } from "../community/community-link"; import { CommunityLink } from "../community/community-link";

View file

@ -1,5 +1,5 @@
import { isBrowser } from "./is-browser"; import isBrowser from "./is-browser";
export function canShare() { export default function canShare() {
return isBrowser() && !!navigator.canShare; return isBrowser() && !!navigator.canShare;
} }

View file

@ -1,3 +1,3 @@
export function isBrowser() { export default function isBrowser() {
return typeof window !== "undefined"; return typeof window !== "undefined";
} }

View file

@ -1,6 +1,6 @@
import { isBrowser } from "./is-browser"; import isBrowser from "./is-browser";
export function share(shareData: ShareData) { export default function share(shareData: ShareData) {
if (isBrowser()) { if (isBrowser()) {
navigator.share(shareData); navigator.share(shareData);
} }

View file

@ -1,4 +1,4 @@
export function debounce<T extends any[], R>( export default function debounce<T extends any[], R>(
func: (...e: T) => R, func: (...e: T) => R,
wait = 1000, wait = 1000,
immediate = false immediate = false

View file

@ -1,6 +1,8 @@
import { isBrowser } from "../browser/is-browser"; import isBrowser from "../browser/is-browser";
export function getQueryParams<T extends Record<string, any>>(processors: { export default function getQueryParams<
T extends Record<string, any>
>(processors: {
[K in keyof T]: (param: string) => T[K]; [K in keyof T]: (param: string) => T[K];
}): T { }): T {
if (isBrowser()) { if (isBrowser()) {

View file

@ -1,6 +1,6 @@
export function getQueryString<T extends Record<string, string | undefined>>( export default function getQueryString<
obj: T T extends Record<string, string | undefined>
) { >(obj: T) {
return Object.entries(obj) return Object.entries(obj)
.filter(([, val]) => val !== undefined && val !== null) .filter(([, val]) => val !== undefined && val !== null)
.reduce( .reduce(

View file

@ -1,9 +1,9 @@
import { sleep } from "./sleep"; import sleep from "./sleep";
/** /**
* Polls / repeatedly runs a promise, every X milliseconds * Polls / repeatedly runs a promise, every X milliseconds
*/ */
export async function poll(promiseFn: any, millis: number) { export default async function poll(promiseFn: any, millis: number) {
if (window.document.visibilityState !== "hidden") { if (window.document.visibilityState !== "hidden") {
await promiseFn(); await promiseFn();
} }

View file

@ -1,3 +1,3 @@
export function sleep(millis: number): Promise<void> { export default function sleep(millis: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, millis)); return new Promise(resolve => setTimeout(resolve, millis));
} }

View file

@ -1,5 +1,7 @@
import { UserService } from "../../services"; import { UserService } from "../../services";
export function amAdmin(myUserInfo = UserService.Instance.myUserInfo): boolean { export default function amAdmin(
myUserInfo = UserService.Instance.myUserInfo
): boolean {
return myUserInfo?.local_user_view.person.admin ?? false; return myUserInfo?.local_user_view.person.admin ?? false;
} }

View file

@ -1,7 +1,7 @@
import { CommunityModeratorView } from "lemmy-js-client"; import { CommunityModeratorView } from "lemmy-js-client";
import { UserService } from "../../services"; import { UserService } from "../../services";
export function amCommunityCreator( export default function amCommunityCreator(
creator_id: number, creator_id: number,
mods?: CommunityModeratorView[], mods?: CommunityModeratorView[],
myUserInfo = UserService.Instance.myUserInfo myUserInfo = UserService.Instance.myUserInfo

View file

@ -1,8 +1,8 @@
import { CommunityModeratorView } from "lemmy-js-client"; import { CommunityModeratorView } from "lemmy-js-client";
import { UserService } from "../../services"; import { UserService } from "../../services";
import { isMod } from "./is-mod"; import isMod from "./is-mod";
export function amMod( export default function amMod(
mods?: CommunityModeratorView[], mods?: CommunityModeratorView[],
myUserInfo = UserService.Instance.myUserInfo myUserInfo = UserService.Instance.myUserInfo
): boolean { ): boolean {

View file

@ -1,7 +1,7 @@
import { PersonView } from "lemmy-js-client"; import { PersonView } from "lemmy-js-client";
import { UserService } from "../../services"; import { UserService } from "../../services";
export function amSiteCreator( export default function amSiteCreator(
creator_id: number, creator_id: number,
admins?: PersonView[], admins?: PersonView[],
myUserInfo = UserService.Instance.myUserInfo myUserInfo = UserService.Instance.myUserInfo

View file

@ -1,7 +1,7 @@
import { CommunityModeratorView } from "lemmy-js-client"; import { CommunityModeratorView } from "lemmy-js-client";
import { UserService } from "../../services"; import { UserService } from "../../services";
export function amTopMod( export default function amTopMod(
mods: CommunityModeratorView[], mods: CommunityModeratorView[],
myUserInfo = UserService.Instance.myUserInfo myUserInfo = UserService.Instance.myUserInfo
): boolean { ): boolean {

View file

@ -1,8 +1,8 @@
import { PersonView } from "lemmy-js-client"; import { PersonView } from "lemmy-js-client";
import { UserService } from "../../services"; import { UserService } from "../../services";
import { canMod } from "./can-mod"; import canMod from "./can-mod";
export function canAdmin( export default function canAdmin(
creatorId: number, creatorId: number,
admins?: PersonView[], admins?: PersonView[],
myUserInfo = UserService.Instance.myUserInfo, myUserInfo = UserService.Instance.myUserInfo,

View file

@ -1,8 +1,8 @@
import { GetSiteResponse } from "lemmy-js-client"; import { GetSiteResponse } from "lemmy-js-client";
import { UserService } from "../../services"; import { UserService } from "../../services";
import { amAdmin } from "./am-admin"; import amAdmin from "./am-admin";
export function canCreateCommunity( export default function canCreateCommunity(
siteRes: GetSiteResponse, siteRes: GetSiteResponse,
myUserInfo = UserService.Instance.myUserInfo myUserInfo = UserService.Instance.myUserInfo
): boolean { ): boolean {

View file

@ -1,7 +1,7 @@
import { CommunityModeratorView, PersonView } from "lemmy-js-client"; import { CommunityModeratorView, PersonView } from "lemmy-js-client";
import { UserService } from "../../services"; import { UserService } from "../../services";
export function canMod( export default function canMod(
creator_id: number, creator_id: number,
mods?: CommunityModeratorView[], mods?: CommunityModeratorView[],
admins?: PersonView[], admins?: PersonView[],

View file

@ -1,5 +1,8 @@
import { PersonView } from "lemmy-js-client"; import { PersonView } from "lemmy-js-client";
export function isAdmin(creatorId: number, admins?: PersonView[]): boolean { export default function isAdmin(
creatorId: number,
admins?: PersonView[]
): boolean {
return admins?.map(a => a.person.id).includes(creatorId) ?? false; return admins?.map(a => a.person.id).includes(creatorId) ?? false;
} }

View file

@ -1,6 +1,6 @@
import { Person } from "lemmy-js-client"; import { Person } from "lemmy-js-client";
export function isBanned(ps: Person): boolean { export default function isBanned(ps: Person): boolean {
const expires = ps.ban_expires; const expires = ps.ban_expires;
// Add Z to convert from UTC date // Add Z to convert from UTC date
// TODO this check probably isn't necessary anymore // TODO this check probably isn't necessary anymore

View file

@ -1,6 +1,6 @@
import { CommunityModeratorView } from "lemmy-js-client"; import { CommunityModeratorView } from "lemmy-js-client";
export function isMod( export default function isMod(
creatorId: number, creatorId: number,
mods?: CommunityModeratorView[] mods?: CommunityModeratorView[]
): boolean { ): boolean {