mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-10-01 17:31:13 +00:00
Store selected feed and reload on 99+ future notes
This commit is contained in:
parent
a5bf233b25
commit
416a383caf
@ -1,19 +1,23 @@
|
|||||||
import { Component } from 'solid-js';
|
import { Component } from 'solid-js';
|
||||||
|
import { useAccountContext } from '../../contexts/AccountContext';
|
||||||
import { useHomeContext } from '../../contexts/HomeContext';
|
import { useHomeContext } from '../../contexts/HomeContext';
|
||||||
import { useSettingsContext } from '../../contexts/SettingsContext';
|
import { useSettingsContext } from '../../contexts/SettingsContext';
|
||||||
import { hookForDev } from '../../lib/devTools';
|
import { hookForDev } from '../../lib/devTools';
|
||||||
|
import { fetchStoredFeed } from '../../lib/localStore';
|
||||||
import { FeedOption, PrimalFeed, SelectionOption } from '../../types/primal';
|
import { FeedOption, PrimalFeed, SelectionOption } from '../../types/primal';
|
||||||
import SelectBox from '../SelectBox/SelectBox';
|
import SelectBox from '../SelectBox/SelectBox';
|
||||||
import SelectionBox from '../SelectionBox/SelectionBox';
|
import SelectionBox from '../SelectionBox/SelectionBox';
|
||||||
|
|
||||||
const FeedSelect: Component<{ isPhone?: boolean, id?: string}> = (props) => {
|
const FeedSelect: Component<{ isPhone?: boolean, id?: string}> = (props) => {
|
||||||
|
|
||||||
|
const account = useAccountContext();
|
||||||
const home = useHomeContext();
|
const home = useHomeContext();
|
||||||
const settings = useSettingsContext();
|
const settings = useSettingsContext();
|
||||||
|
|
||||||
const findFeed = (hex: string, includeReplies: string) => {
|
const findFeed = (hex: string, includeReplies: string) => {
|
||||||
const ir = includeReplies === 'undefined' ? undefined :
|
const ir = includeReplies === 'undefined' ? undefined :
|
||||||
includeReplies === 'true';
|
includeReplies === 'true';
|
||||||
|
|
||||||
return settings?.availableFeeds.find(f => {
|
return settings?.availableFeeds.find(f => {
|
||||||
const isHex = f.hex === hex;
|
const isHex = f.hex === hex;
|
||||||
const isOpt = typeof ir === typeof f.includeReplies ?
|
const isOpt = typeof ir === typeof f.includeReplies ?
|
||||||
@ -74,7 +78,7 @@ const FeedSelect: Component<{ isPhone?: boolean, id?: string}> = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const initialValue = () => {
|
const initialValue = () => {
|
||||||
const selected = home?.selectedFeed;
|
const selected = home?.selectedFeed || fetchStoredFeed(account?.publicKey);
|
||||||
|
|
||||||
if (!selected) {
|
if (!selected) {
|
||||||
return {
|
return {
|
||||||
|
@ -4,6 +4,7 @@ import { createStore, reconcile, unwrap } from "solid-js/store";
|
|||||||
import { APP_ID } from "../App";
|
import { APP_ID } from "../App";
|
||||||
import { Kind } from "../constants";
|
import { Kind } from "../constants";
|
||||||
import { getEvents, getExploreFeed, getFeed, getFutureExploreFeed, getFutureFeed } from "../lib/feed";
|
import { getEvents, getExploreFeed, getFeed, getFutureExploreFeed, getFutureFeed } from "../lib/feed";
|
||||||
|
import { fetchStoredFeed, saveStoredFeed } from "../lib/localStore";
|
||||||
import { setLinkPreviews } from "../lib/notes";
|
import { setLinkPreviews } from "../lib/notes";
|
||||||
import { getScoredUsers, searchContent } from "../lib/search";
|
import { getScoredUsers, searchContent } from "../lib/search";
|
||||||
import { isConnected, refreshSocketListeners, removeSocketListeners, socket } from "../sockets";
|
import { isConnected, refreshSocketListeners, removeSocketListeners, socket } from "../sockets";
|
||||||
@ -378,6 +379,8 @@ export const HomeProvider = (props: { children: ContextChildren }) => {
|
|||||||
const selectFeed = (feed: PrimalFeed | undefined) => {
|
const selectFeed = (feed: PrimalFeed | undefined) => {
|
||||||
if (feed?.hex !== undefined && (feed.hex !== currentFeed?.hex || feed.includeReplies !== currentFeed?.includeReplies)) {
|
if (feed?.hex !== undefined && (feed.hex !== currentFeed?.hex || feed.includeReplies !== currentFeed?.includeReplies)) {
|
||||||
currentFeed = { ...feed };
|
currentFeed = { ...feed };
|
||||||
|
saveStoredFeed(account?.publicKey, currentFeed);
|
||||||
|
|
||||||
updateStore('selectedFeed', reconcile({...feed}));
|
updateStore('selectedFeed', reconcile({...feed}));
|
||||||
clearNotes();
|
clearNotes();
|
||||||
fetchNotes(feed.hex , `${APP_ID}`, 0, feed.includeReplies);
|
fetchNotes(feed.hex , `${APP_ID}`, 0, feed.includeReplies);
|
||||||
@ -665,7 +668,8 @@ export const HomeProvider = (props: { children: ContextChildren }) => {
|
|||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (account?.isKeyLookupDone && settings?.defaultFeed) {
|
if (account?.isKeyLookupDone && settings?.defaultFeed) {
|
||||||
selectFeed(settings?.defaultFeed);
|
const storedFeed = fetchStoredFeed(account.publicKey);
|
||||||
|
selectFeed(storedFeed || settings?.defaultFeed);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ export type LocalStore = {
|
|||||||
noteDraft: Record<string, string>,
|
noteDraft: Record<string, string>,
|
||||||
noteDraftUserRefs: Record<string, Record<string, PrimalUser>>,
|
noteDraftUserRefs: Record<string, Record<string, PrimalUser>>,
|
||||||
uploadTime: Record<string, number>,
|
uploadTime: Record<string, number>,
|
||||||
|
selectedFeed: PrimalFeed | undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UploadTime = {
|
export type UploadTime = {
|
||||||
@ -43,7 +44,7 @@ export const defaultUploadTime: UploadTime = {
|
|||||||
final: 100,
|
final: 100,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const emptyStorage = {
|
export const emptyStorage: LocalStore = {
|
||||||
following: [],
|
following: [],
|
||||||
followingSince: 0,
|
followingSince: 0,
|
||||||
muted: [],
|
muted: [],
|
||||||
@ -61,6 +62,7 @@ export const emptyStorage = {
|
|||||||
noteDraft: {},
|
noteDraft: {},
|
||||||
noteDraftUserRefs: {},
|
noteDraftUserRefs: {},
|
||||||
uploadTime: defaultUploadTime,
|
uploadTime: defaultUploadTime,
|
||||||
|
selectedFeed: undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const storageName = (pubkey?: string) => {
|
export const storageName = (pubkey?: string) => {
|
||||||
@ -402,3 +404,22 @@ export const loadMsgContacts = (pubkey: string) => {
|
|||||||
|
|
||||||
return store.msgContacts || { profiles: {}, counts: {} };
|
return store.msgContacts || { profiles: {}, counts: {} };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const fetchStoredFeed = (pubkey: string | undefined) => {
|
||||||
|
if (!pubkey) return undefined;
|
||||||
|
|
||||||
|
const store = getStorage(pubkey)
|
||||||
|
|
||||||
|
return store.selectedFeed;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const saveStoredFeed = (pubkey: string | undefined, feed: PrimalFeed) => {
|
||||||
|
if (!pubkey) return;
|
||||||
|
|
||||||
|
const store = getStorage(pubkey);
|
||||||
|
|
||||||
|
store.selectedFeed = { ...feed };
|
||||||
|
|
||||||
|
setStorage(pubkey, store);
|
||||||
|
};
|
||||||
|
@ -110,6 +110,11 @@ const Home: Component = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const loadNewContent = () => {
|
const loadNewContent = () => {
|
||||||
|
if (newNotesCount() > 100) {
|
||||||
|
location.reload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
context?.actions.loadFutureContent();
|
context?.actions.loadFutureContent();
|
||||||
scrollWindowTo(0, true);
|
scrollWindowTo(0, true);
|
||||||
setHasNewPosts(false);
|
setHasNewPosts(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user