Add /@username routes for profile pages

https://codeberg.org/silverpill/mitra/issues/22
This commit is contained in:
silverpill 2022-12-28 22:42:04 +00:00
parent a13d9a27a6
commit fa7c267f26
4 changed files with 36 additions and 4 deletions

View file

@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased] ## [Unreleased]
### Added
- Added `/@username` routes for profile pages.
### Changed ### Changed
- Changed text on Ethereum page. - Changed text on Ethereum page.

View file

@ -187,6 +187,19 @@ export async function getCurrentUser(authToken: string): Promise<User | null> {
return data return data
} }
export async function lookupProfile(
authToken: string | null,
acct: string,
): Promise<Profile> {
const url = `${BACKEND_URL}/api/v1/accounts/lookup`
const response = await http(url, { authToken, queryParams: { acct } })
const data = await response.json()
if (response.status !== 200) {
throw new Error(data.message)
}
return data
}
export async function getProfile( export async function getProfile(
authToken: string | null, authToken: string | null,
profileId: string, profileId: string,

View file

@ -146,6 +146,12 @@ const routes: Array<RouteRecordRaw> = [
component: SubscriptionsSettings, component: SubscriptionsSettings,
meta: { onlyAuthenticated: true }, meta: { onlyAuthenticated: true },
}, },
{
path: "/@:acct(.*)",
name: "profile-by-acct",
component: ProfileView,
meta: { },
},
{ {
path: "/:pathMatch(.*)*", path: "/:pathMatch(.*)*",
redirect: { name: "home" }, redirect: { name: "home" },

View file

@ -256,6 +256,7 @@ import {
import { getReceivedSubscriptions } from "@/api/subscriptions-common" import { getReceivedSubscriptions } from "@/api/subscriptions-common"
import { import {
getProfile, getProfile,
lookupProfile,
Profile, Profile,
ProfileField, ProfileField,
ProfileWrapper, ProfileWrapper,
@ -296,10 +297,18 @@ let followListNextPageUrl = $ref<string | null>(null)
onMounted(async () => { onMounted(async () => {
isLoading = true isLoading = true
try { try {
const _profile = await getProfile( let _profile
if (route.params.acct) {
_profile = await lookupProfile(
authToken,
route.params.acct as string,
)
} else {
_profile = await getProfile(
authToken, authToken,
route.params.profileId as string, route.params.profileId as string,
) )
}
profile = new ProfileWrapper(_profile) profile = new ProfileWrapper(_profile)
} catch (error: any) { } catch (error: any) {
if (error.message === "profile not found") { if (error.message === "profile not found") {