Post: fix pendings, creation

This commit is contained in:
Liam Fitzgerald 2021-06-21 11:51:07 +10:00
parent faa659d780
commit 42aebb1ba6
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
4 changed files with 25 additions and 9 deletions

View File

@ -64,7 +64,8 @@ const useGraphState = createState<GraphState>('Graph', (set, get) => ({
body['add-nodes'].resource.ship = body['add-nodes'].resource.ship.slice(1);
GraphReducer({
'graph-update': body,
'graph-update-flat': body
'graph-update-flat': body,
'graph-update-thread': body
});
await promise;
},
@ -74,7 +75,9 @@ const useGraphState = createState<GraphState>('Graph', (set, get) => ({
markPending(body['add-nodes'].nodes);
body['add-nodes'].resource.ship = body['add-nodes'].resource.ship.slice(1);
GraphReducer({
'graph-update': body
'graph-update': body,
'graph-update-flat': body,
'graph-update-thread': body
});
await promise;
},

View File

@ -13,6 +13,7 @@ import { GroupFeedHeader } from './GroupFeedHeader';
import { PostRepliesRoutes } from './Post/PostReplies';
import PostTimeline from './Post/PostTimeline';
import airlock from '~/logic/api';
import { PostThreadRoutes } from './Post/PostThread';
function GroupFeed(props) {
const {
@ -87,6 +88,14 @@ function GroupFeed(props) {
pendingSize={pendingSize}
/>
</Route>
<Route path={relativePath('/feed/thread')}>
<PostThreadRoutes
baseUrl={relativePath('/feed/thread')}
association={association}
vip={vip}
pendingSize={pendingSize}
/>
</Route>
<Route path={relativePath('/feed/replies')}>
<PostRepliesRoutes
baseUrl={relativePath('/feed/replies')}

View File

@ -1,5 +1,5 @@
import { BaseTextArea, Box, Button, Icon, LoadingSpinner, Row } from '@tlon/indigo-react';
import { addPost, Association, Content, createPost, evalCord, Group, Path } from '@urbit/api';
import { Association, Content, createPost, evalCord, Group, Path } from '@urbit/api';
import React, {
ReactElement, useCallback, useState
} from 'react';
@ -8,6 +8,7 @@ import tokenizeMessage from '~/logic/lib/tokenizeMessage';
import useStorage from '~/logic/lib/useStorage';
import { useToggleState } from '~/logic/lib/useToggleState';
import airlock from '~/logic/api';
import useGraphState, { GraphState } from '~/logic/state/graph';
function canWrite(props) {
const { group, association, vip, index } = props;
@ -37,9 +38,12 @@ interface PostInputProps {
vip: string;
}
const selGraph = (s: GraphState) => s.addPost;
const PostInput = (props: PostInputProps): ReactElement | null => {
const { graphPath, index, submitCallback } = props;
const graphResource = resourceFromPath(graphPath);
const addPost = useGraphState(selGraph);
const [disabled, setDisabled] = useState(false);
const [code, toggleCode] = useToggleState(false);
@ -51,14 +55,14 @@ const PostInput = (props: PostInputProps): ReactElement | null => {
setDisabled(true);
const url = await promptUpload();
const { ship, name } = graphResource;
await airlock.thread(addPost(ship, name, createPost(`~${window.ship}`, [{ url }], index || '')));
await addPost(ship, name, createPost(window.ship, [{ url }], index || ''));
} catch (e) {
// TODO: better handling
console.error(e);
} finally {
setDisabled(false);
}
}, [promptUpload]);
}, [promptUpload, addPost]);
const sendPost = async () => {
if (!graphResource) {
@ -74,13 +78,13 @@ const PostInput = (props: PostInputProps): ReactElement | null => {
}
setDisabled(true);
const post = createPost(`~${window.ship}`, contents, index || '');
const post = createPost(window.ship, contents, index || '');
await airlock.thread(addPost(
await addPost(
graphResource.ship,
graphResource.name,
post
));
);
setDisabled(false);
if(code) {

View File

@ -151,7 +151,7 @@ function PostItem(props: PostItemProps) {
group={group}
association={association}
vip={vip}
index={index.join('/')}
index={`/${index.join('/')}`}
submitCallback={toggleReplyMode}
/>
</Col>