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