Skip to content

Commit b6ac8f3

Browse files
committed
moved more interfaces to global declaration file
1 parent ee92455 commit b6ac8f3

5 files changed

Lines changed: 62 additions & 66 deletions

File tree

app/assets/javascripts/filters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ $(() => {
122122
async function saveFilter() {
123123
if (!$form[0].reportValidity()) { return; }
124124

125-
const filter = /** @type {Filter} */({});
125+
const filter = /** @type {QPixelFlag} */({});
126126

127127
for (const el of $formFilters) {
128128
filter[el.dataset.name] = $(el).val();

app/assets/javascripts/qpixel_api.js

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,6 @@ const validators = [];
66
/** Counts notifications popped up at any time. */
77
let popped_modals_ct = 0;
88

9-
/**
10-
* @typedef {{
11-
* min_score: number | null,
12-
* max_score: number | null,
13-
* min_answers: number | null,
14-
* max_answers: number | null,
15-
* include_tags: [string, number][],
16-
* exclude_tags: [string, number][],
17-
* status: 'any' | 'closed' | 'open',
18-
* system: boolean,
19-
* }} Filter
20-
*
21-
* @typedef {{
22-
* id: number,
23-
* username: string,
24-
* is_standard: boolean,
25-
* is_moderator: boolean,
26-
* is_admin: boolean,
27-
* is_global_moderator: boolean,
28-
* is_global_admin: boolean,
29-
* trust_level: number,
30-
* se_acct_id: string | null,
31-
* }} User
32-
*/
33-
349
window.QPixel = {
3510
csrfToken: () => {
3611
const token = $('meta[name="csrf-token"]').attr('content');
@@ -135,7 +110,7 @@ window.QPixel = {
135110
},
136111

137112
/**
138-
* @type {Filter[]|null}
113+
* @type {QPixelFlag[]|null}
139114
*/
140115
_filters: null,
141116

@@ -146,7 +121,7 @@ window.QPixel = {
146121
_pendingUserResponse: null,
147122

148123
/**
149-
* @type {User|null}
124+
* @type {QPixelUser|null}
150125
*/
151126
_user: null,
152127

app/assets/javascripts/suggested_edit.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
/**
2-
* @typedef {{
3-
* message?: string
4-
* redirect_url?: string
5-
* status: 'success' | 'error'
6-
* }} SuggestedEditActionResult
7-
*/
8-
91
$(() => {
102
$('[data-suggested-edit-approve]').on('click', async (ev) => {
113
ev.preventDefault();
@@ -15,7 +7,7 @@ $(() => {
157

168
const resp = await QPixel.fetchJSON(`/posts/suggested-edit/${editId}/approve`, { comment });
179

18-
/** @type {SuggestedEditActionResult} */
10+
/** @type {QPixelSuggestedEditActionResult} */
1911
const data = await resp.json();
2012

2113
if (data.status !== 'success') {
@@ -40,7 +32,7 @@ $(() => {
4032

4133
const resp = await QPixel.fetchJSON(`/posts/suggested-edit/${editId}/reject`, { rejection_comment: comment });
4234

43-
/** @type {SuggestedEditActionResult} */
35+
/** @type {QPixelSuggestedEditActionResult} */
4436
const data = await resp.json();
4537

4638
if (data.status !== 'success') {
@@ -50,4 +42,4 @@ $(() => {
5042
location.href = data.redirect_url;
5143
}
5244
});
53-
});
45+
});

app/assets/javascripts/tags.js

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
11
/**
2-
* @typedef {{
3-
* name: string
4-
* }} RemoteTagSynonym
5-
*
6-
* @typedef {{
7-
* id: number
8-
* community_id: number
9-
* parent_id: number | null
10-
* tag_set_id: number
11-
* excerpt: string
12-
* name: string
13-
* tag_synonyms: RemoteTagSynonym[]
14-
* wiki: string | null
15-
* wiki_markdown: string
16-
* created_at: string
17-
* updated_at: string
18-
* }} RemoteTag
19-
*
202
* @typedef {{
213
* id: number | string
224
* text: string
235
* desc: string
24-
* synonyms?: string | RemoteTagSynonym[]
6+
* synonyms?: string | QPixelTagSynonym[]
257
* }} ProcessedTag
268
*/
279

@@ -87,7 +69,7 @@ $(() => {
8769
headers: { 'Accept': 'application/json' },
8870
delay: 100,
8971
/**
90-
* @param {RemoteTag[]} data
72+
* @param {QPixelTag[]} data
9173
* @returns {Select2.ProcessedResult<ProcessedTag>}
9274
*/
9375
processResults: (data) => {
@@ -120,8 +102,8 @@ $(() => {
120102

121103
/**
122104
* @param {JQuery} $search
123-
* @param {RemoteTagSynonym[]} synonyms
124-
* @returns {string | RemoteTagSynonym[]}
105+
* @param {QPixelTagSynonym[]} synonyms
106+
* @returns {string | QPixelTagSynonym[]}
125107
*/
126108
function processSynonyms($search, synonyms) {
127109
if (!synonyms) return synonyms;

global.d.ts

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,53 @@ type QPixelComment = {
201201
references_comment_id: string | null
202202
}
203203

204+
type QPixelFlag = {
205+
exclude_tags: [string, number][]
206+
include_tags: [string, number][]
207+
max_answers: number | null
208+
max_score: number | null
209+
min_answers: number | null
210+
min_score: number | null
211+
status: 'any' | 'closed' | 'open'
212+
system: boolean
213+
}
214+
215+
type QPixelSuggestedEditActionResult = {
216+
message?: string
217+
redirect_url?: string
218+
status: 'success' | 'error'
219+
}
220+
221+
type QPixelTag = {
222+
community_id: number
223+
created_at: string
224+
excerpt: string
225+
id: number
226+
name: string
227+
parent_id: number | null
228+
tag_set_id: number
229+
tag_synonyms: QPixelTagSynonym[]
230+
updated_at: string
231+
wiki: string | null
232+
wiki_markdown: string
233+
}
234+
235+
type QPixelTagSynonym = {
236+
name: string
237+
}
238+
239+
type QPixelUser = {
240+
id: number
241+
is_standard: boolean
242+
is_moderator: boolean
243+
is_admin: boolean
244+
is_global_moderator: boolean
245+
is_global_admin: boolean
246+
se_acct_id: string | null
247+
trust_level: number
248+
username: string
249+
}
250+
204251
type QPixelFlagData = {
205252
flag_type: number | null
206253
post_id: string
@@ -215,11 +262,11 @@ interface GetThreadContentOptions {
215262

216263
interface QPixel {
217264
// private properties
218-
_filters?: Filter[] | null;
265+
_filters?: QPixelFlag[] | null;
219266
_pendingUserResponse?: Promise<Response> | null;
220267
_popups?: Record<string, QPixelPopup>;
221268
_preferences?: UserPreferences | null;
222-
_user?: User | null;
269+
_user?: QPixelUser | null;
223270

224271
// private methods
225272

@@ -309,7 +356,7 @@ interface QPixel {
309356
*/
310357
defaultFilter?: (categoryId: string) => Promise<string>;
311358
deleteFilter?: (name: string, system?: boolean) => Promise<void>;
312-
filters?: () => Promise<Record<string, Filter>>;
359+
filters?: () => Promise<Record<string, QPixelFlag>>;
313360

314361
/**
315362
* Get the absolute offset of an element.
@@ -332,7 +379,7 @@ interface QPixel {
332379
* @param text the text with which to replace the selection
333380
*/
334381
replaceSelection?: ($field: JQuery<HTMLInputElement | HTMLTextAreaElement>, text: string) => void;
335-
setFilter?: (name: string, filter: Filter, category: string, isDefault: boolean) => Promise<void>;
382+
setFilter?: (name: string, filter: QPixelFlag, category: string, isDefault: boolean) => Promise<void>;
336383
setFilterAsDefault?: (categoryId: string, name: string) => Promise<void>;
337384

338385
/**
@@ -347,7 +394,7 @@ interface QPixel {
347394
* Get the user object for the current user.
348395
* @returns JSON object containing user details
349396
*/
350-
user?: () => Promise<User>;
397+
user?: () => Promise<QPixelUser>;
351398

352399
/**
353400
* Internal. Called just before a post is sent to the server to validate that it passes

0 commit comments

Comments
 (0)