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:
parent
32a2a0567e
commit
6c1f8967e8
8 changed files with 52 additions and 3 deletions
|
@ -35,6 +35,7 @@ const CommentWrapper: FC<IProps> = ({
|
||||||
<div
|
<div
|
||||||
className={styles.thumb_image}
|
className={styles.thumb_image}
|
||||||
style={{ backgroundImage: `url("${getURL(path(['photo'], user), PRESETS.avatar)}")` }}
|
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 className={styles.thumb_user}>~{path(['username'], user)}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -56,6 +56,7 @@
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
flex: 0 0 $comment_height;
|
flex: 0 0 $comment_height;
|
||||||
will-change: transform;
|
will-change: transform;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
@include tablet {
|
@include tablet {
|
||||||
height: 32px;
|
height: 32px;
|
||||||
|
|
|
@ -9,6 +9,8 @@ export const API = {
|
||||||
PROFILE: (username: string) => `/user/${username}/profile`,
|
PROFILE: (username: string) => `/user/${username}/profile`,
|
||||||
MESSAGES: (username: string) => `/user/${username}/messages`,
|
MESSAGES: (username: string) => `/user/${username}/messages`,
|
||||||
MESSAGE_SEND: (username: string) => `/user/${username}/messages`,
|
MESSAGE_SEND: (username: string) => `/user/${username}/messages`,
|
||||||
|
GET_UPDATES: '/user/updates',
|
||||||
|
|
||||||
UPLOAD: (target, type) => `/upload/${target}/${type}`,
|
UPLOAD: (target, type) => `/upload/${target}/${type}`,
|
||||||
},
|
},
|
||||||
NODE: {
|
NODE: {
|
||||||
|
|
|
@ -19,6 +19,7 @@ render(
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
- backend: exclude node covers on import
|
- backend: exclude node covers on import
|
||||||
- profile modal
|
- profile modal
|
||||||
- profile editing
|
- profile editing
|
||||||
|
@ -29,6 +30,8 @@ render(
|
||||||
- password restore
|
- password restore
|
||||||
- signup?
|
- signup?
|
||||||
- text post can also has songs http://vault48.org/post5052
|
- 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 ?
|
- notifications ?
|
||||||
- better node brief update
|
- better node brief update
|
||||||
|
|
|
@ -50,3 +50,12 @@ export const apiAuthSendMessage = ({
|
||||||
.post(API.USER.MESSAGE_SEND(username), { message }, configWithToken(access))
|
.post(API.USER.MESSAGE_SEND(username), { message }, configWithToken(access))
|
||||||
.then(resultMiddleware)
|
.then(resultMiddleware)
|
||||||
.catch(errorMiddleware);
|
.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);
|
||||||
|
|
|
@ -11,6 +11,10 @@ const INITIAL_STATE: IAuthState = {
|
||||||
token: null,
|
token: null,
|
||||||
user: { ...EMPTY_USER },
|
user: { ...EMPTY_USER },
|
||||||
|
|
||||||
|
updates: {
|
||||||
|
messages: [],
|
||||||
|
},
|
||||||
|
|
||||||
login: {
|
login: {
|
||||||
error: null,
|
error: null,
|
||||||
is_loading: false,
|
is_loading: false,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { call, put, takeLatest, select, delay } from 'redux-saga/effects';
|
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 {
|
import {
|
||||||
authSetToken,
|
authSetToken,
|
||||||
userSetLoginError,
|
userSetLoginError,
|
||||||
|
@ -17,11 +17,12 @@ import {
|
||||||
apiAuthGetUserProfile,
|
apiAuthGetUserProfile,
|
||||||
apiAuthGetUserMessages,
|
apiAuthGetUserMessages,
|
||||||
apiAuthSendMessage,
|
apiAuthSendMessage,
|
||||||
|
apiAuthGetUpdates,
|
||||||
} from '~/redux/auth/api';
|
} from '~/redux/auth/api';
|
||||||
import { modalSetShown, modalShowDialog } from '~/redux/modal/actions';
|
import { modalSetShown, modalShowDialog } from '~/redux/modal/actions';
|
||||||
import { selectToken, selectAuthProfile } from './selectors';
|
import { selectToken, selectAuthProfile, selectAuthUser } from './selectors';
|
||||||
import { IResultWithStatus } from '../types';
|
import { IResultWithStatus } from '../types';
|
||||||
import { IUser } from './types';
|
import { IUser, IAuthState } from './types';
|
||||||
import { REHYDRATE, RehydrateAction } from 'redux-persist';
|
import { REHYDRATE, RehydrateAction } from 'redux-persist';
|
||||||
import { selectModal } from '../modal/selectors';
|
import { selectModal } from '../modal/selectors';
|
||||||
import { IModalState } from '../modal/reducer';
|
import { IModalState } from '../modal/reducer';
|
||||||
|
@ -189,6 +190,29 @@ function* sendMessage({ message, onSuccess }: ReturnType<typeof authSendMessage>
|
||||||
onSuccess();
|
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() {
|
function* authSaga() {
|
||||||
yield takeLatest(REHYDRATE, checkUserSaga);
|
yield takeLatest(REHYDRATE, checkUserSaga);
|
||||||
yield takeLatest(AUTH_USER_ACTIONS.LOGOUT, logoutSaga);
|
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.OPEN_PROFILE, openProfile);
|
||||||
yield takeLatest(AUTH_USER_ACTIONS.GET_MESSAGES, getMessages);
|
yield takeLatest(AUTH_USER_ACTIONS.GET_MESSAGES, getMessages);
|
||||||
yield takeLatest(AUTH_USER_ACTIONS.SEND_MESSAGE, sendMessage);
|
yield takeLatest(AUTH_USER_ACTIONS.SEND_MESSAGE, sendMessage);
|
||||||
|
yield takeLatest(REHYDRATE, startPollingSaga);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default authSaga;
|
export default authSaga;
|
||||||
|
|
|
@ -25,6 +25,10 @@ export type IAuthState = Readonly<{
|
||||||
user: IUser;
|
user: IUser;
|
||||||
token: string;
|
token: string;
|
||||||
|
|
||||||
|
updates: {
|
||||||
|
messages: IMessage[];
|
||||||
|
};
|
||||||
|
|
||||||
login: {
|
login: {
|
||||||
error: string;
|
error: string;
|
||||||
is_loading: boolean;
|
is_loading: boolean;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue