Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/admin/users/actions.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { fromJS, List } from "immutable";67import { Actions, redux } from "../../app-framework";8import { user_search, User } from "../../frame-editors/generic/client";9import { sortBy } from "lodash";10import { StoreState, User as ImmutableUser, store } from "./store";1112function user_sort_key(user: User): number {13if (user.last_active) {14return -user.last_active;15}16if (user.created) {17return -user.created;18}19return 0;20}2122export class AdminUsersActions extends Actions<StoreState> {23public set_query(query: string): void {24this.setState({ query: query });25}2627public clear_status(): void {28this.setState({ status: "" });29}3031public set_status(status: string): void {32this.setState({ status: status });33}3435public async search(): Promise<void> {36this.set_status("Searching...");3738let result;39try {40result = await user_search({41query: store.get("query").trim().toLowerCase(), // backend assumes lower case42admin: true,43limit: 100,44});45} catch (err) {46this.set_status(`ERROR -- ${err}`);47return;48}49if (result == null) {50this.set_status("ERROR");51return;52}5354const result_sorted = sortBy(result, user_sort_key);55this.set_status("");5657this.setState({58result: fromJS(result_sorted) as unknown as List<ImmutableUser>,59});60}6162public set_view(view: boolean): void {63this.setState({ view });64}65}6667// The ?? is just to support hot module reload.68export const actions =69redux.getActions("admin-users") ??70redux.createActions("admin-users", AdminUsersActions);717273