Skip to content

Commit 4d5a19f

Browse files
authored
Merge pull request #22 from Acode-Foundation/feat-supported_editor
feat: enhance plugin management with editor support updates
2 parents 8f9ff30 + 2fbb78e commit 4d5a19f

File tree

23 files changed

+1411
-181
lines changed

23 files changed

+1411
-181
lines changed
59.1 KB
Loading
Lines changed: 19 additions & 0 deletions
Loading

client/components/plugins/index.js

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,58 @@ import PluginStatus from 'components/pluginStatus';
77
import { calcRating, getLoggedInUser, hideLoading, showLoading, since } from 'lib/helpers';
88
import Router from 'lib/Router';
99

10-
export default function Plugins({ user, orderBy, status, name }) {
10+
export default async function Plugins({ user, orderBy, status, name, editor }) {
1111
const el = <div className='plugins' data-msg='loading...' />;
1212

13-
(async () => {
14-
try {
15-
showLoading();
16-
let url = '/api/plugin';
17-
18-
if (user) {
19-
url += `?user=${user}`;
20-
} else if (status !== undefined) {
21-
url += `?status=${status}`;
22-
} else if (name) {
23-
url += `?name=${name}`;
24-
} else if (orderBy) {
25-
url += `?orderBy=${orderBy}`;
26-
}
13+
try {
14+
showLoading();
15+
const params = new URLSearchParams();
16+
17+
if (user) {
18+
params.set('user', user);
19+
}
20+
21+
if (status !== undefined) {
22+
params.set('status', status);
23+
}
24+
25+
if (name) {
26+
params.set('name', name);
27+
}
28+
29+
if (editor) {
30+
params.set('supported_editor', editor);
31+
}
2732

28-
const res = await fetch(url);
29-
const { isAdmin, id: userId } = (await getLoggedInUser()) || {};
30-
const plugins = await res.json();
31-
const adsPosition = [2, 15, 28];
32-
33-
el.setAttribute('data-msg', 'No plugins found. :(');
34-
for (let i = 0; i < plugins.length; i++) {
35-
const plugin = plugins[i];
36-
if (adsPosition.includes(i) || (i > 33 && Math.random() < 0.1)) {
37-
el.append(<AdSense className='plugin' style={{ position: 'relative' }} />);
38-
}
39-
el.append(<Plugin {...plugin} isAdmin={isAdmin} userId={userId} />);
33+
if (orderBy) {
34+
params.set('orderBy', orderBy);
35+
}
36+
37+
const query = params.toString();
38+
const url = `/api/plugin${query ? `?${query}` : ''}`;
39+
40+
const res = await fetch(url);
41+
const { isAdmin, id: userId } = (await getLoggedInUser()) || {};
42+
const plugins = await res.json();
43+
const adsPosition = [2, 15, 28];
44+
45+
el.setAttribute('data-msg', 'No plugins found. :(');
46+
for (let i = 0; i < plugins.length; i++) {
47+
const plugin = plugins[i];
48+
if (adsPosition.includes(i) || (i > 33 && Math.random() < 0.1)) {
49+
el.append(<AdSense className='plugin' style={{ position: 'relative' }} />);
4050
}
41-
} catch (error) {
42-
el.append(
43-
<div className='error'>
44-
<h2>{error.error}</h2>
45-
</div>,
46-
);
47-
} finally {
48-
hideLoading();
51+
el.append(<Plugin {...plugin} isAdmin={isAdmin} userId={userId} />);
4952
}
50-
})();
53+
} catch (error) {
54+
el.append(
55+
<div className='error'>
56+
<h2>{error.error}</h2>
57+
</div>,
58+
);
59+
} finally {
60+
hideLoading();
61+
}
5162

5263
return el;
5364
}
@@ -62,12 +73,14 @@ function Plugin({
6273
downloads,
6374
votes_up: upVotes,
6475
user_id: pluginUser,
65-
package_updated_at: updatedAt,
6676
votes_down: downVotes,
6777
comment_count: comments,
78+
supported_editor: editorType,
79+
package_updated_at: updatedAt,
6880
}) {
6981
return (
7082
<a href={`/plugin/${id}`} className='plugin'>
83+
<span className={`badge editor-type ${editorType}`} />
7184
<div className='plugin-icon' style={{ backgroundImage: `url(/plugin-icon/${id})` }} />
7285
<div className='plugin-info'>
7386
<h2 style={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{name}</h2>

client/components/plugins/style.scss

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
}
1313

1414
.plugin {
15+
position: relative;
1516
width: calc(33% - 30px);
1617
min-width: 250px;
1718
margin: 10px 0 0 10px;
@@ -22,6 +23,60 @@
2223
border-radius: 4px;
2324
text-decoration: none;
2425

26+
.badge {
27+
position: absolute;
28+
top: 10px;
29+
left: 10px;
30+
display: inline-block;
31+
height: 20px;
32+
width: 20px;
33+
padding: 2px 6px;
34+
border-radius: 3px;
35+
font-size: 12px;
36+
background-position: center;
37+
background-repeat: no-repeat;
38+
background-size: 100%;
39+
40+
&.editor-type {
41+
&.ace {
42+
background-image: url(./ace-logo.png);
43+
}
44+
45+
&.cm {
46+
background-image: url(./cm-logo.svg);
47+
}
48+
49+
&.all {
50+
display: flex;
51+
justify-content: center;
52+
align-items: center;
53+
width: 40px;
54+
55+
&::before,
56+
&::after {
57+
display: inline-block;
58+
height: 20px;
59+
width: 20px;
60+
background-position: center;
61+
background-repeat: no-repeat;
62+
background-size: 100%;
63+
}
64+
65+
&::before {
66+
content: '';
67+
background-image: url(./ace-logo.png);
68+
margin-right: 2px;
69+
}
70+
71+
&::after {
72+
content: '';
73+
background-image: url(./cm-logo.svg);
74+
margin-left: 2px;
75+
}
76+
}
77+
}
78+
}
79+
2580
h2 {
2681
margin-bottom: 5px;
2782
}

client/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ window.onload = async () => {
6363
Router.add('/plugin/:id/:section?', (params) => loadModule('plugin', params));
6464
Router.add('/user/:userId?', (params) => loadModule('user', params));
6565
Router.add('/earnings', (_params, query) => loadModule('earnings', query));
66+
Router.add('/update-plugin-editor/:id', (params) => loadModule('updatePluginEditor', params));
6667
Router.add('/:filename(index.html?)?', () => loadModule('home'));
6768

6869
Router.add('*', () => {

client/pages/plugin/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@ export default async function Plugin({ id: pluginId, section = 'description' })
3939
comment_count: commentCount,
4040
package_updated_at: updatedAt,
4141
author_verified: authorVerified,
42+
supported_editor: supportedEditor,
4243
} = plugin;
4344

45+
const getEditorDisplayName = (editor) => {
46+
if (editor === 'cm') return 'CodeMirror';
47+
if (editor === 'ace') return 'Ace';
48+
return 'Both Editors';
49+
};
50+
4451
const user = await getLoggedInUser();
4552
const userComment = await getUserComment(pluginId);
4653
const sectionDescription = Ref();
@@ -140,6 +147,11 @@ export default async function Plugin({ id: pluginId, section = 'description' })
140147
<span>{license}</span>
141148
</div>
142149
)}
150+
{supportedEditor && (
151+
<div className='chip editor-badge' data-editor={supportedEditor}>
152+
<span>{getEditorDisplayName(supportedEditor)}</span>
153+
</div>
154+
)}
143155
{votesUp + votesDown > 0 && (
144156
<div className='chip' onclick={() => changeSection('comments')}>
145157
<img src='/thumbs-up.gif' alt='thumbs up' />
@@ -469,7 +481,6 @@ function CommentsContainerAndForm({ plugin, listRef, user, id, userComment }) {
469481
try {
470482
const deleted = await deleteComment(commentId);
471483
if (!deleted) return;
472-
alert('SUCCESS', 'Comment deleted successfully');
473484
commentId = null;
474485
form.el.reset();
475486
for (const input of form.getAll('input[name=vote]')) {

client/pages/plugin/style.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@
99
color: #39f;
1010
}
1111

12+
.editor-badge {
13+
font-weight: 600;
14+
15+
&[data-editor='cm'] {
16+
background: rgba(16, 185, 129, 0.2) !important;
17+
border: 1px solid #10b981;
18+
color: #10b981;
19+
}
20+
21+
&[data-editor='ace'] {
22+
background: rgba(239, 68, 68, 0.2) !important;
23+
border: 1px solid #ef4444;
24+
color: #ef4444;
25+
}
26+
27+
&[data-editor='all'] {
28+
background: rgba(59, 130, 246, 0.2) !important;
29+
border: 1px solid #3b82f6;
30+
color: #3b82f6;
31+
}
32+
}
33+
1234
.plugin-head {
1335
height: fit-content;
1436
border-bottom: solid 1px rgba(234, 234, 234, 0.486);

0 commit comments

Comments
 (0)