index.community/frontend/src/redux/types.ts

162 lines
3.5 KiB
TypeScript
Raw Normal View History

import { RouterState } from "connected-react-router";
2020-05-19 13:45:27 +00:00
import { SearchFilter } from "../searchFilters";
2018-08-27 15:27:09 +00:00
export enum ActionType {
// Instance details
REQUEST_INSTANCE_DETAILS = "REQUEST_INSTANCE_DETAILS",
RECEIVE_INSTANCE_DETAILS = "RECEIVE_INSTANCE_DETAILS",
INSTANCE_LOAD_ERROR = "INSTANCE_LOAD_ERROR",
// Graph
REQUEST_GRAPH = "REQUEST_GRAPH",
RECEIVE_GRAPH = "RECEIVE_GRAPH",
GRAPH_LOAD_ERROR = "GRAPH_LOAD_ERROR",
2019-08-27 13:50:16 +00:00
// Instance list
REQUEST_INSTANCES = "REQUEST_INSTANCES",
RECEIVE_INSTANCES = "RECEIVE_INSTANCES",
INSTANCE_LIST_LOAD_ERROR = "INSTANCE_LIST_LOAD_ERROR",
// Nav
DESELECT_INSTANCE = "DESELECT_INSTANCE",
// Search
REQUEST_SEARCH_RESULTS = "REQUEST_SEARCH_RESULTS",
RECEIVE_SEARCH_RESULTS = "RECEIVE_SEARCH_RESULTS",
SEARCH_RESULTS_ERROR = "SEARCH_RESULTS_ERROR",
2019-07-26 22:30:11 +00:00
RESET_SEARCH = "RESET_SEARCH",
// Search -- hovering over results
2020-05-19 13:45:27 +00:00
SET_SEARCH_RESULT_HOVER = "SET_SEARCH_RESULT_HOVER",
2018-08-27 15:27:09 +00:00
}
2020-05-19 13:45:27 +00:00
export interface Action {
type: ActionType;
payload: any;
2018-08-27 15:27:09 +00:00
}
2019-08-29 20:10:37 +00:00
export type SortField = "domain" | "userCount" | "statusCount" | "insularity";
export type SortDirection = "asc" | "desc";
2020-05-19 13:45:27 +00:00
export interface InstanceSort {
2019-08-29 20:10:37 +00:00
field: SortField;
direction: SortDirection;
}
2020-05-19 13:45:27 +00:00
export interface Peer {
name: string;
2018-08-27 15:27:09 +00:00
}
2020-05-19 13:45:27 +00:00
export interface SearchResultInstance {
name: string;
description?: string;
userCount?: number;
2019-07-24 15:51:44 +00:00
type?: string;
}
2020-05-19 13:45:27 +00:00
export interface FederationRestrictions {
2019-08-29 16:54:34 +00:00
reportRemoval?: string[];
reject?: string[];
mediaRemoval?: string[];
mediaNsfw?: string[];
federatedTimelineRemoval?: string[];
bannerRemoval?: string[];
avatarRemoval?: string[];
accept?: string[];
}
2020-05-19 13:45:27 +00:00
export interface InstanceDetails {
name: string;
description?: string;
version?: string;
2019-07-18 15:20:09 +00:00
userCount?: number;
insularity?: number;
statusCount?: number;
domainCount?: number;
2020-05-19 13:45:27 +00:00
peers?: Peer[];
federationRestrictions: FederationRestrictions;
lastUpdated?: string;
status: string;
2019-07-24 16:25:20 +00:00
type?: string;
2019-07-27 17:58:40 +00:00
statusesPerDay?: number;
statusesPerUserPerDay?: number;
2018-09-01 17:24:05 +00:00
}
2020-05-19 13:45:27 +00:00
interface GraphNode {
data: {
id: string;
label: string;
size: number;
};
position: {
x: number;
y: number;
};
}
2020-05-19 13:45:27 +00:00
interface GraphEdge {
data: {
source: string;
target: string;
id: string;
weight: number;
};
}
2020-05-19 13:45:27 +00:00
interface GraphMetadata {
2019-07-27 17:58:40 +00:00
ranges: { [key: string]: [number, number] };
}
2020-05-19 13:45:27 +00:00
export interface Graph {
nodes: GraphNode[];
edges: GraphEdge[];
}
2020-05-19 13:45:27 +00:00
export interface GraphResponse {
graph: Graph;
metadata: GraphMetadata;
2019-07-27 17:58:40 +00:00
}
2020-05-19 13:45:27 +00:00
export interface SearchResponse {
results: SearchResultInstance[];
next: string | null;
}
2020-05-19 13:45:27 +00:00
export interface InstanceListResponse {
2019-08-27 13:50:16 +00:00
pageNumber: number;
totalPages: number;
totalEntries: number;
pageSize: number;
2020-05-19 13:45:27 +00:00
instances: InstanceDetails[];
2019-08-27 13:50:16 +00:00
}
// Redux state
// The current instance name is stored in the URL. See state -> router -> location
2020-05-19 13:45:27 +00:00
export interface CurrentInstanceState {
currentInstanceDetails: InstanceDetails | null;
isLoadingInstanceDetails: boolean;
error: boolean;
2018-09-01 17:24:05 +00:00
}
2020-05-19 13:45:27 +00:00
export interface DataState {
graphResponse?: GraphResponse;
instancesResponse?: InstanceListResponse;
instanceListSort: InstanceSort;
isLoadingGraph: boolean;
2019-08-27 13:50:16 +00:00
isLoadingInstanceList: boolean;
graphLoadError: boolean;
instanceListLoadError: boolean;
2018-08-27 15:27:09 +00:00
}
2020-05-19 13:45:27 +00:00
export interface SearchState {
error: boolean;
isLoadingResults: boolean;
next: string;
query: string;
2020-05-19 13:45:27 +00:00
results: SearchResultInstance[];
filters: SearchFilter[];
2019-07-26 22:30:11 +00:00
hoveringOverResult?: string;
}
2020-05-19 13:45:27 +00:00
export interface AppState {
router: RouterState;
2020-05-19 13:45:27 +00:00
currentInstance: CurrentInstanceState;
data: DataState;
search: SearchState;
2018-09-01 17:24:05 +00:00
}