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,
showScores,
} from "../../utils";
import { amCommunityCreator } from "../../utils/roles/am-community-creator";
import { canAdmin } from "../../utils/roles/can-admin";
import { canMod } from "../../utils/roles/can-mod";
import { isAdmin } from "../../utils/roles/is-admin";
import { isBanned } from "../../utils/roles/is-banned";
import { isMod } from "../../utils/roles/is-mod";
import amCommunityCreator from "../../utils/roles/am-community-creator";
import canAdmin from "../../utils/roles/can-admin";
import canMod from "../../utils/roles/can-mod";
import isAdmin from "../../utils/roles/is-admin";
import isBanned from "../../utils/roles/is-banned";
import isMod from "../../utils/roles/is-mod";
import { Icon, PurgeWarning, Spinner } from "../common/icon";
import { MomentTime } from "../common/moment-time";
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;
}

View file

@ -1,3 +1,3 @@
export function isBrowser() {
export default function isBrowser() {
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()) {
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,
wait = 1000,
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];
}): T {
if (isBrowser()) {

View file

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

View file

@ -1,9 +1,9 @@
import { sleep } from "./sleep";
import sleep from "./sleep";
/**
* 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") {
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));
}

View file

@ -1,5 +1,7 @@
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;
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,8 @@
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;
}

View file

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

View file

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