Fix home page not using site-level listing type #1612 (#1778)

* Fix home page not using site-level listing type

* Use null handling instead
This commit is contained in:
jcgurango 2023-07-05 05:06:34 +08:00 committed by GitHub
parent 778c3533f0
commit 26ff0f7e06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -114,7 +114,7 @@ interface HomeState {
} }
interface HomeProps { interface HomeProps {
listingType: ListingType; listingType?: ListingType;
dataType: DataType; dataType: DataType;
sort: SortType; sort: SortType;
page: number; page: number;
@ -163,12 +163,12 @@ function getDataTypeFromQuery(type?: string): DataType {
return type ? DataType[type] : DataType.Post; return type ? DataType[type] : DataType.Post;
} }
function getListingTypeFromQuery(type?: string): ListingType { function getListingTypeFromQuery(type?: string): ListingType | undefined {
const myListingType = const myListingType =
UserService.Instance.myUserInfo?.local_user_view?.local_user UserService.Instance.myUserInfo?.local_user_view?.local_user
?.default_listing_type; ?.default_listing_type;
return (type ? (type as ListingType) : myListingType) ?? "Local"; return type ? (type as ListingType) : myListingType;
} }
function getSortTypeFromQuery(type?: string): SortType { function getSortTypeFromQuery(type?: string): SortType {
@ -311,11 +311,12 @@ export class Home extends Component<any, HomeState> {
client, client,
auth, auth,
query: { dataType: urlDataType, listingType, page: urlPage, sort: urlSort }, query: { dataType: urlDataType, listingType, page: urlPage, sort: urlSort },
site,
}: InitialFetchRequest<QueryParams<HomeProps>>): Promise<HomeData> { }: InitialFetchRequest<QueryParams<HomeProps>>): Promise<HomeData> {
const dataType = getDataTypeFromQuery(urlDataType); const dataType = getDataTypeFromQuery(urlDataType);
const type_ =
// TODO figure out auth default_listingType, default_sort_type getListingTypeFromQuery(listingType) ??
const type_ = getListingTypeFromQuery(listingType); site.site_view.local_site.default_post_listing_type;
const sort = getSortTypeFromQuery(urlSort); const sort = getSortTypeFromQuery(urlSort);
const page = urlPage ? Number(urlPage) : 1; const page = urlPage ? Number(urlPage) : 1;
@ -761,7 +762,10 @@ export class Home extends Component<any, HomeState> {
</div> </div>
<div className="col-auto"> <div className="col-auto">
<ListingTypeSelect <ListingTypeSelect
type_={listingType} type_={
listingType ??
this.state.siteRes.site_view.local_site.default_post_listing_type
}
showLocal={showLocal(this.isoData)} showLocal={showLocal(this.isoData)}
showSubscribed showSubscribed
onChange={this.handleListingTypeChange} onChange={this.handleListingTypeChange}
@ -770,7 +774,12 @@ export class Home extends Component<any, HomeState> {
<div className="col-auto"> <div className="col-auto">
<SortSelect sort={sort} onChange={this.handleSortChange} /> <SortSelect sort={sort} onChange={this.handleSortChange} />
</div> </div>
<div className="col-auto ps-0">{getRss(listingType)}</div> <div className="col-auto ps-0">
{getRss(
listingType ??
this.state.siteRes.site_view.local_site.default_post_listing_type
)}
</div>
</div> </div>
); );
} }