Skip to content

Commit

Permalink
rm basecomponent
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalmi committed Aug 22, 2023
1 parent 2517dc5 commit 3993391
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 58 deletions.
53 changes: 0 additions & 53 deletions src/js/BaseComponent.ts

This file was deleted.

30 changes: 26 additions & 4 deletions src/js/components/header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ChevronDownIcon } from '@heroicons/react/20/solid';
import { Cog8ToothIcon, HeartIcon } from '@heroicons/react/24/outline';
import { ArrowLeftIcon, HeartIcon as HeartIconFull } from '@heroicons/react/24/solid';
import { PureComponent } from 'preact/compat';
import { Link, route } from 'preact-router';

import Component from '../../BaseComponent.ts';
import Key from '../../nostr/Key.ts';
import Relays from '../../nostr/Relays.ts';
import localState from '../../state/LocalState.ts';
import localState, { Callback, Unsubscribe } from '../../state/LocalState.ts';
import { translate as t } from '../../translations/Translation.mjs';
import Icons from '../../utils/Icons.tsx';
import Show from '../helpers/Show.tsx';
Expand All @@ -19,9 +19,11 @@ declare global {
}
}

export default class Header extends Component {
export default class Header extends PureComponent<any, any> {
userId = null as string | null;
iv = null as any;
unmounted?: boolean;
unsubscribes: Record<string, Unsubscribe | undefined> = {};

constructor() {
super();
Expand All @@ -35,12 +37,32 @@ export default class Header extends Component {
}
}

sub(callback: CallableFunction, path?: string): Callback {
const cb = (data, key, unsubscribe, f): void => {
if (this.unmounted) {
unsubscribe?.();
return;
}
this.unsubscribes[path ?? key] = unsubscribe;
callback(data, key, unsubscribe, f);
};

return cb as any;
}

inject(name?: string, path?: string): Callback {
return this.sub((v: unknown, k: string) => {
const newState: any = {};
newState[name ?? k] = v as any;
this.setState(newState);
}, path);
}

backButtonClicked() {
window.history.back();
}

componentWillUnmount() {
super.componentWillUnmount();
this.iv && clearInterval(this.iv);
document.removeEventListener('keydown', this.escFunction, false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/views/settings/IrisAccount.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import debounce from 'lodash/debounce';
import { Event, UnsignedEvent } from 'nostr-tools';
import { Component } from 'preact';
import { route } from 'preact-router';

import Component from '../../BaseComponent';
import Events from '../../nostr/Events';
import Key from '../../nostr/Key';
import SocialNetwork from '../../nostr/SocialNetwork';
Expand Down

0 comments on commit 3993391

Please sign in to comment.