mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-10 11:21:29 +00:00
listen notification
optimize code Update user-api.js optimize code optimize code Update lib-content-view.js Update lib-content-view.js remove-userless-code update settings optimize cur code add max number of reconnections
This commit is contained in:
@@ -32,7 +32,7 @@ import DirColumnView from '../../components/dir-view-mode/dir-column-view';
|
||||
import SelectedDirentsToolbar from '../../components/toolbar/selected-dirents-toolbar';
|
||||
import MetadataPathToolbar from '../../components/toolbar/metadata-path-toolbar';
|
||||
import { eventBus } from '../../components/common/event-bus';
|
||||
|
||||
import WebSocketClient from '../../utils/websocket-service';
|
||||
import '../../css/lib-content-view.css';
|
||||
|
||||
dayjs.extend(relativeTime);
|
||||
@@ -49,7 +49,6 @@ class LibContentView extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
let isTreePanelShown = true;
|
||||
const storedTreePanelState = localStorage.getItem(TREE_PANEL_STATE_KEY);
|
||||
if (storedTreePanelState != undefined) {
|
||||
@@ -59,6 +58,7 @@ class LibContentView extends React.Component {
|
||||
const storedDirentDetailShowState = localStorage.getItem(DIRENT_DETAIL_SHOW_KEY);
|
||||
const isDirentDetailShow = storedDirentDetailShowState === 'true';
|
||||
|
||||
this.socket = new WebSocketClient(this.onMessageCallback, this.props.repoID);
|
||||
this.state = {
|
||||
currentMode: cookie.load('seafile_view_mode') || LIST_MODE,
|
||||
isTreePanelShown: isTreePanelShown, // display the 'dirent tree' side panel
|
||||
@@ -161,6 +161,38 @@ class LibContentView extends React.Component {
|
||||
this.calculatePara(this.props);
|
||||
}
|
||||
|
||||
onMessageCallback = (data) => {
|
||||
if (data.type === 'file-lock-changed') {
|
||||
const currentUrl = window.location.href;
|
||||
const parsedUrl = new URL(currentUrl);
|
||||
const pathParts = parsedUrl.pathname.split('/').filter(part => part.length > 0);
|
||||
const dirRouter = decodeURIComponent(pathParts.slice(3).join('/'));
|
||||
let notiUrlIndex = '';
|
||||
if (data.content.path.includes('/')) {
|
||||
notiUrlIndex = data.content.path.lastIndexOf('/');
|
||||
}
|
||||
const notifRouter = data.content.path.slice(0, notiUrlIndex);
|
||||
if (dirRouter === notifRouter) {
|
||||
const dirent = { name: data.content.path.split('/').pop() };
|
||||
if (data.content.change_event === 'locked') {
|
||||
if (data.content.expire === -1) {
|
||||
this.updateDirent(dirent, 'is_freezed', true);
|
||||
} else {
|
||||
this.updateDirent(dirent, 'is_freezed', false);
|
||||
}
|
||||
this.updateDirent(dirent, 'is_locked', true);
|
||||
this.updateDirent(dirent, 'locked_by_me', true);
|
||||
let lockName = data.content.lock_user.split('@');
|
||||
this.updateDirent(dirent, 'lock_owner_name', lockName[0]);
|
||||
} else if (data.content.change_event === 'unlocked') {
|
||||
this.updateDirent(dirent, 'is_locked', false);
|
||||
this.updateDirent(dirent, 'locked_by_me', false);
|
||||
this.updateDirent(dirent, 'lock_owner_name', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.repoID !== this.props.repoID) {
|
||||
this.setState({ path: '/', viewId: '', tagID: '', currentMode: cookie.load('seafile_view_mode') || LIST_MODE }, () => {
|
||||
@@ -280,6 +312,7 @@ class LibContentView extends React.Component {
|
||||
isLibView: false,
|
||||
currentRepoInfo: null,
|
||||
});
|
||||
this.socket.close();
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
@@ -405,6 +438,7 @@ class LibContentView extends React.Component {
|
||||
|
||||
// load data
|
||||
loadDirData = (path) => {
|
||||
|
||||
// list used FileTags
|
||||
this.updateUsedRepoTags();
|
||||
|
||||
|
Reference in New Issue
Block a user