Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | 158x 158x 158x 279x 279x 279x 279x 279x 279x 279x 279x 279x 279x 279x 279x 279x 279x 279x 1x 1x 15x 13x 1x 1x 13x 13x 7x 1x 1x 19x 19x 8x 8x 1x 8x 7x 1x 1x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x | import { flatten, isArray, without } from 'lodash-es';
import { action, autorun, makeAutoObservable, observable } from 'mobx';
import { RouterStore } from 'mobx-angular';
import { Ext } from '../model/ext';
import { Plugin } from '../model/plugin';
import { Ref } from '../model/ref';
import { DEFAULT_WIKI_PREFIX } from '../mods/org/wiki';
import { EventBus } from './bus';
export type Saving = { url?: string, name: string, progress?: number };
export class SubmitStore {
wikiPrefix = DEFAULT_WIKI_PREFIX;
maxPreview = 300;
submitGenId: Plugin[] = [];
submitDm: Plugin[] = [];
files: File[] = [] as any;
caching: Map<File, Saving> = new Map<File, Saving>();
exts: Ext[] = [];
refs: Ref[] = [];
overwrite = false;
refLimitOverride = false;
constructor(
public route: RouterStore,
private eventBus: EventBus,
) {
makeAutoObservable(this, {
submitGenId: observable.shallow,
submitDm: observable.shallow,
files: observable.shallow,
caching: observable.shallow,
setRef: action,
setExt: action,
});
autorun(() => {
Iif (this.eventBus.event === 'refresh') {
if (this.eventBus.ref) {
this.setRef(this.eventBus.ref)
}
}
});
}
get topRefs() {
return this.refs.slice(0, 5);
}
get topExts() {
return this.exts.slice(0, 5);
}
get subpage() {
return this.route.routeSnapshot?.firstChild?.firstChild?.routeConfig?.path;
}
get url() {
return this.route.routeSnapshot?.queryParams['url'];
}
get linkTypeOverride() {
return this.route.routeSnapshot?.queryParams['linkTypeOverride'];
}
get text() {
Iif (this.linkTypeOverride) return this.linkTypeOverride === 'text';
Eif (this.subpage != 'text') return false;
return this.url?.startsWith('comment:') || !this.url;
}
get wiki() {
Iif (this.linkTypeOverride) return this.linkTypeOverride === 'wiki';
return !!this.url?.startsWith(this.wikiPrefix);
}
get title(): string {
return this.route.routeSnapshot?.queryParams['title'] || '';
}
get to(): string[] {
const tag = this.route.routeSnapshot?.queryParams['to'];
Eif (!tag) return [];
return isArray(tag) ? tag : [tag];
}
get tag() {
return this.route.routeSnapshot?.queryParams['tag'] as string;
}
get tags(): string[] {
return flatten(this.tag ? [this.tag] : [])
.flatMap( t => t.split(/[:|!()]/))
.map(t => t.includes('@') ? t.substring(0, t.indexOf('@')) : t)
.filter(t => t && !t.includes('*'));
}
get plugin() {
return this.route.routeSnapshot?.queryParams['plugin'] || '' as string;
}
get pluginUpload() {
Eif (!this.plugin) return '';
return this.route.routeSnapshot?.queryParams['upload'] || '' as string;
}
get repost() {
return this.tags.includes('plugin/repost');
}
get source() {
return this.route.routeSnapshot?.queryParams['source'];
}
get sources(): string[] {
return flatten(this.source ? [this.source] : []);
}
get web() {
return !this.wiki && (!this.subpage || this.subpage === 'web');
}
get upload() {
return this.subpage === 'upload';
}
get filesEmpty() {
return !this.files.length;
}
get empty() {
return !this.exts.length && !this.refs.length;
}
get genId() {
return this.tags.find(t => this.submitGenId.find(p => p.tag === t));
}
get dmPlugin() {
return [...this.tags, ...this.to].find(t => this.submitDm.find(p => p.tag === t));
}
get withoutGenId() {
Eif (!this.submitGenId.length) return this.tags;
return without(this.tags, ...this.submitGenId.map(p => p.tag));
}
get huge() {
Iif (this.refLimitOverride) return false;
return this.refs.length > 100 || this.exts.length > 100;
}
get uploads() {
return [...this.caching.values()];
}
clearOverride() {
this.refLimitOverride = false;
}
overrideHuge() {
this.refLimitOverride = true;
}
addRefs(...refs: Ref[]) {
this.refs = [...this.refs, ...refs];
}
addExts(...exts: Ext[]) {
this.exts = [...this.exts, ...exts];
}
removeRef(ref: Ref) {
this.refs = this.refs.filter(r => r.url !== ref.url || r.modifiedString !== ref.modifiedString);
}
removeExt(ext: Ext) {
this.exts = this.exts.filter(x => x.tag !== ext.tag || x.modifiedString !== ext.modifiedString);
}
clearUpload(refs: Ref[] = [], exts: Ext[] = []) {
this.exts = exts;
this.refs = refs;
}
addFiles(files?: File[]) {
if (!files) return;
this.files ||= [];
this.files.push(...files);
}
clearFiles() {
Eif (this.filesEmpty) return;
this.files = [] as any;
}
foundRef(url: string) {
for (const r of this.refs) {
if (r.url === url) {
r.exists = true;
}
}
}
foundExt(tag: string) {
for (const e of this.exts) {
if (e.tag === tag) {
e.exists = true;
}
}
}
setRef(ref: Ref) {
for (let i = 0; i < this.refs.length; i++) {
if (this.refs[i].url === ref.url) {
this.refs[i] = ref;
}
}
}
setExt(ext: Ext) {
for (let i = 0; i < this.exts.length; i++) {
if (this.exts[i].tag === ext.tag) {
this.exts[i] = ext;
}
}
}
tagRefs(tags: string[]) {
for (const ref of this.refs)
for (const t of tags) {
if (t.startsWith('-')) {
const r = t.substring(1);
if (ref.tags?.includes(r)) ref.tags.splice(ref.tags.indexOf(r), 1);
} else if (!ref.tags?.includes(t)) {
ref.tags ||= [];
ref.tags.push(t)
}
}
}
}
|