Skip to content

Commit 3ef3231

Browse files
committed
Fixed Add Images for new backend endpoint.
1 parent 4b4a9b9 commit 3ef3231

File tree

7 files changed

+659
-67
lines changed

7 files changed

+659
-67
lines changed

mystbin/frontend/components/EditorTabs.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import React from "react";
1414
import SettingsIcon from "@material-ui/icons/Settings";
1515
import AddBoxIcon from '@material-ui/icons/AddBox';
1616
import LibraryAddCheckIcon from '@material-ui/icons/LibraryAddCheck';
17+
import {ImageRounded} from "@material-ui/icons";
1718

1819
const languages = {
1920
py: "python",
@@ -188,8 +189,9 @@ export default function EditorTabs({
188189
<>
189190
<div>
190191
{value.map((v, i) => (
191-
<div className={styles.attachmentImageBackdrop} onClick={(e) => setShowImage(-1)} style={{ display: showImage === i ? "block" : "none",}}>
192+
<div className={styles.attachmentImageBackdrop} onClick={(e) => setShowImage(-1)} style={{ display: showImage === i ? "flex" : "none",}}>
192193
<img className={styles.attachmentImage} src={value[i]['image']} style={{ display: showImage === i ? "block" : "none",}}/>
194+
<a className={styles.attachmentLink} href={value[i]['image']} target={"_blank"}>Open Original</a>
193195
</div>
194196
))}
195197
</div>
@@ -234,20 +236,22 @@ export default function EditorTabs({
234236
</div> : null}
235237

236238
{ value[i]['image'] ?
237-
<div className={styles.addImageButtonContainer} onClick={(e) => setShowImage(i)}>
238-
<LibraryAddCheckIcon style={{color: "#E3E3E3"}}/>
239+
<div
240+
className={styles.addImageButtonContainer}
241+
onClick={() => setShowImage(i)}
242+
>
243+
<ImageRounded className={styles.addImagesButtonNS}/>
239244
</div>
240245
: null }
241246

242247
{!!pid ? (
243248
<div className={styles.dropdownContainer} ref={tabRef}>
244-
<Button
245-
type="submit"
249+
<div
246250
className={styles.langButton}
247251
onClick={() => setLangDropDown(!langDropDown)}
248252
>
249253
<SettingsIcon />
250-
</Button>
254+
</div>
251255
{langDropDown ? (
252256
<div className={styles.langParent}>
253257
<Dropdown className={styles.dropDown} autoClose>

mystbin/frontend/components/OptsBar.tsx

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,6 @@ export default function OptsBar() {
3939

4040
const [uploaded, setUploaded] = useState(false)
4141

42-
function handleFileUploads(id) {
43-
let paste = pasteStore.getPaste();
44-
let FD = new FormData();
45-
46-
for (const [index, element] of paste.entries()) {
47-
if (element['image'] === null || element['image'] == undefined) {
48-
continue
49-
}
50-
else {
51-
let name = `${index}-${id}-${element['image'].name}`
52-
FD.append('images', element['image'], name)
53-
}
54-
55-
if (FD.entries().next().done === true) {
56-
setUploaded(true)
57-
return
58-
}
59-
}
60-
61-
axios({
62-
url: `${config['site']['backend_site']}/images/upload/${id}`,
63-
method: 'PUT',
64-
data: FD,
65-
}).then((response) => {
66-
setUploaded(true);
67-
})
68-
}
6942

7043
const personal = [
7144
{
@@ -164,32 +137,49 @@ export default function OptsBar() {
164137

165138
setSaving(true);
166139
let files = [];
140+
let FD = new FormData();
167141

168142
for (let file of paste) {
169-
files.push({ filename: file["title"], content: file["content"] });
143+
if (file['image'] === null || file['image'] == undefined) {
144+
files.push({ filename: file["title"], content: file["content"] });
145+
}
146+
else {
147+
files.push({ filename: file["title"], content: file["content"], attachment: file['image'].name });
148+
FD.append('images', file['image'], file['image'].name)
149+
}
170150
}
171151

152+
let data = { "files": files, "password": paste.password }
153+
FD.append('data', JSON.stringify(data))
154+
172155
const headers = {
173-
"Content-Type": "application/json",
156+
"Content-Type": "multipart/form-data",
174157
};
158+
175159
if (!!cookieCutter.get("auth")) {
176160
headers["Authorization"] = cookieCutter.get("auth");
177161
}
178-
fetch(config["site"]["backend_site"] + "/paste", {
179-
method: "PUT",
162+
163+
axios( {
164+
url: config["site"]["backend_site"] + "/rich-paste",
165+
method: "POST",
180166
headers: headers,
181-
body: JSON.stringify({ files: files, password: paste.password }),
167+
data: FD,
182168
})
183169
.then((r) => {
184170
if (r.status === 201) {
185-
return r.json();
171+
return r.data;
186172
}
187173
setSaving(false);
174+
setUploaded(false);
175+
188176
console.error(r.status);
177+
console.log(r.data)
189178
})
190179
.then((d) => {
180+
setUploaded(true);
181+
191182
if (d && d.id) {
192-
handleFileUploads(d.id)
193183

194184
let path = `/${d.id}`;
195185
let full = window.location.origin + path;
@@ -198,7 +188,7 @@ export default function OptsBar() {
198188
setSaveSuccessToast(d.id);
199189
setTimeout(() => {
200190
router.push(path);
201-
}, 6000);
191+
}, 3000);
202192
});
203193
}
204194
});

mystbin/frontend/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
"launch": "next build && next start"
1111
},
1212
"dependencies": {
13+
"@emotion/react": "^11.10.4",
14+
"@emotion/styled": "^11.10.4",
1315
"@material-ui/core": "^4.11.0",
1416
"@material-ui/icons": "^4.9.1",
1517
"@material-ui/x-grid": "^4.0.0-alpha.37",
1618
"@monaco-editor/react": "^3.7.0",
19+
"@mui/icons-material": "^5.10.3",
20+
"@mui/material": "^5.10.3",
1721
"@types/crypto-js": "^4.0.1",
1822
"@types/node": "*",
1923
"@types/react": "18.0.1",
@@ -27,6 +31,7 @@
2731
"flux": "^4.0.1",
2832
"http-proxy": "^1.18.1",
2933
"install": "^0.13.0",
34+
"mui-datatables": "^4.2.2",
3035
"next": "^11.0.0",
3136
"react": "17.0.1",
3237
"react-bootstrap": "^2.5.0",

mystbin/frontend/pages/[pid].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function Pastey(props: PropsWithoutRef<{ paste }>) {
2222
});
2323
} else {
2424
for (let file of paste["files"]) {
25-
initialData.push({ title: file["filename"], content: file["content"], image: file['image'] });
25+
initialData.push({ title: file["filename"], content: file["content"], image: file['attachment'] });
2626
}
2727
}
2828

mystbin/frontend/styles/EditorTabs.module.css

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
display: flex;
3030
align-self: center;
3131
justify-content: center;
32-
margin: -1rem!important;
32+
padding: 0.5rem;
3333
}
3434

3535
.langButton:hover {
@@ -83,7 +83,7 @@
8383
display: flex;
8484
align-items: center;
8585
justify-content: center;
86-
padding: 0.5rem
86+
padding: 0.5rem;
8787
}
8888

8989
.addImagesButtonNS {
@@ -100,17 +100,31 @@
100100

101101
.attachmentImageBackdrop {
102102
position: fixed;
103+
display: flex;
104+
flex-direction: column;
103105
width: 100vw;
104106
height: 100vh;
105107
background-color: rgba(0, 0, 0, 0.5);
106-
z-index: 9;
108+
z-index: 7;
109+
justify-content: center;
107110
}
108111

109112
.attachmentImage {
110-
position: fixed;
111-
left: 50%;
112-
top: 50%;
113-
transform: translate(-50%, -50%);
113+
align-self: center;
114+
justify-self: center;
114115
z-index: 8;
115-
max-width: 100%;
116+
max-height: 60%;
117+
}
118+
119+
.attachmentLink {
120+
color: #e3e3e3;
121+
z-index: 8;
122+
align-self: center;
123+
text-decoration: none;
124+
}
125+
126+
.attachmentLink:hover {
127+
filter: brightness(120%);
128+
color: #e3e3e3;
129+
cursor: pointer;
116130
}

mystbin/frontend/styles/globals.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,18 @@ input[type=radio] {
217217
/* Handle */
218218
.dropdown::-webkit-scrollbar-thumb {
219219
background: #0070f3;
220+
}
221+
222+
::-webkit-scrollbar {
223+
width: 10px;
224+
}
225+
226+
/* Track */
227+
::-webkit-scrollbar-track {
228+
background: rgba(200, 200, 255, 0.3);
229+
}
230+
231+
/* Handle */
232+
::-webkit-scrollbar-thumb {
233+
background: #3b3b3b;
220234
}

0 commit comments

Comments
 (0)