Skip to content

Commit

Permalink
Reimplement glitchy elephant friend
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Feb 23, 2024
1 parent 2be2df0 commit 47c67b1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 62 deletions.
7 changes: 0 additions & 7 deletions app/javascript/flavours/glitch/actions/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ let fetchComposeSuggestionsAccountsController;
let fetchComposeSuggestionsTagsController;

export const COMPOSE_CHANGE = 'COMPOSE_CHANGE';
export const COMPOSE_CYCLE_ELEFRIEND = 'COMPOSE_CYCLE_ELEFRIEND';
export const COMPOSE_SUBMIT_REQUEST = 'COMPOSE_SUBMIT_REQUEST';
export const COMPOSE_SUBMIT_SUCCESS = 'COMPOSE_SUBMIT_SUCCESS';
export const COMPOSE_SUBMIT_FAIL = 'COMPOSE_SUBMIT_FAIL';
Expand Down Expand Up @@ -117,12 +116,6 @@ export function changeCompose(text) {
};
}

export function cycleElefriendCompose() {
return {
type: COMPOSE_CYCLE_ELEFRIEND,
};
}

export function replyCompose(status, routerHistory) {
return (dispatch, getState) => {
const prependCWRe = getState().getIn(['local_settings', 'prepend_cw_re']);
Expand Down
23 changes: 21 additions & 2 deletions app/javascript/flavours/glitch/features/compose/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import PublicIcon from '@/material-icons/400-24px/public.svg?react';
import { openModal } from 'flavours/glitch/actions/modal';
import Column from 'flavours/glitch/components/column';
import { Icon } from 'flavours/glitch/components/icon';
import glitchedElephant1 from 'flavours/glitch/images/mbstobon-ui-0.png';
import glitchedElephant2 from 'flavours/glitch/images/mbstobon-ui-1.png';
import glitchedElephant3 from 'flavours/glitch/images/mbstobon-ui-2.png';
import { logOut } from 'flavours/glitch/utils/log_out';

import elephantUIPlane from '../../../../images/elephant_ui_plane.svg';
Expand Down Expand Up @@ -51,6 +54,11 @@ const mapStateToProps = (state, ownProps) => ({
showSearch: ownProps.multiColumn ? state.getIn(['search', 'submitted']) && !state.getIn(['search', 'hidden']) : false,
});

// ~4% chance you'll end up with an unexpected friend
// glitch-soc/mastodon repo created_at date: 2017-04-20T21:55:28Z
const glitchProbability = 1 - 0.0420215528;
const totalElefriends = 3;

class Compose extends PureComponent {

static propTypes = {
Expand All @@ -61,6 +69,10 @@ class Compose extends PureComponent {
intl: PropTypes.object.isRequired,
};

state = {
elefriend: Math.random() < glitchProbability ? Math.floor(Math.random() * totalElefriends) : totalElefriends,
};

componentDidMount () {
const { dispatch } = this.props;
dispatch(mountCompose());
Expand Down Expand Up @@ -107,9 +119,15 @@ class Compose extends PureComponent {
this.props.dispatch(changeComposing(false));
};

cycleElefriend = () => {
this.setState((state) => ({ elefriend: (state.elefriend + 1) % totalElefriends }));
};

render () {
const { multiColumn, showSearch, intl } = this.props;

const elefriend = [glitchedElephant1, glitchedElephant2, glitchedElephant3, elephantUIPlane][this.state.elefriend];

if (multiColumn) {
const { columns } = this.props;

Expand Down Expand Up @@ -147,8 +165,9 @@ class Compose extends PureComponent {
<div className='drawer__inner' onFocus={this.onFocus}>
<ComposeFormContainer autoFocus={!isMobile(window.innerWidth)} />

<div className='drawer__inner__mastodon'>
<img alt='' draggable='false' src={mascot || elephantUIPlane} />
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions -- this is not a feature but a visual easter egg */}
<div className='drawer__inner__mastodon' onClick={this.cycleElefriend}>
<img alt='' draggable='false' src={mascot || elefriend} />

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
</div>
</div>

Expand Down
11 changes: 0 additions & 11 deletions app/javascript/flavours/glitch/reducers/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
COMPOSE_MOUNT,
COMPOSE_UNMOUNT,
COMPOSE_CHANGE,
COMPOSE_CYCLE_ELEFRIEND,
COMPOSE_REPLY,
COMPOSE_REPLY_CANCEL,
COMPOSE_DIRECT,
Expand Down Expand Up @@ -62,20 +61,13 @@ import { overwrite } from '../utils/js_helpers';
import { privacyPreference } from '../utils/privacy_preference';
import { uuid } from '../uuid';

const totalElefriends = 3;

// ~4% chance you'll end up with an unexpected friend
// glitch-soc/mastodon repo created_at date: 2017-04-20T21:55:28Z
const glitchProbability = 1 - 0.0420215528;

const initialState = ImmutableMap({
mounted: 0,
advanced_options: ImmutableMap({
do_not_federate: false,
threaded_mode: false,
}),
sensitive: false,
elefriend: Math.random() < glitchProbability ? Math.floor(Math.random() * totalElefriends) : totalElefriends,
spoiler: false,
spoiler_text: '',
privacy: null,
Expand Down Expand Up @@ -425,9 +417,6 @@ export default function compose(state = initialState, action) {
.set('idempotencyKey', uuid());
case COMPOSE_COMPOSING_CHANGE:
return state.set('is_composing', action.value);
case COMPOSE_CYCLE_ELEFRIEND:
return state
.set('elefriend', (state.get('elefriend') + 1) % totalElefriends);
case COMPOSE_REPLY:
return state.withMutations(map => {
map.set('id', null);
Expand Down
42 changes: 0 additions & 42 deletions app/javascript/flavours/glitch/styles/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3424,14 +3424,6 @@ $ui-header-height: 55px;
user-select: none;
}

> .mastodon {
display: block;
width: 100%;
height: 100%;
border: 0;
cursor: inherit;
}

@media screen and (height >= 640px) {
display: block;
}
Expand All @@ -3454,40 +3446,6 @@ $ui-header-height: 55px;
}
}

@for $i from 0 through 3 {
.mbstobon-#{$i} .drawer__inner__mastodon {
@if $i == 3 {
background:
url('~flavours/glitch/images/wave-drawer.png')
no-repeat
bottom /
100%
auto,
$ui-base-color;
} @else {
background:
url('~flavours/glitch/images/wave-drawer-glitched.png')
no-repeat
bottom /
100%
auto,
$ui-base-color;
}

& > .mastodon {
background: url('~flavours/glitch/images/mbstobon-ui-#{$i}.png')
no-repeat
left
bottom /
contain;

@if $i != 3 {
filter: contrast(50%) brightness(50%);
}
}
}
}

.scrollable {
overflow-y: scroll;
overflow-x: hidden;
Expand Down

0 comments on commit 47c67b1

Please sign in to comment.