ui: remember scratchpad panel visibility

pull/199/head
undefined 3 years ago
parent 9f9ab1320b
commit ed8ae6ba69

@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.34.1",
"version": "2.34.2",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",

@ -1,8 +1,8 @@
import moment from 'moment-timezone';
import {
BlacklistedError,
InvalidTokenError, LoginError,
SystemError, UserAlreadyExistError, UserFacingError, UserNotFoundError, VerifyPasswordError,
BlacklistedError, InvalidTokenError, LoginError,
SystemError, UserAlreadyExistError, UserFacingError,
UserNotFoundError, VerifyPasswordError,
} from '../error';
import { User } from '../interface';
import avatar from '../lib/avatar';
@ -18,9 +18,7 @@ import * as system from '../model/system';
import task from '../model/task';
import token from '../model/token';
import user from '../model/user';
import {
Handler, param, post,
Route, Types } from '../service/server';
import { Handler, param, post, Route, Types } from '../service/server';
import { registerResolver, registerValue } from './api';
registerValue('User', [

@ -2,14 +2,15 @@
import { omit, sum } from 'lodash';
import moment from 'moment';
import {
Collection, FilterQuery,
MatchKeysAndValues, ObjectID, OnlyFieldsOfType,
PushOperator, UpdateQuery,
Collection, FilterQuery, MatchKeysAndValues,
ObjectID, OnlyFieldsOfType, PushOperator,
UpdateQuery,
} from 'mongodb';
import { ProblemNotFoundError } from '../error';
import {
ContestInfo, ExternalProblemId, FileInfo,
ProblemConfigFile, RecordDoc } from '../interface';
ProblemConfigFile, RecordDoc,
} from '../interface';
import * as bus from '../service/bus';
import db from '../service/db';
import { MaybeArray } from '../typeutils';
@ -221,7 +222,7 @@ class RecordModel {
@ArgMethod
static getByUid(domainId: string, uid: number, limit: number): Promise<RecordDoc[]> {
return RecordModel.coll.find({
domainId, uid, hidden: false, 'contest.tid': null,
domainId, 'contest.tid': null, hidden: false, uid,
}).sort({ _id: -1 }).limit(limit).toArray();
}
}
@ -234,11 +235,12 @@ bus.on('domain/delete', (domainId) => Promise.all([
]));
bus.on('app/started', () => {
RecordModel.coll.createIndexes([
{ key: { 'contest.tid': 1, hidden: 1, _id: -1 }, name: 'basic' },
{ key: { 'contest.tid': 1, hidden: 1, uid: 1, _id: -1 }, name: 'withUser' },
{ key: { 'contest.tid': 1, hidden: 1, pid: 1, _id: -1 }, name: 'withProblem' },
]);
return db.ensureIndexes(
RecordModel.coll,
{ key: { domainId: 1, 'contest.tid': 1, hidden: 1, _id: -1 }, name: 'basic' },
{ key: { domainId: 1, 'contest.tid': 1, hidden: 1, uid: 1, _id: -1 }, name: 'withUser' },
{ key: { domainId: 1, 'contest.tid': 1, hidden: 1, pid: 1, _id: -1 }, name: 'withProblem' },
);
});
export default RecordModel;

@ -1,7 +1,10 @@
import { Collection, Db, MongoClient } from 'mongodb';
import { Collection, Db, IndexSpecification, MongoClient } from 'mongodb';
import { BaseService, Collections } from '../interface';
import { Logger } from '../logger';
import * as bus from './bus';
const logger = new Logger('mongo');
interface MongoConfig {
protocol?: string,
username?: string,
@ -44,6 +47,21 @@ class MongoService implements BaseService {
if (this.opts.prefix) return this.db.collection(`${this.opts.prefix}.${c}`);
return this.db.collection(c);
}
public async ensureIndexes<T>(coll: Collection<T>, ...args: IndexSpecification[]) {
const existed = await coll.listIndexes().toArray();
for (const index of args) {
const i = existed.find(t => t.name == index.name);
if (!i) {
logger.info('Indexing %s.%s with key %o', coll.collectionName, index.name, index.key);
await coll.createIndexes([index]);
} else if (i.v < 2 || JSON.stringify(i.key) !== JSON.stringify(index.key)) {
logger.info('Re-Index %s.%s with key %o', coll.collectionName, index.name, index.key);
await coll.dropIndex(index.name);
await coll.createIndexes([index]);
}
}
}
}
const service = new MongoService();

@ -6,11 +6,11 @@ export default function reducer(state = {
size: '50%',
},
pretest: {
visible: false,
visible: localStorage.getItem('scratchpad/pretest') === 'true',
size: 200,
},
records: {
visible: UiContext.canViewRecord,
visible: UiContext.canViewRecord && localStorage.getItem('scratchpad/records') === 'true',
size: 200,
isLoading: false,
},
@ -29,6 +29,7 @@ export default function reducer(state = {
}
case 'SCRATCHPAD_UI_SET_VISIBILITY': {
const { uiElement, visibility } = action.payload;
localStorage.setItem(`scratchpad/${uiElement}`, visibility.toString());
return {
...state,
[uiElement]: {
@ -39,6 +40,7 @@ export default function reducer(state = {
}
case 'SCRATCHPAD_UI_TOGGLE_VISIBILITY': {
const { uiElement } = action.payload;
localStorage.setItem(`scratchpad/${uiElement}`, (!state[uiElement].visible).toString());
return {
...state,
[uiElement]: {

@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.20.0",
"version": "4.20.1",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",

Loading…
Cancel
Save