fix: select state.version for selector hook
This commit is contained in:
parent
6398e470ef
commit
d3bcb75f3a
@ -18,7 +18,7 @@ export interface RelayProps {
|
||||
|
||||
export default function Relay(props: RelayProps) {
|
||||
const navigate = useNavigate();
|
||||
const state = useLogin(s => s.state);
|
||||
const { state } = useLogin(s => ({ v: s.state.version, state: s.state }));
|
||||
|
||||
const name = useMemo(() => getRelayName(props.addr), [props.addr]);
|
||||
const connection = useRelayState(props.addr);
|
||||
|
@ -6,7 +6,7 @@ import useLogin from "./useLogin";
|
||||
* Simple hook for adding / removing follows
|
||||
*/
|
||||
export default function useFollowsControls() {
|
||||
const state = useLogin(s => s.state);
|
||||
const { state } = useLogin(s => ({ v: s.state.version, state: s.state }));
|
||||
|
||||
return {
|
||||
isFollowing: (pk: string) => {
|
||||
|
@ -12,7 +12,7 @@ export class MutedWordTag implements ToNostrEventTag {
|
||||
}
|
||||
|
||||
export default function useModeration() {
|
||||
const state = useLogin(s => s.state);
|
||||
const { state } = useLogin(s => ({ v: s.state.version, state: s.state }));
|
||||
|
||||
function isMuted(id: string) {
|
||||
const link = NostrLink.publicKey(id);
|
||||
|
@ -39,7 +39,7 @@ const HashTagsPage = () => {
|
||||
export default HashTagsPage;
|
||||
|
||||
export function HashTagHeader({ tag, events, className }: { tag: string; events?: number; className?: string }) {
|
||||
const state = useLogin(s => s.state);
|
||||
const { state } = useLogin(s => ({ v: s.state.version, state: s.state }));
|
||||
const isFollowing = useMemo(() => {
|
||||
return state.isOnList(EventKind.InterestsList, new NostrHashtagLink(tag));
|
||||
}, [state, tag]);
|
||||
|
@ -6,14 +6,12 @@ import { Link } from "react-router-dom";
|
||||
import TimelineFollows from "@/Components/Feed/TimelineFollows";
|
||||
import { TaskList } from "@/Components/Tasks/TaskList";
|
||||
import useFollowsControls from "@/Hooks/useFollowControls";
|
||||
import useLogin from "@/Hooks/useLogin";
|
||||
import { DeckContext } from "@/Pages/Deck/DeckLayout";
|
||||
import messages from "@/Pages/messages";
|
||||
|
||||
const FollowsHint = () => {
|
||||
const publicKey = useLogin(s => s.publicKey);
|
||||
const { followList } = useFollowsControls();
|
||||
if (followList.length === 0 && publicKey) {
|
||||
if (followList.length === 0) {
|
||||
return (
|
||||
<FormattedMessage
|
||||
{...messages.NoFollows}
|
||||
|
@ -17,7 +17,7 @@ import messages from "./messages";
|
||||
const RelaySettingsPage = () => {
|
||||
const { publisher, system } = useEventPublisher();
|
||||
const relays = useRelays();
|
||||
const { readonly, state } = useLogin(s => ({ state: s.state, readonly: s.readonly }));
|
||||
const { readonly, state } = useLogin(s => ({ v: s.state.version, state: s.state, readonly: s.readonly }));
|
||||
const [newRelay, setNewRelay] = useState<string>();
|
||||
|
||||
const otherConnections = useMemo(() => {
|
||||
@ -92,7 +92,7 @@ export function CloseRelays() {
|
||||
const country = getCountry();
|
||||
const [location, setLocation] = useState<{ lat: number; lon: number }>(country);
|
||||
const currentRelays = useRelays();
|
||||
const state = useLogin(s => s.state);
|
||||
const { state } = useLogin(s => ({ v: s.state.version, state: s.state }));
|
||||
const relayUrls = Object.keys(currentRelays);
|
||||
|
||||
async function loadRelays() {
|
||||
|
@ -63,6 +63,7 @@ export class UserState<TAppData> extends EventEmitter<UserStateEvents> {
|
||||
// state object will be used in the getters as a fallback value
|
||||
#stateObj?: UserStateObject<TAppData>;
|
||||
#didInit = false;
|
||||
#version = 0;
|
||||
|
||||
constructor(
|
||||
readonly pubkey: string,
|
||||
@ -92,6 +93,7 @@ export class UserState<TAppData> extends EventEmitter<UserStateEvents> {
|
||||
this.#profile.on("change", () => this.emit("change", UserStateChangeType.Profile));
|
||||
this.#contacts.on("change", () => this.emit("change", UserStateChangeType.Contacts));
|
||||
this.#relays.on("change", () => this.emit("change", UserStateChangeType.Relays));
|
||||
this.on("change", () => this.#version++);
|
||||
}
|
||||
|
||||
async init(signer: EventSigner | undefined, system: SystemInterface) {
|
||||
@ -143,6 +145,10 @@ export class UserState<TAppData> extends EventEmitter<UserStateEvents> {
|
||||
}
|
||||
}
|
||||
|
||||
get version() {
|
||||
return this.#version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Users profile
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user