mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-22 20:31:13 +00:00
export default everything, will fix type errors next
This commit is contained in:
parent
b1b0fdf5f8
commit
f53d5db007
20 changed files with 41 additions and 34 deletions
|
@ -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";
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
export function isBrowser() {
|
export default function isBrowser() {
|
||||||
return typeof window !== "undefined";
|
return typeof window !== "undefined";
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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()) {
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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[],
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue