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

feat: remember previously used links for migration #933

Merged
merged 33 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a2efff7
feat: remember previously used links for migration
sharunkumar Nov 14, 2023
dd22d3a
remove unused imports
sharunkumar Nov 14, 2023
302998c
add dependency in useEffect
sharunkumar Nov 14, 2023
76ef7bf
add inset
sharunkumar Nov 14, 2023
8b01d69
add clear button
sharunkumar Nov 14, 2023
e237d55
update clear button style
sharunkumar Nov 14, 2023
af43ad8
added a back button to go from the subs list to the migration page
sharunkumar Nov 14, 2023
b5c69da
lint fix
sharunkumar Nov 14, 2023
30f3211
Merge remote-tracking branch 'upstream/main' into migrate-remember
sharunkumar Nov 16, 2023
95f5274
Merge Release 1.24.2
sharunkumar Nov 18, 2023
644fd20
Merge Release 1.25.0
sharunkumar Nov 23, 2023
132252e
Merge Release 1.26.0 + conflicts resolved
sharunkumar Nov 27, 2023
ee78177
Merge Release 1.27.0
sharunkumar Dec 1, 2023
c13a590
Merge Release 1.28.0
sharunkumar Dec 4, 2023
e6ad500
Merge remote-tracking branch 'upstream/main' into migrate-remember + …
sharunkumar Dec 5, 2023
522addc
Merge Release 1.29.0
sharunkumar Dec 6, 2023
5438be7
Merge Release 1.30.3
sharunkumar Dec 11, 2023
e29301b
not sure how this import got removed
sharunkumar Dec 12, 2023
b8d9627
Merge Release 1.32.2
sharunkumar Dec 18, 2023
c949b73
update reducers
sharunkumar Dec 18, 2023
03c8877
remove unused param
sharunkumar Dec 18, 2023
fc7d8eb
lint fix
sharunkumar Dec 18, 2023
46abca6
Merge Release 1.32.6
sharunkumar Dec 30, 2023
7b3e6ac
Merge Release 1.32.7
sharunkumar Jan 4, 2024
bec24dc
Merge Release 1.33.0
sharunkumar Jan 7, 2024
fa0c240
Merge Release 1.34.1
sharunkumar Jan 15, 2024
83e83d0
Merge Release 1.36.0
sharunkumar Jan 20, 2024
0c7031a
Merge Release 1.37.2
sharunkumar Jan 25, 2024
632cb49
Merge Release 1.37.4
sharunkumar Jan 27, 2024
7426317
Merge Release 1.38.0
sharunkumar Feb 3, 2024
06a9338
Merge Release 1.39.0
sharunkumar Feb 10, 2024
d31e8cc
Merge branch 'main' into migrate-remember
aeharding Feb 16, 2024
093178c
Add separate pages for navigation, refactor add UI, swipe to forget
aeharding Feb 16, 2024
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
70 changes: 70 additions & 0 deletions src/features/community/migrationSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
import { AppDispatch, RootState } from "../../store";
import { db } from "../../services/db";
import { uniq } from "lodash";

interface MigrationSlice {
links: Array<string>;
}

const initialState: MigrationSlice = {
links: [],
};

export const migrationSlice = createSlice({
name: "migration",
initialState,
reducers: {
setMigrationLinks: (state, action: PayloadAction<string[]>) => {
state.links = action.payload;
},
},
});

export default migrationSlice.reducer;

export const addMigrationLink =
sharunkumar marked this conversation as resolved.
Show resolved Hide resolved
(link: string) =>
async (dispatch: AppDispatch, getState: () => RootState) => {
const userHandle = getState().auth.accountData?.activeHandle;
const links = uniq([link, ...getState().migration.links]);

if (!userHandle) return;

dispatch(setMigrationLinks(links));

db.setSetting("migration_links", links, {
user_handle: userHandle,
});
};

export const getMigrationLinks =
() => async (dispatch: AppDispatch, getState: () => RootState) => {
const userHandle = getState().auth.accountData?.activeHandle;

if (!userHandle) {
dispatch(setMigrationLinks([]));
return;
}

const links = await db.getSetting("migration_links", {
user_handle: userHandle,
});

dispatch(setMigrationLinks(links || []));
};

export const resetMigrationLinks =
() => async (dispatch: AppDispatch, getState: () => RootState) => {
const userHandle = getState().auth.accountData?.activeHandle;

if (!userHandle) return;

dispatch(setMigrationLinks([]));

db.setSetting("migration_links", [], {
user_handle: userHandle,
});
};

const { setMigrationLinks } = migrationSlice.actions;
54 changes: 52 additions & 2 deletions src/pages/settings/RedditDataMigratePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
IonBackButton,
IonButton,
IonButtons,
IonHeader,
IonInput,
Expand All @@ -16,6 +17,11 @@ import { InsetIonItem } from "../profile/ProfileFeedItemsPage";
import { isValidUrl } from "../../helpers/url";
import useAppToast from "../../helpers/useAppToast";
import { useSetActivePage } from "../../features/auth/AppContext";
import { useAppDispatch, useAppSelector } from "../../store";
import {
addMigrationLink,
resetMigrationLinks,
} from "../../features/community/migrationSlice";

export default function RedditMigratePage() {
const pageRef = useRef<HTMLElement>(null);
Expand All @@ -24,6 +30,10 @@ export default function RedditMigratePage() {
const [subs, setSubs] = useState<string[] | undefined>();
const [link, setLink] = useState("");

const links = useAppSelector((state) => state.migration.links);

const dispatch = useAppDispatch();

useSetActivePage(pageRef);

useEffect(() => {
Expand All @@ -42,8 +52,9 @@ export default function RedditMigratePage() {
return;
}

dispatch(addMigrationLink(link));
setSubs(subs);
}, [link, presentToast]);
}, [link, presentToast, dispatch]);

function renderUpload() {
return (
Expand Down Expand Up @@ -87,6 +98,33 @@ export default function RedditMigratePage() {
</InsetIonItem>
</label>
</IonList>
<IonList inset>
{links.length > 0 ? (
<IonItem>
<IonLabel>Previous Links</IonLabel>
<IonButton
fill="clear"
onClick={(e) => {
e.preventDefault();
dispatch(resetMigrationLinks());
}}
>
Clear
</IonButton>
</IonItem>
) : undefined}
{links.map((link, idx) => (
<InsetIonItem
key={idx}
onClick={(e) => {
e.preventDefault();
setLink(link);
}}
>
<IonLabel>{link}</IonLabel>
</InsetIonItem>
))}
</IonList>
</>
);
}
Expand All @@ -108,7 +146,19 @@ export default function RedditMigratePage() {
<IonHeader>
<IonToolbar>
<IonButtons slot="start">
<IonBackButton defaultHref="/settings" text="Settings" />
{subs ? (
<IonButton
onClick={(e) => {
sharunkumar marked this conversation as resolved.
Show resolved Hide resolved
e.preventDefault();
setLink("");
setSubs(undefined);
}}
>
Back
</IonButton>
) : (
<IonBackButton defaultHref="/settings" text="Settings" />
)}
</IonButtons>

<IonTitle>Migrate</IonTitle>
Expand Down
1 change: 1 addition & 0 deletions src/services/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export type SettingValueTypes = {
compact_thumbnail_size: CompactThumbnailSizeType;
blur_nsfw: PostBlurNsfwType;
favorite_communities: string[];
migration_links: string[];
default_comment_sort: CommentDefaultSort;
disable_marking_posts_read: boolean;
mark_read_on_scroll: boolean;
Expand Down
5 changes: 5 additions & 0 deletions src/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import resolveSlice from "./features/resolve/resolveSlice";
import biometricSlice, {
initializeBiometricSliceDataIfNeeded,
} from "./features/settings/biometric/biometricSlice";
import migrationSlice, {
getMigrationLinks,
} from "./features/community/migrationSlice";
import modSlice from "./features/moderation/modSlice";

const store = configureStore({
Expand All @@ -50,6 +53,7 @@ const store = configureStore({
resolve: resolveSlice,
biometric: biometricSlice,
mod: modSlice,
migration: migrationSlice,
},
});
export type RootState = ReturnType<typeof store.getState>;
Expand All @@ -74,6 +78,7 @@ const activeHandleChange = () => {
lastActiveHandle = activeHandle;

store.dispatch(getFavoriteCommunities());
store.dispatch(getMigrationLinks());
store.dispatch(getBlurNsfw());
store.dispatch(getFilteredKeywords());
store.dispatch(getDefaultFeed());
Expand Down