@@ -1,22 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
max_line_length = 120
|
||||
tab_width = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.ex]
|
||||
indent_size = 2
|
||||
tab_width = 2
|
||||
|
||||
[*.scss]
|
||||
indent_size = 2
|
||||
|
||||
[*.ts]
|
||||
indent_size = 2
|
||||
tab_width = 2
|
||||
@@ -1,5 +1,9 @@
|
||||
async function asyncForEach(array: Array<any>, callback: Function) {
|
||||
async function asyncForEach(
|
||||
array: Array<any>,
|
||||
callback: (arg0: any, arg1: number, arg2: Array<any>) => any
|
||||
): Promise<void> {
|
||||
for (let index = 0; index < array.length; index += 1) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await callback(array[index], index, array);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ import {
|
||||
import { ILogin, IToken } from "@/types/login.model";
|
||||
import { UPDATE_CURRENT_USER_CLIENT } from "@/graphql/user";
|
||||
import ApolloClient from "apollo-client";
|
||||
import { ICurrentUserRole } from "@/types/current-user.model";
|
||||
import { IPerson } from "@/types/actor";
|
||||
import { IDENTITIES, UPDATE_CURRENT_ACTOR_CLIENT } from "@/graphql/actor";
|
||||
import { NormalizedCacheObject } from "apollo-cache-inmemory";
|
||||
import { ICurrentUserRole } from "@/types/enums";
|
||||
|
||||
export function saveTokenData(obj: IToken): void {
|
||||
localStorage.setItem(AUTH_ACCESS_TOKEN, obj.accessToken);
|
||||
@@ -37,14 +37,19 @@ export function saveActorData(obj: IPerson): void {
|
||||
}
|
||||
|
||||
export function deleteUserData(): void {
|
||||
[AUTH_USER_ID, AUTH_USER_EMAIL, AUTH_ACCESS_TOKEN, AUTH_REFRESH_TOKEN, AUTH_USER_ROLE].forEach((key) => {
|
||||
localStorage.removeItem(key);
|
||||
});
|
||||
[AUTH_USER_ID, AUTH_USER_EMAIL, AUTH_ACCESS_TOKEN, AUTH_REFRESH_TOKEN, AUTH_USER_ROLE].forEach(
|
||||
(key) => {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export class NoIdentitiesException extends Error {}
|
||||
|
||||
export async function changeIdentity(apollo: ApolloClient<NormalizedCacheObject>, identity: IPerson): Promise<void> {
|
||||
export async function changeIdentity(
|
||||
apollo: ApolloClient<NormalizedCacheObject>,
|
||||
identity: IPerson
|
||||
): Promise<void> {
|
||||
await apollo.mutate({
|
||||
mutation: UPDATE_CURRENT_ACTOR_CLIENT,
|
||||
variables: identity,
|
||||
@@ -69,7 +74,8 @@ export async function initializeCurrentActor(apollo: ApolloClient<any>): Promise
|
||||
console.warn("Logged user has no identities!");
|
||||
throw new NoIdentitiesException();
|
||||
}
|
||||
const activeIdentity = identities.find((identity: IPerson) => identity.id === actorId) || (identities[0] as IPerson);
|
||||
const activeIdentity =
|
||||
identities.find((identity: IPerson) => identity.id === actorId) || (identities[0] as IPerson);
|
||||
|
||||
if (activeIdentity) {
|
||||
await changeIdentity(apollo, activeIdentity);
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export function nl2br(text: string) {
|
||||
export function nl2br(text: string): string {
|
||||
return text.replace(/(?:\r\n|\r|\n)/g, "<br>");
|
||||
}
|
||||
|
||||
@@ -7,10 +7,15 @@ import langs from "../i18n/langs.json";
|
||||
|
||||
const DEFAULT_LOCALE = "en_US";
|
||||
|
||||
let language = localStorage.getItem(USER_LOCALE) || (document.documentElement.getAttribute("lang") as string);
|
||||
language = language || ((window.navigator as any).userLanguage || window.navigator.language).replace(/-/, "_");
|
||||
let language =
|
||||
localStorage.getItem(USER_LOCALE) || (document.documentElement.getAttribute("lang") as string);
|
||||
language =
|
||||
language ||
|
||||
((window.navigator as any).userLanguage || window.navigator.language).replace(/-/, "_");
|
||||
export const locale =
|
||||
language && Object.prototype.hasOwnProperty.call(langs, language) ? language : language.split("-")[0];
|
||||
language && Object.prototype.hasOwnProperty.call(langs, language)
|
||||
? language
|
||||
: language.split("-")[0];
|
||||
|
||||
Vue.use(VueI18n);
|
||||
|
||||
|
||||
@@ -9,7 +9,11 @@ export async function buildFileFromIMedia(obj: IMedia | null | undefined): Promi
|
||||
return new File([blob], obj.name);
|
||||
}
|
||||
|
||||
export function buildFileVariable(file: File | null, name: string, alt?: string): Record<string, unknown> {
|
||||
export function buildFileVariable(
|
||||
file: File | null,
|
||||
name: string,
|
||||
alt?: string
|
||||
): Record<string, unknown> {
|
||||
if (!file) return {};
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
export function buildObjectCollection<T, U>(collection: T[] | undefined, builder: new (p: T) => U) {
|
||||
if (!collection || Array.isArray(collection) === false) return [];
|
||||
|
||||
return collection.map((v) => new builder(v));
|
||||
}
|
||||
@@ -1,15 +1,5 @@
|
||||
import { IActor } from "@/types/actor";
|
||||
|
||||
function autoUpdateUsername(actor: IActor, newDisplayName: string | null): IActor {
|
||||
const oldUsername = convertToUsername(actor.name);
|
||||
|
||||
if (actor.preferredUsername === oldUsername) {
|
||||
actor.preferredUsername = convertToUsername(newDisplayName);
|
||||
}
|
||||
|
||||
return actor;
|
||||
}
|
||||
|
||||
function convertToUsername(value: string | null): string {
|
||||
if (!value) return "";
|
||||
|
||||
@@ -22,6 +12,17 @@ function convertToUsername(value: string | null): string {
|
||||
.replace(/[^a-z0-9_]/g, "");
|
||||
}
|
||||
|
||||
function autoUpdateUsername(actor: IActor, newDisplayName: string | null): IActor {
|
||||
const actor2 = { ...actor };
|
||||
const oldUsername = convertToUsername(actor.name);
|
||||
|
||||
if (actor.preferredUsername === oldUsername) {
|
||||
actor2.preferredUsername = convertToUsername(newDisplayName);
|
||||
}
|
||||
|
||||
return actor2;
|
||||
}
|
||||
|
||||
function validateUsername(actor: IActor): boolean {
|
||||
return actor.preferredUsername === convertToUsername(actor.preferredUsername);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export function validateEmailField(value: string) {
|
||||
export function validateEmailField(value: string): boolean | string {
|
||||
return value.includes("@") || "Invalid e-mail.";
|
||||
}
|
||||
|
||||
export function validateRequiredField(value: any) {
|
||||
export function validateRequiredField(value: unknown): boolean | string {
|
||||
return !!value || "Required.";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user