mirror of
https://github.com/modrinth/code.git
synced 2026-08-26 09:34:50 +00:00
feat: move users page to xplat page system (#6889)
* feat: move users page to xplat * feat: stop doing tauri plugin open for user links * feat: qa * fix: qa * fix: qa * fix: comment * fix: prepr * prepr * prepr * prepr --------- Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
This commit is contained in:
@@ -1,11 +1,56 @@
|
||||
import type { Labrinth } from '@modrinth/api-client'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
|
||||
export type SearchUser = {
|
||||
id: string
|
||||
username: string
|
||||
avatar_url: string | null
|
||||
// Converts user profile links from rendered Markdown/any dynamic content into app routes.
|
||||
export function parse_modrinth_user_link(href: string): string | null {
|
||||
try {
|
||||
const url = new URL(href)
|
||||
if (url.hostname !== 'modrinth.com' && url.hostname !== 'www.modrinth.com') return null
|
||||
|
||||
const segments = url.pathname.split('/').filter(Boolean)
|
||||
if (segments[0]?.toLowerCase() !== 'user' || !segments[1] || segments.length > 3) return null
|
||||
|
||||
const path = `/user/${encodeURIComponent(decodeURIComponent(segments[1]))}`
|
||||
return segments[2] ? `${path}/${encodeURIComponent(decodeURIComponent(segments[2]))}` : path
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function search_user(query: string): Promise<SearchUser[]> {
|
||||
return await invoke<SearchUser[]>('plugin:users|search_user', { query })
|
||||
export async function search_user(query: string): Promise<Labrinth.Users.v3.SearchUser[]> {
|
||||
return await invoke<Labrinth.Users.v3.SearchUser[]>('plugin:users|search_user', { query })
|
||||
}
|
||||
|
||||
export async function get_user_profile(userId: string): Promise<Labrinth.Users.v3.User> {
|
||||
return await invoke<Labrinth.Users.v3.User>('plugin:users|get_user_profile', { userId })
|
||||
}
|
||||
|
||||
export async function get_user_projects(userId: string): Promise<Labrinth.Projects.v2.Project[]> {
|
||||
return await invoke<Labrinth.Projects.v2.Project[]>('plugin:users|get_user_projects', {
|
||||
userId,
|
||||
})
|
||||
}
|
||||
|
||||
export async function get_user_organizations(
|
||||
userId: string,
|
||||
): Promise<Labrinth.Organizations.v3.Organization[]> {
|
||||
return await invoke<Labrinth.Organizations.v3.Organization[]>(
|
||||
'plugin:users|get_user_organizations',
|
||||
{ userId },
|
||||
)
|
||||
}
|
||||
|
||||
export async function get_user_collections(
|
||||
userId: string,
|
||||
): Promise<Labrinth.Collections.Collection[]> {
|
||||
return await invoke<Labrinth.Collections.Collection[]>('plugin:users|get_user_collections', {
|
||||
userId,
|
||||
})
|
||||
}
|
||||
|
||||
export async function patch_user(
|
||||
userId: string,
|
||||
patch: Partial<Pick<Labrinth.Users.v3.User, 'badges' | 'role'>>,
|
||||
): Promise<void> {
|
||||
await invoke('plugin:users|patch_user', { userId, patch })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user