Removing community and user routes in favor of shortnames. Fixes #317 (#343)

This commit is contained in:
Dessalines 2021-07-21 11:01:32 -04:00 committed by GitHub
parent 79ce0e864a
commit cffdfab8eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 55 deletions

View file

@ -27,11 +27,10 @@ export class CommunityLink extends Component<CommunityLinkProps, any> {
title = community.title; title = community.title;
link = `/c/${community.name}`; link = `/c/${community.name}`;
} else { } else {
name_ = `${community.name}@${hostname(community.actor_id)}`; let domain = hostname(community.actor_id);
title = `${community.title}@${hostname(community.actor_id)}`; name_ = `${community.name}@${domain}`;
link = !this.props.realLink title = `${community.title}@${domain}`;
? `/community/${community.id}` link = !this.props.realLink ? `/c/${name_}` : community.actor_id;
: community.actor_id;
} }
let apubName = `!${name_}`; let apubName = `!${name_}`;

View file

@ -61,7 +61,6 @@ import { CommunityLink } from "./community-link";
interface State { interface State {
communityRes: GetCommunityResponse; communityRes: GetCommunityResponse;
siteRes: GetSiteResponse; siteRes: GetSiteResponse;
communityId: number;
communityName: string; communityName: string;
communityLoading: boolean; communityLoading: boolean;
postsLoading: boolean; postsLoading: boolean;
@ -91,7 +90,6 @@ export class Community extends Component<any, State> {
private subscription: Subscription; private subscription: Subscription;
private emptyState: State = { private emptyState: State = {
communityRes: undefined, communityRes: undefined,
communityId: Number(this.props.match.params.id),
communityName: this.props.match.params.name, communityName: this.props.match.params.name,
communityLoading: true, communityLoading: true,
postsLoading: true, postsLoading: true,
@ -136,7 +134,6 @@ export class Community extends Component<any, State> {
fetchCommunity() { fetchCommunity() {
let form: GetCommunity = { let form: GetCommunity = {
id: this.state.communityId ? this.state.communityId : null,
name: this.state.communityName ? this.state.communityName : null, name: this.state.communityName ? this.state.communityName : null,
auth: authField(false), auth: authField(false),
}; };
@ -198,7 +195,7 @@ export class Community extends Component<any, State> {
saved_only: false, saved_only: false,
}; };
setOptionalAuth(getPostsForm, req.auth); setOptionalAuth(getPostsForm, req.auth);
this.setIdOrName(getPostsForm, id, name_); this.setName(getPostsForm, name_);
promises.push(req.client.getPosts(getPostsForm)); promises.push(req.client.getPosts(getPostsForm));
} else { } else {
let getCommentsForm: GetComments = { let getCommentsForm: GetComments = {
@ -209,19 +206,14 @@ export class Community extends Component<any, State> {
saved_only: false, saved_only: false,
}; };
setOptionalAuth(getCommentsForm, req.auth); setOptionalAuth(getCommentsForm, req.auth);
this.setIdOrName(getCommentsForm, id, name_);
promises.push(req.client.getComments(getCommentsForm)); promises.push(req.client.getComments(getCommentsForm));
} }
return promises; return promises;
} }
static setIdOrName(obj: any, id: number, name_: string) { static setName(obj: any, name_: string) {
if (id) { obj.community_name = name_;
obj.community_id = id;
} else {
obj.community_name = name_;
}
} }
componentDidUpdate(_: any, lastState: State) { componentDidUpdate(_: any, lastState: State) {
@ -404,9 +396,7 @@ export class Community extends Component<any, State> {
const sortStr = paramUpdates.sort || this.state.sort; const sortStr = paramUpdates.sort || this.state.sort;
const page = paramUpdates.page || this.state.page; const page = paramUpdates.page || this.state.page;
let typeView = this.state.communityName let typeView = `/c/${this.state.communityName}`;
? `/c/${this.state.communityName}`
: `/community/${this.state.communityId}`;
this.props.history.push( this.props.history.push(
`${typeView}/data_type/${dataTypeStr}/sort/${sortStr}/page/${page}` `${typeView}/data_type/${dataTypeStr}/sort/${sortStr}/page/${page}`
@ -420,7 +410,6 @@ export class Community extends Component<any, State> {
limit: fetchLimit, limit: fetchLimit,
sort: this.state.sort, sort: this.state.sort,
type_: ListingType.Community, type_: ListingType.Community,
community_id: this.state.communityId,
community_name: this.state.communityName, community_name: this.state.communityName,
saved_only: false, saved_only: false,
auth: authField(false), auth: authField(false),
@ -432,7 +421,6 @@ export class Community extends Component<any, State> {
limit: fetchLimit, limit: fetchLimit,
sort: this.state.sort, sort: this.state.sort,
type_: ListingType.Community, type_: ListingType.Community,
community_id: this.state.communityId,
community_name: this.state.communityName, community_name: this.state.communityName,
saved_only: false, saved_only: false,
auth: authField(false), auth: authField(false),

View file

@ -28,8 +28,11 @@ export class PersonListing extends Component<PersonListingProps, any> {
apubName = `@${person.name}`; apubName = `@${person.name}`;
link = `/u/${person.name}`; link = `/u/${person.name}`;
} else { } else {
apubName = `@${person.name}@${hostname(person.actor_id)}`; let domain = hostname(person.actor_id);
link = !this.props.realLink ? `/user/${person.id}` : person.actor_id; apubName = `@${person.name}@${domain}`;
link = !this.props.realLink
? `/u/${person.name}@${domain}`
: person.actor_id;
} }
let displayName = this.props.useApubName let displayName = this.props.useApubName

View file

@ -31,7 +31,6 @@ import {
editPostFindRes, editPostFindRes,
elementUrl, elementUrl,
fetchLimit, fetchLimit,
getIdFromProps,
getLanguage, getLanguage,
getUsernameFromProps, getUsernameFromProps,
languages, languages,
@ -67,7 +66,6 @@ import { PersonListing } from "./person-listing";
interface PersonState { interface PersonState {
personRes: GetPersonDetailsResponse; personRes: GetPersonDetailsResponse;
personId: number;
userName: string; userName: string;
view: PersonDetailsView; view: PersonDetailsView;
sort: SortType; sort: SortType;
@ -102,7 +100,6 @@ export class Person extends Component<any, PersonState> {
private subscription: Subscription; private subscription: Subscription;
private emptyState: PersonState = { private emptyState: PersonState = {
personRes: undefined, personRes: undefined,
personId: getIdFromProps(this.props),
userName: getUsernameFromProps(this.props), userName: getUsernameFromProps(this.props),
loading: true, loading: true,
view: Person.getViewFromProps(this.props.match.view), view: Person.getViewFromProps(this.props.match.view),
@ -164,7 +161,6 @@ export class Person extends Component<any, PersonState> {
fetchUserData() { fetchUserData() {
let form: GetPersonDetails = { let form: GetPersonDetails = {
person_id: this.state.personId,
username: this.state.userName, username: this.state.userName,
sort: this.state.sort, sort: this.state.sort,
saved_only: this.state.view === PersonDetailsView.Saved, saved_only: this.state.view === PersonDetailsView.Saved,
@ -969,9 +965,7 @@ export class Person extends Component<any, PersonState> {
const viewStr = paramUpdates.view || PersonDetailsView[this.state.view]; const viewStr = paramUpdates.view || PersonDetailsView[this.state.view];
const sortStr = paramUpdates.sort || this.state.sort; const sortStr = paramUpdates.sort || this.state.sort;
let typeView = this.state.userName let typeView = `/u/${this.state.userName}`;
? `/u/${this.state.userName}`
: `/user/${this.state.personId}`;
this.props.history.push( this.props.history.push(
`${typeView}/view/${viewStr}/sort/${sortStr}/page/${page}` `${typeView}/view/${viewStr}/sort/${sortStr}/page/${page}`

View file

@ -161,11 +161,6 @@ export class CreatePost extends Component<any, CreatePostState> {
get prevCommunityId(): number { get prevCommunityId(): number {
if (this.props.match.params.id) { if (this.props.match.params.id) {
return this.props.match.params.id; return this.props.match.params.id;
} else if (this.props.location.state) {
let lastLocation = this.props.location.state.prevPath;
if (lastLocation.includes("/community/")) {
return Number(lastLocation.split("/community/")[1]);
}
} }
return null; return null;
} }

View file

@ -71,16 +71,6 @@ export const routes: IRoutePropsWithFetch[] = [
component: Post, component: Post,
fetchInitialData: req => Post.fetchInitialData(req), fetchInitialData: req => Post.fetchInitialData(req),
}, },
{
path: `/community/:id/data_type/:data_type/sort/:sort/page/:page`,
component: Community,
fetchInitialData: req => Community.fetchInitialData(req),
},
{
path: `/community/:id`,
component: Community,
fetchInitialData: req => Community.fetchInitialData(req),
},
{ {
path: `/c/:name/data_type/:data_type/sort/:sort/page/:page`, path: `/c/:name/data_type/:data_type/sort/:sort/page/:page`,
component: Community, component: Community,
@ -96,16 +86,6 @@ export const routes: IRoutePropsWithFetch[] = [
component: Person, component: Person,
fetchInitialData: req => Person.fetchInitialData(req), fetchInitialData: req => Person.fetchInitialData(req),
}, },
{
path: `/user/:id/view/:view/sort/:sort/page/:page`,
component: Person,
fetchInitialData: req => Person.fetchInitialData(req),
},
{
path: `/user/:id`,
component: Person,
fetchInitialData: req => Person.fetchInitialData(req),
},
{ {
path: `/u/:username`, path: `/u/:username`,
component: Person, component: Person,