You've already forked AstralRinth
forked from didirus/AstralRinth
refactor: migrate to common eslint+prettier configs (#4168)
* refactor: migrate to common eslint+prettier configs * fix: prettier frontend * feat: config changes * fix: lint issues * fix: lint * fix: type imports * fix: cyclical import issue * fix: lockfile * fix: missing dep * fix: switch to tabs * fix: continue switch to tabs * fix: rustfmt parity * fix: moderation lint issue * fix: lint issues * fix: ui intl * fix: lint issues * Revert "fix: rustfmt parity" This reverts commit cb99d2376c321d813d4b7fc7e2a213bb30a54711. * feat: revert last rs
This commit is contained in:
@@ -1,51 +1,52 @@
|
||||
import { useState } from "#app";
|
||||
import {
|
||||
type NotificationPanelLocation,
|
||||
type WebNotification,
|
||||
AbstractWebNotificationManager,
|
||||
} from "@modrinth/ui";
|
||||
AbstractWebNotificationManager,
|
||||
type NotificationPanelLocation,
|
||||
type WebNotification,
|
||||
} from '@modrinth/ui'
|
||||
|
||||
import { useState } from '#app'
|
||||
|
||||
export class FrontendNotificationManager extends AbstractWebNotificationManager {
|
||||
private readonly state: Ref<WebNotification[]>;
|
||||
private readonly locationState: Ref<NotificationPanelLocation>;
|
||||
private readonly state: Ref<WebNotification[]>
|
||||
private readonly locationState: Ref<NotificationPanelLocation>
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
this.state = useState<WebNotification[]>("notifications", () => []);
|
||||
this.locationState = useState<NotificationPanelLocation>(
|
||||
"notifications.location",
|
||||
() => "right",
|
||||
);
|
||||
}
|
||||
public constructor() {
|
||||
super()
|
||||
this.state = useState<WebNotification[]>('notifications', () => [])
|
||||
this.locationState = useState<NotificationPanelLocation>(
|
||||
'notifications.location',
|
||||
() => 'right',
|
||||
)
|
||||
}
|
||||
|
||||
public getNotificationLocation(): NotificationPanelLocation {
|
||||
return this.locationState.value;
|
||||
}
|
||||
public getNotificationLocation(): NotificationPanelLocation {
|
||||
return this.locationState.value
|
||||
}
|
||||
|
||||
public setNotificationLocation(location: NotificationPanelLocation): void {
|
||||
this.locationState.value = location;
|
||||
}
|
||||
public setNotificationLocation(location: NotificationPanelLocation): void {
|
||||
this.locationState.value = location
|
||||
}
|
||||
|
||||
public getNotifications(): WebNotification[] {
|
||||
return this.state.value;
|
||||
}
|
||||
public getNotifications(): WebNotification[] {
|
||||
return this.state.value
|
||||
}
|
||||
|
||||
protected addNotificationToStorage(notification: WebNotification): void {
|
||||
this.state.value.push(notification);
|
||||
}
|
||||
protected addNotificationToStorage(notification: WebNotification): void {
|
||||
this.state.value.push(notification)
|
||||
}
|
||||
|
||||
protected removeNotificationFromStorage(id: string | number): void {
|
||||
const index = this.state.value.findIndex((n) => n.id === id);
|
||||
if (index > -1) {
|
||||
this.state.value.splice(index, 1);
|
||||
}
|
||||
}
|
||||
protected removeNotificationFromStorage(id: string | number): void {
|
||||
const index = this.state.value.findIndex((n) => n.id === id)
|
||||
if (index > -1) {
|
||||
this.state.value.splice(index, 1)
|
||||
}
|
||||
}
|
||||
|
||||
protected removeNotificationFromStorageByIndex(index: number): void {
|
||||
this.state.value.splice(index, 1);
|
||||
}
|
||||
protected removeNotificationFromStorageByIndex(index: number): void {
|
||||
this.state.value.splice(index, 1)
|
||||
}
|
||||
|
||||
protected clearAllNotificationsFromStorage(): void {
|
||||
this.state.value.splice(0);
|
||||
}
|
||||
protected clearAllNotificationsFromStorage(): void {
|
||||
this.state.value.splice(0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,108 +1,108 @@
|
||||
import { createContext } from "@modrinth/ui";
|
||||
import { type Organization, type OrganizationMember, type ProjectV3 } from "@modrinth/utils";
|
||||
import { createContext } from '@modrinth/ui'
|
||||
import type { Organization, OrganizationMember, ProjectV3 } from '@modrinth/utils'
|
||||
|
||||
export class OrganizationContext {
|
||||
public readonly organization: Ref<Organization | null>;
|
||||
public readonly projects: Ref<ProjectV3[] | null>;
|
||||
private readonly auth: Ref<any>;
|
||||
private readonly tags: Ref<any>;
|
||||
private readonly refreshFunction: () => Promise<void>;
|
||||
public readonly organization: Ref<Organization | null>
|
||||
public readonly projects: Ref<ProjectV3[] | null>
|
||||
private readonly auth: Ref<any>
|
||||
private readonly tags: Ref<any>
|
||||
private readonly refreshFunction: () => Promise<void>
|
||||
|
||||
public constructor(
|
||||
organization: Ref<Organization | null>,
|
||||
projects: Ref<ProjectV3[] | null>,
|
||||
auth: Ref<any>,
|
||||
tags: Ref<any>,
|
||||
refreshFunction: () => Promise<void>,
|
||||
) {
|
||||
this.organization = organization;
|
||||
this.projects = projects;
|
||||
this.auth = auth;
|
||||
this.tags = tags;
|
||||
this.refreshFunction = refreshFunction;
|
||||
}
|
||||
public constructor(
|
||||
organization: Ref<Organization | null>,
|
||||
projects: Ref<ProjectV3[] | null>,
|
||||
auth: Ref<any>,
|
||||
tags: Ref<any>,
|
||||
refreshFunction: () => Promise<void>,
|
||||
) {
|
||||
this.organization = organization
|
||||
this.projects = projects
|
||||
this.auth = auth
|
||||
this.tags = tags
|
||||
this.refreshFunction = refreshFunction
|
||||
}
|
||||
|
||||
public refresh = async () => {
|
||||
if (this.organization.value === null) {
|
||||
throw new Error("Organization is not set.");
|
||||
}
|
||||
public refresh = async () => {
|
||||
if (this.organization.value === null) {
|
||||
throw new Error('Organization is not set.')
|
||||
}
|
||||
|
||||
await this.refreshFunction();
|
||||
};
|
||||
await this.refreshFunction()
|
||||
}
|
||||
|
||||
public currentMember = computed<Partial<OrganizationMember> | null>(() => {
|
||||
if (this.auth.value.user && this.organization.value) {
|
||||
const member = this.organization.value.members.find(
|
||||
(x) => x.user.id === this.auth.value.user.id,
|
||||
);
|
||||
public currentMember = computed<Partial<OrganizationMember> | null>(() => {
|
||||
if (this.auth.value.user && this.organization.value) {
|
||||
const member = this.organization.value.members.find(
|
||||
(x) => x.user.id === this.auth.value.user.id,
|
||||
)
|
||||
|
||||
if (member) {
|
||||
return member;
|
||||
}
|
||||
if (member) {
|
||||
return member
|
||||
}
|
||||
|
||||
if (this.tags.value.staffRoles.includes(this.auth.value.user.role)) {
|
||||
return {
|
||||
user: this.auth.value.user,
|
||||
role: this.auth.value.user.role,
|
||||
permissions: this.auth.value.user.role === "admin" ? 1023 : 12,
|
||||
accepted: true,
|
||||
payouts_split: 0,
|
||||
avatar_url: this.auth.value.user.avatar_url,
|
||||
name: this.auth.value.user.username,
|
||||
} as Partial<OrganizationMember>;
|
||||
}
|
||||
}
|
||||
if (this.tags.value.staffRoles.includes(this.auth.value.user.role)) {
|
||||
return {
|
||||
user: this.auth.value.user,
|
||||
role: this.auth.value.user.role,
|
||||
permissions: this.auth.value.user.role === 'admin' ? 1023 : 12,
|
||||
accepted: true,
|
||||
payouts_split: 0,
|
||||
avatar_url: this.auth.value.user.avatar_url,
|
||||
name: this.auth.value.user.username,
|
||||
} as Partial<OrganizationMember>
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
return null
|
||||
})
|
||||
|
||||
public hasPermission = computed(() => {
|
||||
const EDIT_DETAILS = 1 << 2;
|
||||
return (
|
||||
this.currentMember.value &&
|
||||
(this.currentMember.value.permissions & EDIT_DETAILS) === EDIT_DETAILS
|
||||
);
|
||||
});
|
||||
public hasPermission = computed(() => {
|
||||
const EDIT_DETAILS = 1 << 2
|
||||
return (
|
||||
this.currentMember.value &&
|
||||
(this.currentMember.value.permissions & EDIT_DETAILS) === EDIT_DETAILS
|
||||
)
|
||||
})
|
||||
|
||||
public patchIcon = async (icon: { name: string }) => {
|
||||
if (this.organization.value === null) {
|
||||
throw new Error("Organization is not set.");
|
||||
}
|
||||
public patchIcon = async (icon: { name: string }) => {
|
||||
if (this.organization.value === null) {
|
||||
throw new Error('Organization is not set.')
|
||||
}
|
||||
|
||||
const ext = icon.name.split(".").pop();
|
||||
await useBaseFetch(`organization/${this.organization.value.id}/icon`, {
|
||||
method: "PATCH",
|
||||
body: icon,
|
||||
query: { ext },
|
||||
apiVersion: 3,
|
||||
});
|
||||
};
|
||||
const ext = icon.name.split('.').pop()
|
||||
await useBaseFetch(`organization/${this.organization.value.id}/icon`, {
|
||||
method: 'PATCH',
|
||||
body: icon,
|
||||
query: { ext },
|
||||
apiVersion: 3,
|
||||
})
|
||||
}
|
||||
|
||||
public deleteIcon = async () => {
|
||||
if (this.organization.value === null) {
|
||||
throw new Error("Organization is not set.");
|
||||
}
|
||||
public deleteIcon = async () => {
|
||||
if (this.organization.value === null) {
|
||||
throw new Error('Organization is not set.')
|
||||
}
|
||||
|
||||
await useBaseFetch(`organization/${this.organization.value.id}/icon`, {
|
||||
method: "DELETE",
|
||||
apiVersion: 3,
|
||||
});
|
||||
};
|
||||
await useBaseFetch(`organization/${this.organization.value.id}/icon`, {
|
||||
method: 'DELETE',
|
||||
apiVersion: 3,
|
||||
})
|
||||
}
|
||||
|
||||
public patchOrganization = async (newData: { slug: any }) => {
|
||||
if (this.organization.value === null) {
|
||||
throw new Error("Organization is not set.");
|
||||
}
|
||||
public patchOrganization = async (newData: { slug: any }) => {
|
||||
if (this.organization.value === null) {
|
||||
throw new Error('Organization is not set.')
|
||||
}
|
||||
|
||||
await useBaseFetch(`organization/${this.organization.value.id}`, {
|
||||
method: "PATCH",
|
||||
body: newData,
|
||||
apiVersion: 3,
|
||||
});
|
||||
await useBaseFetch(`organization/${this.organization.value.id}`, {
|
||||
method: 'PATCH',
|
||||
body: newData,
|
||||
apiVersion: 3,
|
||||
})
|
||||
|
||||
await this.refreshFunction();
|
||||
};
|
||||
await this.refreshFunction()
|
||||
}
|
||||
}
|
||||
|
||||
export const [injectOrganizationContext, provideOrganizationContext] =
|
||||
createContext<OrganizationContext>("[id].vue", "organizationContext");
|
||||
createContext<OrganizationContext>('[id].vue', 'organizationContext')
|
||||
|
||||
Reference in New Issue
Block a user