--- /dev/null
+alter table user_ drop column default_sort_type;
+alter table user_ drop column default_listing_type;
--- /dev/null
+alter table user_ add column default_sort_type smallint default 0 not null;
+alter table user_ add column default_listing_type smallint default 1 not null;
None => false,
};
- let type_ = PostListingType::from_str(&data.type_)?;
+ let type_ = ListingType::from_str(&data.type_)?;
let sort = SortType::from_str(&data.sort)?;
let posts = match PostView::list(
SearchType::Posts => {
posts = PostView::list(
&conn,
- PostListingType::All,
+ ListingType::All,
&sort,
data.community_id,
None,
SearchType::All => {
posts = PostView::list(
&conn,
- PostListingType::All,
+ ListingType::All,
&sort,
data.community_id,
None,
SearchType::Url => {
posts = PostView::list(
&conn,
- PostListingType::All,
+ ListingType::All,
&sort,
data.community_id,
None,
pub struct SaveUserSettings {
show_nsfw: bool,
theme: String,
+ default_sort_type: i16,
+ default_listing_type: i16,
auth: String,
}
banned: false,
show_nsfw: data.show_nsfw,
theme: "darkly".into(),
+ default_sort_type: SortType::Hot as i16,
+ default_listing_type: ListingType::Subscribed as i16,
};
// Create the user
banned: read_user.banned,
show_nsfw: data.show_nsfw,
theme: data.theme.to_owned(),
+ default_sort_type: data.default_sort_type,
+ default_listing_type: data.default_listing_type,
};
let updated_user = match User_::update(&conn, user_id, &user_form) {
let posts = if data.saved_only {
PostView::list(
&conn,
- PostListingType::All,
+ ListingType::All,
&sort,
data.community_id,
None,
} else {
PostView::list(
&conn,
- PostListingType::All,
+ ListingType::All,
&sort,
data.community_id,
Some(user_details_id),
banned: read_user.banned,
show_nsfw: read_user.show_nsfw,
theme: read_user.theme,
+ default_sort_type: read_user.default_sort_type,
+ default_listing_type: read_user.default_listing_type,
};
match User_::update(&conn, data.user_id, &user_form) {
banned: data.ban,
show_nsfw: read_user.show_nsfw,
theme: read_user.theme,
+ default_sort_type: read_user.default_sort_type,
+ default_listing_type: read_user.default_listing_type,
};
match User_::update(&conn, data.user_id, &user_form) {
// Posts
let posts = PostView::list(
&conn,
- PostListingType::All,
+ ListingType::All,
&SortType::New,
None,
Some(user_id),
#[cfg(test)]
mod tests {
use super::User_;
+ use crate::db::{ListingType, SortType};
use crate::naive_now;
#[test]
updated: None,
show_nsfw: false,
theme: "darkly".into(),
+ default_sort_type: SortType::Hot as i16,
+ default_listing_type: ListingType::Subscribed as i16,
};
let person = expected_user.person();
updated: None,
show_nsfw: false,
theme: "darkly".into(),
+ default_sort_type: SortType::Hot as i16,
+ default_listing_type: ListingType::Subscribed as i16,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
updated: None,
show_nsfw: false,
theme: "darkly".into(),
+ default_sort_type: SortType::Hot as i16,
+ default_listing_type: ListingType::Subscribed as i16,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
updated: None,
show_nsfw: false,
theme: "darkly".into(),
+ default_sort_type: SortType::Hot as i16,
+ default_listing_type: ListingType::Subscribed as i16,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
TopAll,
}
+#[derive(EnumString, ToString, Debug, Serialize, Deserialize)]
+pub enum ListingType {
+ All,
+ Subscribed,
+ Community,
+}
+
#[derive(EnumString, ToString, Debug, Serialize, Deserialize)]
pub enum SearchType {
All,
updated: None,
show_nsfw: false,
theme: "darkly".into(),
+ default_sort_type: SortType::Hot as i16,
+ default_listing_type: ListingType::Subscribed as i16,
};
let inserted_mod = User_::create(&conn, &new_mod).unwrap();
updated: None,
show_nsfw: false,
theme: "darkly".into(),
+ default_sort_type: SortType::Hot as i16,
+ default_listing_type: ListingType::Subscribed as i16,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
updated: None,
show_nsfw: false,
theme: "darkly".into(),
+ default_sort_type: SortType::Hot as i16,
+ default_listing_type: ListingType::Subscribed as i16,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
use super::*;
-#[derive(EnumString, ToString, Debug, Serialize, Deserialize)]
-pub enum PostListingType {
- All,
- Subscribed,
- Community,
-}
-
// The faked schema since diesel doesn't do views
table! {
post_view (id) {
impl PostView {
pub fn list(
conn: &PgConnection,
- type_: PostListingType,
+ type_: ListingType,
sort: &SortType,
for_community_id: Option<i32>,
for_creator_id: Option<i32>,
};
match type_ {
- PostListingType::Subscribed => {
+ ListingType::Subscribed => {
query = query.filter(subscribed.eq(true));
}
_ => {}
banned: false,
show_nsfw: false,
theme: "darkly".into(),
+ default_sort_type: SortType::Hot as i16,
+ default_listing_type: ListingType::Subscribed as i16,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
let read_post_listings_with_user = PostView::list(
&conn,
- PostListingType::Community,
+ ListingType::Community,
&SortType::New,
Some(inserted_community.id),
None,
.unwrap();
let read_post_listings_no_user = PostView::list(
&conn,
- PostListingType::Community,
+ ListingType::Community,
&SortType::New,
Some(inserted_community.id),
None,
pub updated: Option<chrono::NaiveDateTime>,
pub show_nsfw: bool,
pub theme: String,
+ pub default_sort_type: i16,
+ pub default_listing_type: i16,
}
#[derive(Insertable, AsChangeset, Clone)]
pub updated: Option<chrono::NaiveDateTime>,
pub show_nsfw: bool,
pub theme: String,
+ pub default_sort_type: i16,
+ pub default_listing_type: i16,
}
impl Crud<UserForm> for User_ {
pub iss: String,
pub show_nsfw: bool,
pub theme: String,
+ pub default_sort_type: i16,
+ pub default_listing_type: i16,
}
impl Claims {
iss: self.fedi_name.to_owned(),
show_nsfw: self.show_nsfw,
theme: self.theme.to_owned(),
+ default_sort_type: self.default_sort_type,
+ default_listing_type: self.default_listing_type,
};
encode(
&Header::default(),
updated: None,
show_nsfw: false,
theme: "darkly".into(),
+ default_sort_type: SortType::Hot as i16,
+ default_listing_type: ListingType::Subscribed as i16,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
updated: None,
show_nsfw: false,
theme: "darkly".into(),
+ default_sort_type: SortType::Hot as i16,
+ default_listing_type: ListingType::Subscribed as i16,
};
let read_user = User_::read(&conn, inserted_user.id).unwrap();
updated: None,
show_nsfw: false,
theme: "darkly".into(),
+ default_sort_type: SortType::Hot as i16,
+ default_listing_type: ListingType::Subscribed as i16,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
updated: None,
show_nsfw: false,
theme: "darkly".into(),
+ default_sort_type: SortType::Hot as i16,
+ default_listing_type: ListingType::Subscribed as i16,
};
let inserted_recipient = User_::create(&conn, &recipient_form).unwrap();
updated -> Nullable<Timestamp>,
show_nsfw -> Bool,
theme -> Varchar,
+ default_sort_type -> Int2,
+ default_listing_type -> Int2,
}
}
let conn = establish_connection();
let posts = PostView::list(
&conn,
- PostListingType::Community,
+ ListingType::Community,
&SortType::New,
Some(*community_id),
None,
GetPostsResponse,
CreatePostLikeResponse,
} from '../interfaces';
-import { WebSocketService } from '../services';
+import { WebSocketService, UserService } from '../services';
import { PostListings } from './post-listings';
import { SortSelect } from './sort-select';
import { Sidebar } from './sidebar';
getSortTypeFromProps(props: any): SortType {
return props.match.params.sort
? routeSortTypeToEnum(props.match.params.sort)
+ : UserService.Instance.user
+ ? UserService.Instance.user.default_sort_type
: SortType.Hot;
}
--- /dev/null
+import { Component, linkEvent } from 'inferno';
+import { ListingType } from '../interfaces';
+import { UserService } from '../services';
+
+import { i18n } from '../i18next';
+
+interface ListingTypeSelectProps {
+ type_: ListingType;
+ onChange?(val: ListingType): any;
+}
+
+interface ListingTypeSelectState {
+ type_: ListingType;
+}
+
+export class ListingTypeSelect extends Component<
+ ListingTypeSelectProps,
+ ListingTypeSelectState
+> {
+ private emptyState: ListingTypeSelectState = {
+ type_: this.props.type_,
+ };
+
+ constructor(props: any, context: any) {
+ super(props, context);
+ this.state = this.emptyState;
+ }
+
+ render() {
+ return (
+ <div class="btn-group btn-group-toggle">
+ <label
+ className={`btn btn-sm btn-secondary
+ ${this.state.type_ == ListingType.Subscribed && 'active'}
+ ${UserService.Instance.user == undefined ? 'disabled' : 'pointer'}
+ `}
+ >
+ <input
+ type="radio"
+ value={ListingType.Subscribed}
+ checked={this.state.type_ == ListingType.Subscribed}
+ onChange={linkEvent(this, this.handleTypeChange)}
+ disabled={UserService.Instance.user == undefined}
+ />
+ {i18n.t('subscribed')}
+ </label>
+ <label
+ className={`pointer btn btn-sm btn-secondary ${this.state.type_ ==
+ ListingType.All && 'active'}`}
+ >
+ <input
+ type="radio"
+ value={ListingType.All}
+ checked={this.state.type_ == ListingType.All}
+ onChange={linkEvent(this, this.handleTypeChange)}
+ />
+ {i18n.t('all')}
+ </label>
+ </div>
+ );
+ }
+
+ handleTypeChange(i: ListingTypeSelect, event: any) {
+ i.state.type_ = Number(event.target.value);
+ i.setState(i.state);
+ i.props.onChange(i.state.type_);
+ }
+}
import { WebSocketService, UserService } from '../services';
import { PostListings } from './post-listings';
import { SortSelect } from './sort-select';
+import { ListingTypeSelect } from './listing-type-select';
import { SiteForm } from './site-form';
import {
msgOp,
return props.match.params.type
? routeListingTypeToEnum(props.match.params.type)
: UserService.Instance.user
- ? ListingType.Subscribed
+ ? UserService.Instance.user.default_listing_type
: ListingType.All;
}
getSortTypeFromProps(props: any): SortType {
return props.match.params.sort
? routeSortTypeToEnum(props.match.params.sort)
+ : UserService.Instance.user
+ ? UserService.Instance.user.default_sort_type
: SortType.Hot;
}
this.state = this.emptyState;
this.handleEditCancel = this.handleEditCancel.bind(this);
this.handleSortChange = this.handleSortChange.bind(this);
+ this.handleTypeChange = this.handleTypeChange.bind(this);
this.subscription = WebSocketService.Instance.subject
.pipe(
selects() {
return (
<div className="mb-3">
- <div class="btn-group btn-group-toggle">
- <label
- className={`btn btn-sm btn-secondary
- ${this.state.type_ == ListingType.Subscribed && 'active'}
- ${UserService.Instance.user == undefined ? 'disabled' : 'pointer'}
- `}
- >
- <input
- type="radio"
- value={ListingType.Subscribed}
- checked={this.state.type_ == ListingType.Subscribed}
- onChange={linkEvent(this, this.handleTypeChange)}
- disabled={UserService.Instance.user == undefined}
- />
- {i18n.t('subscribed')}
- </label>
- <label
- className={`pointer btn btn-sm btn-secondary ${this.state.type_ ==
- ListingType.All && 'active'}`}
- >
- <input
- type="radio"
- value={ListingType.All}
- checked={this.state.type_ == ListingType.All}
- onChange={linkEvent(this, this.handleTypeChange)}
- />
- {i18n.t('all')}
- </label>
- </div>
+ <ListingTypeSelect
+ type_={this.state.type_}
+ onChange={this.handleTypeChange}
+ />
<span class="ml-2">
<SortSelect sort={this.state.sort} onChange={this.handleSortChange} />
</span>
window.scrollTo(0, 0);
}
- handleTypeChange(i: Main, event: any) {
- i.state.type_ = Number(event.target.value);
- i.state.page = 1;
- i.state.loading = true;
- i.setState(i.state);
- i.updateUrl();
- i.fetchPosts();
+ handleTypeChange(val: ListingType) {
+ this.state.type_ = val;
+ this.state.page = 1;
+ this.state.loading = true;
+ this.setState(this.state);
+ this.updateUrl();
+ this.fetchPosts();
window.scrollTo(0, 0);
}
CommunityUser,
GetUserDetailsForm,
SortType,
+ ListingType,
UserDetailsResponse,
UserView,
CommentResponse,
} from '../utils';
import { PostListing } from './post-listing';
import { SortSelect } from './sort-select';
+import { ListingTypeSelect } from './listing-type-select';
import { CommentNodes } from './comment-nodes';
import { MomentTime } from './moment-time';
import { i18n } from '../i18next';
userSettingsForm: {
show_nsfw: null,
theme: null,
+ default_sort_type: null,
+ default_listing_type: null,
auth: null,
},
userSettingsLoading: null,
this.state = this.emptyState;
this.handleSortChange = this.handleSortChange.bind(this);
+ this.handleUserSettingsSortTypeChange = this.handleUserSettingsSortTypeChange.bind(
+ this
+ );
+ this.handleUserSettingsListingTypeChange = this.handleUserSettingsListingTypeChange.bind(
+ this
+ );
this.state.user_id = Number(this.props.match.params.id);
this.state.username = this.props.match.params.username;
</select>
</div>
</div>
+ <form className="form-group">
+ <div class="col-12">
+ <label>
+ <T i18nKey="sort_type" class="mr-2">
+ #
+ </T>
+ </label>
+ <ListingTypeSelect
+ type_={this.state.userSettingsForm.default_listing_type}
+ onChange={this.handleUserSettingsListingTypeChange}
+ />
+ </div>
+ </form>
+ <form className="form-group">
+ <div class="col-12">
+ <label>
+ <T i18nKey="type" class="mr-2">
+ #
+ </T>
+ </label>
+ <SortSelect
+ sort={this.state.userSettingsForm.default_sort_type}
+ onChange={this.handleUserSettingsSortTypeChange}
+ />
+ </div>
+ </form>
<div class="form-group">
<div class="col-12">
<div class="form-check">
</div>
</div>
</div>
- <div class="form-group row mb-0">
+ <div class="form-group">
<div class="col-12">
- <button type="submit" class="btn btn-secondary mr-4">
+ <button
+ type="submit"
+ class="btn btn-block btn-secondary mr-4"
+ >
{this.state.userSettingsLoading ? (
<svg class="icon icon-spinner spin">
<use xlinkHref="#icon-spinner"></use>
capitalizeFirstLetter(i18n.t('save'))
)}
</button>
+ </div>
+ </div>
+ <hr />
+ <div class="form-group mb-0">
+ <div class="col-12">
<button
- class="btn btn-danger"
+ class="btn btn-block btn-danger"
onClick={linkEvent(
this,
this.handleDeleteAccountShowConfirmToggle
i.setState(i.state);
}
+ handleUserSettingsSortTypeChange(val: SortType) {
+ this.state.userSettingsForm.default_sort_type = val;
+ this.setState(this.state);
+ }
+
+ handleUserSettingsListingTypeChange(val: ListingType) {
+ this.state.userSettingsForm.default_listing_type = val;
+ this.setState(this.state);
+ }
+
handleUserSettingsSubmit(i: User, event: any) {
event.preventDefault();
i.state.userSettingsLoading = true;
this.state.userSettingsForm.theme = UserService.Instance.user.theme
? UserService.Instance.user.theme
: 'darkly';
+ this.state.userSettingsForm.default_sort_type =
+ UserService.Instance.user.default_sort_type;
+ this.state.userSettingsForm.default_listing_type =
+ UserService.Instance.user.default_listing_type;
}
document.title = `/u/${this.state.user.name} - ${WebSocketService.Instance.site.name}`;
window.scrollTo(0, 0);
username: string;
show_nsfw: boolean;
theme: string;
+ default_sort_type: SortType;
+ default_listing_type: ListingType;
}
export interface UserView {
export interface UserSettingsForm {
show_nsfw: boolean;
theme: string;
+ default_sort_type: SortType;
+ default_listing_type: ListingType;
auth: string;
}