Skip to content

Commit

Permalink
recode the unapproved and remix boxes on projects
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyGamer13 committed Aug 27, 2023
1 parent 0a75670 commit 03b70b7
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/lib/file-uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ const soundUpload = function (fileData, fileType, storage, handleSound, handleEr
* @param {Function} handleError The function to execute if there is an error parsing the sound
*/
const externalFileUpload = function (fileData, fileType, storage, handleFile, handleError) {
// TODO: we should handle TXT and JSON differently
const vmFile = createVMAsset(
storage,
storage.AssetType.ExternalFile,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/project-fetcher-hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const ProjectFetcherHOC = function (WrappedComponent) {
if (!res.ok) {
// Treat failure to load as an error
// Throw to be caught by catch later on
throw new Error('Could not find project; ' + err);
throw new Error('Could not find project; ' + projectUrl);
}
res.arrayBuffer().then(data => {
this.props.onFetchedProjectData(data, loadingState);
Expand Down
58 changes: 54 additions & 4 deletions src/lib/tw-project-meta-fetcher-hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { connect } from 'react-redux';
import log from './log';

import { setProjectTitle } from '../reducers/project-title';
import { setAuthor, setDescription } from '../reducers/tw';
import { setAuthor, setDescription, setExtraProjectInfo, setRemixedProjectInfo } from '../reducers/tw';

const API_URL = 'https://projects.penguinmod.site/api/projects/getPublished?id=$id';
const API_REMIX_URL = 'https://projects.penguinmod.site/api/pmWrapper/remixes?id=$id';
Expand Down Expand Up @@ -52,7 +52,6 @@ const setIndexable = indexable => {
}
};

window.ForceProjectRemixListUpdate = 0
const TWProjectMetaFetcherHOC = function (WrappedComponent) {
class ProjectMetaFetcherComponent extends React.Component {
shouldComponentUpdate(nextProps) {
Expand All @@ -63,6 +62,7 @@ const TWProjectMetaFetcherHOC = function (WrappedComponent) {
this.props.vm.runtime.renderer.setPrivateSkinAccess(true);
this.props.onSetAuthor('', '');
this.props.onSetDescription('', '');
this.props.onSetRemixedProjectInfo(false, '', '');
const projectId = this.props.projectId;
// Don't try to load metadata for empty projects.
if (projectId === '0') {
Expand All @@ -84,6 +84,7 @@ const TWProjectMetaFetcherHOC = function (WrappedComponent) {
// window.FetchedProjectRemixes = remixes
// window.ForceProjectRemixListUpdate += 1
// })
const rawData = data;
data = APIProjectToReadableProject(data);
// If project ID changed, ignore the results.
if (this.props.projectId !== projectId) {
Expand All @@ -101,6 +102,45 @@ const TWProjectMetaFetcherHOC = function (WrappedComponent) {
if (instructions || credits) {
this.props.onSetDescription(instructions, credits);
}
if (
typeof rawData.accepted === 'boolean'
|| rawData.remix > 0 // checks isRemix and remixId existing at the same time
|| typeof rawData.tooLarge === 'boolean'
|| authorName
) {
this.props.onSetExtraProjectInfo(
rawData.accepted === true,
rawData.remix > 0,
Number(rawData.remix),
rawData.tooLarge === true,
authorName
);
}
if (rawData.remix > 0) {
// this is a remix, find the original project
fetchProjectMeta(rawData.remix)
.then(remixProject => {
// If project ID changed, ignore the results.
if (this.props.projectId !== projectId) {
return;
}
// If this project is hidden or not approved, ignore the results.
if (
typeof remixProject.name === 'string'
|| typeof remixProject.owner === 'string'
) {
this.props.onSetRemixedProjectInfo(
true, // loaded
remixProject.name,
remixProject.owner
);
}
})
.catch(err => {
// this isnt fatal, just log
log.warn('cannot fetch remixed project meta for this project;', err);
});
}
setIndexable(true);
})
.catch(err => {
Expand Down Expand Up @@ -156,6 +196,18 @@ const TWProjectMetaFetcherHOC = function (WrappedComponent) {
instructions,
credits
})),
onSetExtraProjectInfo: (accepted, isRemix, remixId, tooLarge, author) => dispatch(setExtraProjectInfo({
accepted,
isRemix,
remixId,
tooLarge,
author
})),
onSetRemixedProjectInfo: (loaded, name, author) => dispatch(setRemixedProjectInfo({
loaded,
name,
author
})),
onSetProjectTitle: title => dispatch(setProjectTitle(title))
});
return connect(
Expand All @@ -164,8 +216,6 @@ const TWProjectMetaFetcherHOC = function (WrappedComponent) {
)(ProjectMetaFetcherComponent);
};

window.CurrentRemixFetchRequestId = 0

export {
TWProjectMetaFetcherHOC as default
};
7 changes: 7 additions & 0 deletions src/playground/interface.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ a {
text-decoration: none;
}

.remix-author-image {
width: 32px;
height: 32px;
margin-right: 4px;
border-radius: 4px;
}

.remixList {
overflow-x: auto;
display: flex;
Expand Down
80 changes: 58 additions & 22 deletions src/playground/render-interface.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const urlparams = new URLSearchParams(location.search);
const restoring = urlparams.get("restore");
const restoreHandler = urlparams.get("handler");
if (String(restoring) === "true") {
console.log(restore)
// console.log(restore)
restore(restoreHandler);
}

Expand Down Expand Up @@ -221,6 +221,8 @@ class Interface extends React.Component {
intl,
hasCloudVariables,
description,
extraProjectInfo,
remixedProjectInfo,
isFullScreen,
isLoading,
isPlayerOnly,
Expand Down Expand Up @@ -269,30 +271,46 @@ class Interface extends React.Component {
{isHomepage ? (
<React.Fragment>
{/* project not approved message */}
{/* would remove this and recode it but its kind of important */}
{(window.LastFetchedProject) != null && (window.LastFetchedProject.accepted == false) ? (
{(!extraProjectInfo.accepted) && (
<div className={styles.remixWarningBox}>
<p>This project is not approved. Be careful when running this project.</p>
</div>
) : null}
{/* todo: fix this and make it work properly */}
{/* project too large to remix message */}
{/* {(window.LastFetchedProject) != null && (window.LastFetchedProject.tooLarge == true) ? (
<div className={styles.remixWarningBox}>
<p>This project is too large to be remixed. If you would like to remix this project, please contact someone who can manually upload it for you.</p>
</div>
) : null} */}
{/* todo: fix this and make it work properly */}
{/* its time for some absolutely BANGER react code boys */}
{/* {(window.LastFetchedProject) != null && (window.LastFetchedProject.remix != null) ? (
)}
{/* remix info */}
{(extraProjectInfo.isRemix && remixedProjectInfo.loaded) && (
<div className={styles.unsharedUpdate}>
<div style={{ display: "flex", flexDirection: "row" }}>
<a style={{ height: "32px" }} target="_blank" href={"https://penguinmod.site/profile?user=" + projectDetailCache[String(window.LastFetchedProject.remix)]?.owner}><img style={{ marginRight: "4px", borderRadius: "4px" }} width="32" height="32" title={projectDetailCache[String(window.LastFetchedProject.remix)]?.owner} alt={projectDetailCache[String(window.LastFetchedProject.remix)]?.owner} src={"https://trampoline.turbowarp.org/avatars/by-username/" + projectDetailCache[String(window.LastFetchedProject.remix)]?.owner}></img></a>
<p>Thanks to <b><a target="_blank" href={"https://penguinmod.site/profile?user=" + projectDetailCache[String(window.LastFetchedProject.remix)]?.owner}>{projectDetailCache[String(window.LastFetchedProject.remix)]?.owner}</a></b> for the original project <b><a href={window.location.origin + "/#" + projectDetailCache[String(window.LastFetchedProject.remix)]?.id}>{projectDetailCache[String(window.LastFetchedProject.remix)]?.name}</a></b>.</p>
<a
style={{ height: "32px" }}
target="_blank"
href={`https://penguinmod.site/profile?user=${remixedProjectInfo.author}`}
>
<img
className={styles.remixAuthorImage}
title={remixedProjectInfo.author}
alt={remixedProjectInfo.author}
src={`https://trampoline.turbowarp.org/avatars/by-username/${remixedProjectInfo.author}`}
/>
</a>
<p>
Thanks to <b>
<a
target="_blank"
href={`https://penguinmod.site/profile?user=${remixedProjectInfo.author}`}
>
{remixedProjectInfo.author}
</a>
</b> for the original project <b>
<a
href={`${window.location.origin}/#${extraProjectInfo.remixId}`}
>
{remixedProjectInfo.name}
</a>
</b>.
</p>
</div>
<div style={{ display: 'none' }}>{getProjectDetailsById(window.LastFetchedProject.remix).yesIDefinetlyKnowHowToUseReactProperlyShutUp}</div>
</div>
) : null} */}
)}
{isRendererSupported() ? null : (
<WebGlModal isRtl={isRtl} />
)}
Expand All @@ -314,10 +332,14 @@ class Interface extends React.Component {
</div>
) : null}
<VoteFrame id={projectId} darkmode={this.props.isDark}></VoteFrame>
{/* todo: fix this and make it work properly */}
{/* {((window.LastFetchedProject) != null) ? (
<a target="_blank" href={"https://penguinmod.site/profile?user=" + window.LastFetchedProject.owner}>View other projects by {window.LastFetchedProject.owner}</a>
) : null} */}
{extraProjectInfo.author && (
<a
target="_blank"
href={`https://penguinmod.site/profile?user=${extraProjectInfo.author}`}
>
View other projects by {extraProjectInfo.author}
</a>
)}
<div className={styles.section}>
<p>
<FormattedMessage
Expand Down Expand Up @@ -357,6 +379,18 @@ Interface.propTypes = {
credits: PropTypes.string,
instructions: PropTypes.string
}),
extraProjectInfo: PropTypes.shape({
accepted: PropTypes.bool,
isRemix: PropTypes.bool,
remixId: PropTypes.number,
tooLarge: PropTypes.bool,
author: PropTypes.string
}),
remixedProjectInfo: PropTypes.shape({
loaded: PropTypes.bool,
name: PropTypes.string,
author: PropTypes.string
}),
isFullScreen: PropTypes.bool,
isLoading: PropTypes.bool,
isPlayerOnly: PropTypes.bool,
Expand All @@ -369,6 +403,8 @@ const mapStateToProps = state => ({
hasCloudVariables: state.scratchGui.tw.hasCloudVariables,
customStageSize: state.scratchGui.customStageSize,
description: state.scratchGui.tw.description,
extraProjectInfo: state.scratchGui.tw.extraProjectInfo,
remixedProjectInfo: state.scratchGui.tw.remixedProjectInfo,
isFullScreen: state.scratchGui.mode.isFullScreen,
isLoading: getIsLoading(state.scratchGui.projectState.loadingState),
isPlayerOnly: state.scratchGui.mode.isPlayerOnly,
Expand Down
38 changes: 38 additions & 0 deletions src/reducers/tw.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const SET_WINDOW_FULLSCREEN = 'tw/SET_WINDOW_FULLSCREEN';
const SET_DIMENSIONS = 'tw/SET_DIMENSIONS';
const SET_AUTHOR = 'tw/SET_AUTHOR';
const SET_DESCRIPTION = 'tw/SET_DESCRIPTION';
const SET_EXTRA_PROJECT_INFO = 'tw/SET_EXTRA_PROJECT_INFO';
const SET_REMIXED_PROJECT_INFO = 'tw/SET_REMIXED_PROJECT_INFO';
const ADD_COMPILE_ERROR = 'tw/ADD_COMPILE_ERROR';
const CLEAR_COMPILE_ERRORS = 'tw/CLEAR_COMPILE_ERRORS';
const SET_FILE_HANDLE = 'tw/SET_FILE_HANDLE';
Expand Down Expand Up @@ -40,6 +42,18 @@ export const initialState = {
instructions: '',
credits: ''
},
extraProjectInfo: {
accepted: true,
isRemix: false,
remixId: 0,
tooLarge: false,
author: ''
},
remixedProjectInfo: {
loaded: false,
name: '',
author: ''
},
compileErrors: [],
fileHandle: null,
usernameInvalid: false,
Expand Down Expand Up @@ -93,6 +107,14 @@ const reducer = function (state, action) {
return Object.assign({}, state, {
description: action.description
});
case SET_EXTRA_PROJECT_INFO:
return Object.assign({}, state, {
extraProjectInfo: action.extraProjectInfo
});
case SET_REMIXED_PROJECT_INFO:
return Object.assign({}, state, {
remixedProjectInfo: action.remixedProjectInfo
});
case ADD_COMPILE_ERROR:
return Object.assign({}, state, {
compileErrors: [
Expand Down Expand Up @@ -198,6 +220,20 @@ const setDescription = function (description) {
};
};

const setExtraProjectInfo = function (extraProjectInfo) {
return {
type: SET_EXTRA_PROJECT_INFO,
extraProjectInfo: extraProjectInfo
};
};

const setRemixedProjectInfo = function (remixedProjectInfo) {
return {
type: SET_REMIXED_PROJECT_INFO,
remixedProjectInfo: remixedProjectInfo
};
};

const addCompileError = function (error) {
return {
type: ADD_COMPILE_ERROR,
Expand Down Expand Up @@ -246,6 +282,8 @@ export {
setDimensions,
setAuthor,
setDescription,
setExtraProjectInfo,
setRemixedProjectInfo,
addCompileError,
clearCompileErrors,
setFileHandle,
Expand Down

0 comments on commit 03b70b7

Please sign in to comment.