Skip to content

Commit

Permalink
Merge branch 'save-upvote'
Browse files Browse the repository at this point in the history
  • Loading branch information
sharunkumar committed Nov 16, 2023
2 parents 0dcee47 + 3b81f3a commit b593b88
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/features/post/postSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ export const savePost =
async (dispatch: AppDispatch, getState: () => RootState) => {
const oldSaved = getState().post.postSavedById[postId];

const { upvoteOnSave } = getState().settings.general.posts;

if (upvoteOnSave) {
dispatch(voteOnPost(postId, save ? 1 : 0));
}

dispatch(updatePostSaved({ postId, saved: save }));

try {
Expand Down
2 changes: 2 additions & 0 deletions src/features/settings/general/posts/Posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IonLabel, IonList } from "@ionic/react";
import { InsetIonItem } from "../../../user/Profile";
import { ListHeader } from "../../shared/formatting";
import InfiniteScrolling from "./InfiniteScrolling";
import UpvoteOnSave from "./UpvoteOnSave";

export default function Posts() {
return (
Expand All @@ -14,6 +15,7 @@ export default function Posts() {
<IonLabel>Mark Read / Hiding Posts</IonLabel>
</InsetIonItem>
<InfiniteScrolling />
<UpvoteOnSave />
</IonList>
</>
);
Expand Down
21 changes: 21 additions & 0 deletions src/features/settings/general/posts/UpvoteOnSave.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { IonLabel, IonToggle } from "@ionic/react";
import { InsetIonItem } from "../../../../pages/profile/ProfileFeedItemsPage";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { setUpvoteOnSave } from "../../settingsSlice";

export default function UpvoteOnSave() {
const dispatch = useAppDispatch();
const { upvoteOnSave } = useAppSelector(
(state) => state.settings.general.posts,
);

return (
<InsetIonItem>
<IonLabel>Upvote on Save</IonLabel>
<IonToggle
checked={upvoteOnSave}
onIonChange={(e) => dispatch(setUpvoteOnSave(e.detail.checked))}
/>
</InsetIonItem>
);
}
11 changes: 11 additions & 0 deletions src/features/settings/settingsSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ interface SettingsState {
autoHideRead: boolean;
disableAutoHideInCommunities: boolean;
infiniteScrolling: boolean;
upvoteOnSave: boolean;
};
enableHapticFeedback: boolean;
linkHandler: LinkHandlerType;
Expand Down Expand Up @@ -172,6 +173,7 @@ const initialState: SettingsState = {
autoHideRead: true,
disableAutoHideInCommunities: false,
infiniteScrolling: true,
upvoteOnSave: false,
},
enableHapticFeedback: false,
linkHandler: OLinkHandlerType.InApp,
Expand Down Expand Up @@ -368,6 +370,11 @@ export const appearanceSlice = createSlice({

db.setSetting("infinite_scrolling", action.payload);
},
setUpvoteOnSave(state, action: PayloadAction<boolean>) {
state.general.posts.upvoteOnSave = action.payload;

db.setSetting("upvote_on_save", action.payload);
},
setTheme(state, action: PayloadAction<AppThemeType>) {
state.appearance.theme = action.payload;
set(LOCALSTORAGE_KEYS.THEME, action.payload);
Expand Down Expand Up @@ -508,6 +515,7 @@ export const fetchSettingsFromDatabase = createAsyncThunk<SettingsState>(
"disable_auto_hide_in_communities",
);
const infinite_scrolling = await db.getSetting("infinite_scrolling");
const upvote_on_save = await db.getSetting("upvote_on_save");
const enable_haptic_feedback = await db.getSetting(
"enable_haptic_feedback",
);
Expand Down Expand Up @@ -593,6 +601,8 @@ export const fetchSettingsFromDatabase = createAsyncThunk<SettingsState>(
infiniteScrolling:
infinite_scrolling ??
initialState.general.posts.infiniteScrolling,
upvoteOnSave:
upvote_on_save ?? initialState.general.posts.upvoteOnSave,
},
linkHandler: link_handler ?? initialState.general.linkHandler,
enableHapticFeedback:
Expand Down Expand Up @@ -648,6 +658,7 @@ export const {
setAutoHideRead,
setDisableAutoHideInCommunities,
setInfiniteScrolling,
setUpvoteOnSave,
setTheme,
setEnableHapticFeedback,
setLinkHandler,
Expand Down
1 change: 1 addition & 0 deletions src/services/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export type SettingValueTypes = {
has_presented_block_nsfw_tip: boolean;
no_subscribed_in_feed: boolean;
infinite_scrolling: boolean;
upvote_on_save: boolean;
};

export interface ISettingItem<T extends keyof SettingValueTypes> {
Expand Down

0 comments on commit b593b88

Please sign in to comment.