1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

periodical fetching updates

This commit is contained in:
Fedor Katurov 2019-11-12 17:59:40 +07:00
parent 32a2a0567e
commit 6c1f8967e8
8 changed files with 52 additions and 3 deletions

View file

@ -35,6 +35,7 @@ const CommentWrapper: FC<IProps> = ({
<div
className={styles.thumb_image}
style={{ backgroundImage: `url("${getURL(path(['photo'], user), PRESETS.avatar)}")` }}
onClick={() => window.postMessage({ type: 'username', username: user.username }, '*')}
/>
<div className={styles.thumb_user}>~{path(['username'], user)}</div>
</div>

View file

@ -56,6 +56,7 @@
background-size: cover;
flex: 0 0 $comment_height;
will-change: transform;
cursor: pointer;
@include tablet {
height: 32px;

View file

@ -9,6 +9,8 @@ export const API = {
PROFILE: (username: string) => `/user/${username}/profile`,
MESSAGES: (username: string) => `/user/${username}/messages`,
MESSAGE_SEND: (username: string) => `/user/${username}/messages`,
GET_UPDATES: '/user/updates',
UPLOAD: (target, type) => `/upload/${target}/${type}`,
},
NODE: {

View file

@ -19,6 +19,7 @@ render(
);
/*
- backend: exclude node covers on import
- profile modal
- profile editing
@ -29,6 +30,8 @@ render(
- password restore
- signup?
- text post can also has songs http://vault48.org/post5052
- fulltext search: https://github.com/typeorm/typeorm/issues/3191
- zoom: https://manuelstofer.github.io/pinchzoom/
- notifications ?
- better node brief update

View file

@ -50,3 +50,12 @@ export const apiAuthSendMessage = ({
.post(API.USER.MESSAGE_SEND(username), { message }, configWithToken(access))
.then(resultMiddleware)
.catch(errorMiddleware);
export const apiAuthGetUpdates = ({
access,
exclude_dialogs,
}): Promise<IResultWithStatus<{ message: IMessage }>> =>
api
.get(API.USER.GET_UPDATES, configWithToken(access, { params: { exclude_dialogs } }))
.then(resultMiddleware)
.catch(errorMiddleware);

View file

@ -11,6 +11,10 @@ const INITIAL_STATE: IAuthState = {
token: null,
user: { ...EMPTY_USER },
updates: {
messages: [],
},
login: {
error: null,
is_loading: false,

View file

@ -1,5 +1,5 @@
import { call, put, takeLatest, select, delay } from 'redux-saga/effects';
import { AUTH_USER_ACTIONS, EMPTY_USER, USER_ERRORS } from '~/redux/auth/constants';
import { AUTH_USER_ACTIONS, EMPTY_USER, USER_ERRORS, USER_ROLES } from '~/redux/auth/constants';
import {
authSetToken,
userSetLoginError,
@ -17,11 +17,12 @@ import {
apiAuthGetUserProfile,
apiAuthGetUserMessages,
apiAuthSendMessage,
apiAuthGetUpdates,
} from '~/redux/auth/api';
import { modalSetShown, modalShowDialog } from '~/redux/modal/actions';
import { selectToken, selectAuthProfile } from './selectors';
import { selectToken, selectAuthProfile, selectAuthUser } from './selectors';
import { IResultWithStatus } from '../types';
import { IUser } from './types';
import { IUser, IAuthState } from './types';
import { REHYDRATE, RehydrateAction } from 'redux-persist';
import { selectModal } from '../modal/selectors';
import { IModalState } from '../modal/reducer';
@ -189,6 +190,29 @@ function* sendMessage({ message, onSuccess }: ReturnType<typeof authSendMessage>
onSuccess();
}
function* getUpdates() {
const user = yield select(selectAuthUser);
if (!user || !user.is_user || user.role === USER_ROLES.GUEST || !user.id) return;
const modal: IModalState = yield select(selectModal);
const profile: IAuthState['profile'] = yield select(selectAuthProfile);
const exclude_dialogs =
modal.is_shown && modal.dialog === DIALOGS.PROFILE && profile.user.id ? profile.user.id : null;
const { error, data } = yield call(reqWrapper, apiAuthGetUpdates, { exclude_dialogs });
if (error || !data) return;
}
function* startPollingSaga() {
while (true) {
yield call(getUpdates);
yield delay(30000);
}
}
function* authSaga() {
yield takeLatest(REHYDRATE, checkUserSaga);
yield takeLatest(AUTH_USER_ACTIONS.LOGOUT, logoutSaga);
@ -197,6 +221,7 @@ function* authSaga() {
yield takeLatest(AUTH_USER_ACTIONS.OPEN_PROFILE, openProfile);
yield takeLatest(AUTH_USER_ACTIONS.GET_MESSAGES, getMessages);
yield takeLatest(AUTH_USER_ACTIONS.SEND_MESSAGE, sendMessage);
yield takeLatest(REHYDRATE, startPollingSaga);
}
export default authSaga;

View file

@ -25,6 +25,10 @@ export type IAuthState = Readonly<{
user: IUser;
token: string;
updates: {
messages: IMessage[];
};
login: {
error: string;
is_loading: boolean;