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