mirror of
https://github.com/urbit/shrub.git
synced 2025-01-05 02:57:18 +03:00
interface: fix invite notifications
This commit is contained in:
parent
413b4b8c9f
commit
dff232816d
@ -1,5 +1,7 @@
|
|||||||
import useMetadataState from '../state/metadata';
|
import useMetadataState from '../state/metadata';
|
||||||
import ob from 'urbit-ob';
|
import ob from 'urbit-ob';
|
||||||
|
import useInviteState from '../state/invite';
|
||||||
|
import {resourceAsPath} from '../../../../npm/api/dist';
|
||||||
|
|
||||||
function getGroupResourceRedirect(key: string) {
|
function getGroupResourceRedirect(key: string) {
|
||||||
const association = useMetadataState.getState().associations.graph[`/ship/${key}`];
|
const association = useMetadataState.getState().associations.graph[`/ship/${key}`];
|
||||||
@ -67,7 +69,9 @@ function getGraphRedirect(link: string) {
|
|||||||
|
|
||||||
function getInviteRedirect(link: string) {
|
function getInviteRedirect(link: string) {
|
||||||
const [,,app,uid] = link.split('/');
|
const [,,app,uid] = link.split('/');
|
||||||
return `/invites/${app}/${uid}`;
|
const invite = useInviteState.getState().invites[app][uid];
|
||||||
|
if(!invite) { return ''; }
|
||||||
|
return { search: `?join-kind=${app}&join-path=${encodeURIComponent(resourceAsPath(invite.resource))}` };
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDmRedirect(link: string) {
|
function getDmRedirect(link: string) {
|
||||||
|
@ -8,6 +8,7 @@ type InviteState = State & BaseState<State>;
|
|||||||
const initial = (json: InviteUpdate, state: InviteState): InviteState => {
|
const initial = (json: InviteUpdate, state: InviteState): InviteState => {
|
||||||
const data = _.get(json, 'initial', false);
|
const data = _.get(json, 'initial', false);
|
||||||
if (data) {
|
if (data) {
|
||||||
|
state.loaded = true;
|
||||||
state.invites = data;
|
state.invites = data;
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
|
@ -9,14 +9,16 @@ import {
|
|||||||
|
|
||||||
export interface InviteState {
|
export interface InviteState {
|
||||||
invites: Invites;
|
invites: Invites;
|
||||||
|
loaded: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const useInviteState = createState<InviteState>(
|
const useInviteState = createState<InviteState>(
|
||||||
'Invite',
|
'Invite',
|
||||||
{
|
{
|
||||||
invites: {}
|
invites: {},
|
||||||
|
loaded: false
|
||||||
},
|
},
|
||||||
['invites'],
|
['invites', 'loaded'],
|
||||||
[
|
[
|
||||||
(set, get) =>
|
(set, get) =>
|
||||||
createSubscription('invite-store', '/all', (e) => {
|
createSubscription('invite-store', '/all', (e) => {
|
||||||
|
@ -16,6 +16,7 @@ import Landscape from '~/views/landscape/index';
|
|||||||
import GraphApp from '../../apps/graph/App';
|
import GraphApp from '../../apps/graph/App';
|
||||||
import { getNotificationRedirect } from '~/logic/lib/notificationRedirects';
|
import { getNotificationRedirect } from '~/logic/lib/notificationRedirects';
|
||||||
import {JoinRoute} from './Join/Join';
|
import {JoinRoute} from './Join/Join';
|
||||||
|
import useInviteState from '~/logic/state/invite';
|
||||||
|
|
||||||
export const Container = styled(Box)`
|
export const Container = styled(Box)`
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
@ -28,16 +29,20 @@ export const Content = (props) => {
|
|||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const mdLoaded = useMetadataState(s => s.loaded);
|
const mdLoaded = useMetadataState(s => s.loaded);
|
||||||
|
const inviteLoaded = useInviteState(s => s.loaded);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const query = new URLSearchParams(location.search);
|
const query = new URLSearchParams(location.search);
|
||||||
if(mdLoaded && query.has('grid-note')) {
|
if(!(mdLoaded && inviteLoaded)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(query.has('grid-note')) {
|
||||||
history.push(getNotificationRedirect(query.get('grid-note')!));
|
history.push(getNotificationRedirect(query.get('grid-note')!));
|
||||||
} else if(mdLoaded && query.has('grid-link')) {
|
} else if(query.has('grid-link')) {
|
||||||
const link = decodeURIComponent(query.get('grid-link')!);
|
const link = decodeURIComponent(query.get('grid-link')!);
|
||||||
history.push(`/perma${link}`);
|
history.push(`/perma${link}`);
|
||||||
}
|
}
|
||||||
}, [location.search, mdLoaded]);
|
}, [location.search, mdLoaded, inviteLoaded]);
|
||||||
|
|
||||||
useShortcut('navForward', useCallback((e) => {
|
useShortcut('navForward', useCallback((e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
Loading…
Reference in New Issue
Block a user