Skip to content

add button to remove banner #3129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 42 additions & 32 deletions client/modules/IDE/pages/IDEView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from '../components/Editor/MobileEditor';
import IDEOverlays from '../components/IDEOverlays';
import useIsMobile from '../hooks/useIsMobile';
import { CrossIcon } from '../../../common/icons';

function getTitle(project) {
const { id } = project;
Expand Down Expand Up @@ -87,37 +88,6 @@ function WarnIfUnsavedChanges() {
);
}

function Banner() {
// temporary banner to display funding opportunities
const [textObj, setTextObj] = useState({});

useEffect(() => {
const grant1 = {
copy:
'Learn to make art with AI with the Social Software High School Summer Institute. Apply by June 1!',
url: 'https://summer.ucla.edu/program/social-software-summer-institute/'
};

const grant2 = {
copy:
'Join us in contributing to p5.js——receive a $10,000 opportunity to grow within the contributor community!',
url: 'https://processingfoundation.org/grants'
};

const allMessages = [grant1, grant2];
const randomIndex = Math.floor(Math.random() * allMessages.length);
const randomMessage = allMessages[randomIndex];

setTextObj(randomMessage);
}, []);

return (
<div className="banner">
<a href={textObj.url}>{textObj.copy}</a>
</div>
);
}

export const CmControllerContext = React.createContext({});

const IDEView = () => {
Expand All @@ -135,6 +105,7 @@ const IDEView = () => {
const [sidebarSize, setSidebarSize] = useState(160);
const [isOverlayVisible, setIsOverlayVisible] = useState(false);
const [MaxSize, setMaxSize] = useState(window.innerWidth);
const [displayBanner, setDisplayBanner] = useState(true);

const cmRef = useRef({});

Expand All @@ -145,6 +116,45 @@ const IDEView = () => {
dispatch(updateFileContent(file.id, file.content));
};

const Banner = () => {
// temporary banner to display funding opportunities
const [textObj, setTextObj] = useState({});

useEffect(() => {
const grant1 = {
copy:
'Learn to make art with AI with the Social Software High School Summer Institute. Apply by June 1!',
url: 'https://summer.ucla.edu/program/social-software-summer-institute/'
};

const grant2 = {
copy:
'Join us in contributing to p5.js——receive a $10,000 opportunity to grow within the contributor community!',
url: 'https://processingfoundation.org/grants'
};

const allMessages = [grant1, grant2];
const randomIndex = Math.floor(Math.random() * allMessages.length);
const randomMessage = allMessages[randomIndex];

setTextObj(randomMessage);
}, []);

return (
<div className="banner">
<a href={textObj.url}>{textObj.copy}</a>
<button
className="banner-close-button"
onClick={() => {
setDisplayBanner(!displayBanner);
}}
>
<CrossIcon />
</button>
</div>
);
};

useEffect(() => {
dispatch(clearPersistedState());
}, [dispatch]);
Expand Down Expand Up @@ -201,7 +211,7 @@ const IDEView = () => {
<Helmet>
<title>{getTitle(project)}</title>
</Helmet>
<Banner />
{displayBanner && <Banner />}
<IDEKeyHandlers getContent={() => cmRef.current?.getContent()} />
<WarnIfUnsavedChanges />
<Toast />
Expand Down
10 changes: 10 additions & 0 deletions client/styles/layout/_ide.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
}
}

.banner-close-button{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 20px;
width:20px;
float: right;
}

.sidebar {
width: 100%;
height: 100%;
Expand Down
Loading