Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing titleOnly, PostSort, and CommentSort. #2715

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"inferno-router": "^8.2.3",
"inferno-server": "^8.2.3",
"jwt-decode": "^4.0.0",
"lemmy-js-client": "0.20.0-alpha.7",
"lemmy-js-client": "0.20.0-alpha.15",
"lodash.isequal": "^4.5.0",
"markdown-it": "^14.1.0",
"markdown-it-bidi": "^0.2.0",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/shared/components/person/person-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
RemovePost,
SaveComment,
SavePost,
SortType,
PostSortType,
TransferCommunity,
} from "lemmy-js-client";
import { CommentViewType, PersonDetailsView } from "../../interfaces";
Expand All @@ -53,7 +53,7 @@ interface PersonDetailsProps {
siteLanguages: number[];
page: number;
limit: number;
sort: SortType;
sort: PostSortType;
enableDownvotes: boolean;
voteDisplayMode: LocalUserVoteDisplayMode;
enableNsfw: boolean;
Expand Down
59 changes: 43 additions & 16 deletions src/shared/components/person/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
BlockCommunityResponse,
BlockInstanceResponse,
BlockPersonResponse,
CommentSortType,
Community,
GenerateTotpSecretResponse,
GetFederatedInstancesResponse,
Expand All @@ -31,7 +32,7 @@ import {
ListingType,
LoginResponse,
Person,
SortType,
PostSortType,
SuccessResponse,
UpdateTotpResponse,
} from "lemmy-js-client";
Expand Down Expand Up @@ -94,7 +95,8 @@ interface SettingsState {
blur_nsfw?: boolean;
auto_expand?: boolean;
theme?: string;
default_sort_type?: SortType;
default_post_sort_type?: PostSortType;
default_comment_sort_type?: CommentSortType;
default_listing_type?: ListingType;
interface_language?: string;
avatar?: string;
Expand Down Expand Up @@ -248,7 +250,9 @@ export class Settings extends Component<SettingsRouteProps, SettingsState> {
constructor(props: any, context: any) {
super(props, context);

this.handleSortTypeChange = this.handleSortTypeChange.bind(this);
this.handlePostSortTypeChange = this.handlePostSortTypeChange.bind(this);
this.handleCommentSortTypeChange =
this.handleCommentSortTypeChange.bind(this);
this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
this.handleBioChange = this.handleBioChange.bind(this);
this.handleDiscussionLanguageChange =
Expand Down Expand Up @@ -276,9 +280,9 @@ export class Settings extends Component<SettingsRouteProps, SettingsState> {
local_user: {
show_nsfw,
blur_nsfw,
auto_expand,
theme,
default_sort_type,
default_post_sort_type,
default_comment_sort_type,
default_listing_type,
interface_language,
show_avatars,
Expand Down Expand Up @@ -313,9 +317,9 @@ export class Settings extends Component<SettingsRouteProps, SettingsState> {
...this.state.saveUserSettingsForm,
show_nsfw,
blur_nsfw,
auto_expand,
theme: theme ?? "browser",
default_sort_type,
default_post_sort_type,
default_comment_sort_type,
default_listing_type,
interface_language,
discussion_languages: mui.discussion_languages,
Expand Down Expand Up @@ -905,14 +909,29 @@ export class Settings extends Component<SettingsRouteProps, SettingsState> {
</form>
<form className="mb-3 row">
<label className="col-sm-3 col-form-label">
{I18NextService.i18n.t("sort_type")}
{I18NextService.i18n.t("post_sort_type")}
</label>
<div className="col-sm-9">
<SortSelect
sort={
this.state.saveUserSettingsForm.default_sort_type ?? "Active"
this.state.saveUserSettingsForm.default_post_sort_type ??
"Active"
}
onChange={this.handleSortTypeChange}
onChange={this.handlePostSortTypeChange}
/>
</div>
</form>
<form className="mb-3 row">
<label className="col-sm-3 col-form-label">
{I18NextService.i18n.t("comment_sort_type")}
</label>
<div className="col-sm-9">
<SortSelect
sort={
this.state.saveUserSettingsForm.default_comment_sort_type ??
"Active"
}
onChange={this.handleCommentSortTypeChange}
/>
</div>
</form>
Expand Down Expand Up @@ -1580,8 +1599,16 @@ export class Settings extends Component<SettingsRouteProps, SettingsState> {
);
}

handleSortTypeChange(val: SortType) {
this.setState(s => ((s.saveUserSettingsForm.default_sort_type = val), s));
handlePostSortTypeChange(val: PostSortType) {
this.setState(
s => ((s.saveUserSettingsForm.default_post_sort_type = val), s),
);
}

handleCommentSortTypeChange(val: CommentSortType) {
this.setState(
s => ((s.saveUserSettingsForm.default_comment_sort_type = val), s),
);
}

handleListingTypeChange(val: ListingType) {
Expand Down Expand Up @@ -1743,9 +1770,9 @@ export class Settings extends Component<SettingsRouteProps, SettingsState> {
local_user: {
show_nsfw,
blur_nsfw,
auto_expand,
theme,
default_sort_type,
default_post_sort_type,
default_comment_sort_type,
default_listing_type,
interface_language,
show_avatars,
Expand Down Expand Up @@ -1782,11 +1809,11 @@ export class Settings extends Component<SettingsRouteProps, SettingsState> {
display_name,
bio,
matrix_user_id,
auto_expand,
blur_nsfw,
bot_account,
default_listing_type,
default_sort_type,
default_post_sort_type,
default_comment_sort_type,
discussion_languages: siteRes.data.my_user?.discussion_languages,
email,
interface_language,
Expand Down
6 changes: 3 additions & 3 deletions src/shared/components/post/post-listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
UserService.Instance.myUserInfo &&
!this.isoData.showAdultConsentModal
) {
const { auto_expand, blur_nsfw } =
UserService.Instance.myUserInfo.local_user_view.local_user;
const blur_nsfw =
UserService.Instance.myUserInfo.local_user_view.local_user.blur_nsfw;
this.setState({
imageExpanded: auto_expand && !(blur_nsfw && this.postView.post.nsfw),
imageExpanded: !(blur_nsfw && this.postView.post.nsfw),
});
}

Expand Down
48 changes: 22 additions & 26 deletions src/shared/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
Search as SearchForm,
SearchResponse,
SearchType,
SortType,
PostSortType,
} from "lemmy-js-client";
import { fetchLimit } from "../config";
import { CommentViewType, InitialFetchRequest } from "../interfaces";
Expand Down Expand Up @@ -76,9 +76,9 @@ import { isBrowser } from "@utils/browser";
interface SearchProps {
q?: string;
type: SearchType;
sort: SortType;
sort: PostSortType;
listingType: ListingType;
postTitleOnly?: boolean;
titleOnly?: boolean;
communityId?: number;
creatorId?: number;
page: number;
Expand Down Expand Up @@ -124,7 +124,7 @@ export function getSearchQueryParams(source?: string): SearchProps {
type: getSearchTypeFromQuery,
sort: getSortTypeFromQuery,
listingType: getListingTypeFromQuery,
postTitleOnly: getBoolFromString,
titleOnly: getBoolFromString,
communityId: getIdFromString,
creatorId: getIdFromString,
page: getPageFromString,
Expand All @@ -139,8 +139,8 @@ function getSearchTypeFromQuery(type_?: string): SearchType {
return type_ ? (type_ as SearchType) : defaultSearchType;
}

function getSortTypeFromQuery(sort?: string): SortType {
return sort ? (sort as SortType) : defaultSortType;
function getSortTypeFromQuery(sort?: string): PostSortType {
return sort ? (sort as PostSortType) : defaultSortType;
}

function getListingTypeFromQuery(listingType?: string): ListingType {
Expand Down Expand Up @@ -286,7 +286,7 @@ export class Search extends Component<SearchRouteProps, SearchState> {
this.handleCommunityFilterChange =
this.handleCommunityFilterChange.bind(this);
this.handleCreatorFilterChange = this.handleCreatorFilterChange.bind(this);
this.handlePostTitleChange = this.handlePostTitleChange.bind(this);
this.handleTitleOnlyChange = this.handleTitleOnlyChange.bind(this);

// Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) {
Expand Down Expand Up @@ -473,7 +473,7 @@ export class Search extends Component<SearchRouteProps, SearchState> {
type: searchType,
sort,
listingType: listing_type,
postTitleOnly: post_title_only,
titleOnly: title_only,
communityId: community_id,
creatorId: creator_id,
page,
Expand Down Expand Up @@ -519,7 +519,7 @@ export class Search extends Component<SearchRouteProps, SearchState> {
type_: searchType,
sort,
listing_type,
post_title_only,
title_only,
page,
limit: fetchLimit,
};
Expand Down Expand Up @@ -595,7 +595,6 @@ export class Search extends Component<SearchRouteProps, SearchState> {
case "Comments":
return this.comments;
case "Posts":
case "Url":
return this.posts;
case "Communities":
return this.communities;
Expand Down Expand Up @@ -641,7 +640,7 @@ export class Search extends Component<SearchRouteProps, SearchState> {
}

get selects() {
const { type, listingType, postTitleOnly, sort, communityId, creatorId } =
const { type, listingType, titleOnly, sort, communityId, creatorId } =
this.props;
const {
communitySearchOptions,
Expand Down Expand Up @@ -684,15 +683,12 @@ export class Search extends Component<SearchRouteProps, SearchState> {
<div className="col">
<input
className="btn-check"
id="post-title-only"
id="title-only"
type="checkbox"
checked={postTitleOnly}
onChange={this.handlePostTitleChange}
checked={titleOnly}
onChange={this.handleTitleOnlyChange}
/>
<label
className="btn btn-outline-secondary"
htmlFor="post-title-only"
>
<label className="btn btn-outline-secondary" htmlFor="title-only">
{I18NextService.i18n.t("post_title_only")}
</label>
</div>
Expand Down Expand Up @@ -1074,7 +1070,7 @@ export class Search extends Component<SearchRouteProps, SearchState> {
type,
sort,
listingType,
postTitleOnly,
titleOnly,
page,
} = props;

Expand All @@ -1087,7 +1083,7 @@ export class Search extends Component<SearchRouteProps, SearchState> {
type_: type,
sort,
listing_type: listingType,
post_title_only: postTitleOnly,
title_only: titleOnly,
page,
limit: fetchLimit,
});
Expand Down Expand Up @@ -1152,13 +1148,13 @@ export class Search extends Component<SearchRouteProps, SearchState> {
return this.searchInput.current?.value ?? this.props.q;
}

handleSortChange(sort: SortType) {
handleSortChange(sort: PostSortType) {
this.updateUrl({ sort, page: 1, q: this.getQ() });
}

handlePostTitleChange(event: any) {
const postTitleOnly = event.target.checked;
this.updateUrl({ postTitleOnly, q: this.getQ() });
handleTitleOnlyChange(event: any) {
const titleOnly = event.target.checked;
this.updateUrl({ titleOnly, q: this.getQ() });
}

handleTypeChange(i: Search, event: any) {
Expand Down Expand Up @@ -1213,7 +1209,7 @@ export class Search extends Component<SearchRouteProps, SearchState> {
q,
type,
listingType,
postTitleOnly,
titleOnly,
sort,
communityId,
creatorId,
Expand All @@ -1227,7 +1223,7 @@ export class Search extends Component<SearchRouteProps, SearchState> {
q,
type: type,
listingType: listingType,
postTitleOnly: postTitleOnly?.toString(),
titleOnly: titleOnly?.toString(),
communityId: communityId?.toString(),
creatorId: creatorId?.toString(),
page: page?.toString(),
Expand Down
4 changes: 2 additions & 2 deletions src/shared/utils/app/convert-comment-sort-type.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommentSortType, SortType } from "lemmy-js-client";
import { CommentSortType, PostSortType } from "lemmy-js-client";

export default function convertCommentSortType(
sort: SortType,
sort: PostSortType,
): CommentSortType {
switch (sort) {
case "TopAll":
Expand Down
6 changes: 4 additions & 2 deletions src/shared/utils/app/post-to-comment-sort-type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { CommentSortType, SortType } from "lemmy-js-client";
import { CommentSortType, PostSortType } from "lemmy-js-client";

export default function postToCommentSortType(sort: SortType): CommentSortType {
export default function postToCommentSortType(
sort: PostSortType,
): CommentSortType {
switch (sort) {
case "Active":
case "Hot":
Expand Down