Skip to content

Commit

Permalink
Created preferences screen
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBacon committed Jul 10, 2020
1 parent 168d924 commit 5198fd6
Show file tree
Hide file tree
Showing 7 changed files with 345 additions and 17 deletions.
7 changes: 7 additions & 0 deletions client/src/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Licenses from "./components/Licenses";
// import Fire from "./ExpoParty/Fire";
import GameScreen from "./screens/GameScreen";
import ChallengesScreen from "./screens/AchievementScreen";
import Preferences from "./screens/PreferencesScreen";
// import LeaderboardScreen from "./screens/LeaderboardScreen";
// import ProfileScreen from "./screens/ProfileScreen";
// import ReportScreen from "./screens/ReportScreen";
Expand All @@ -35,6 +36,7 @@ const linking = {
Licenses: "/credit",
Report: "/report",
Challenges: "/challenges",
Preferences: "/settings",
Social: {
screens: {
Leaderboard: "/rank",
Expand Down Expand Up @@ -121,6 +123,11 @@ export default () => {
component={Licenses}
options={{ stackPresentation: "modal" }}
/>
<AppStack.Screen
name="Preferences"
component={Preferences}
options={{ stackPresentation: "modal" }}
/>
</AppStack.Navigator>
</NavigationContainer>
);
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default class Avatar extends React.PureComponent<{
}}
style={[
styles.avatarStyle,
{ backgroundColor: this.props.color ?? this.avatarColor },
{ backgroundColor: this.props.color || this.avatarColor },
this.props.avatarStyle,
]}
accessibilityTraits="image"
Expand Down
10 changes: 10 additions & 0 deletions client/src/components/Button/PreferencesButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from "react";

import Icon from "./Icon";

const PreferencesButton = React.forwardRef(
(props: React.ComponentProps<typeof Icon>, ref) => {
return <Icon {...props} ref={ref} name="cog" />;
}
);
export default PreferencesButton;
4 changes: 4 additions & 0 deletions client/src/components/Button/SwapPlatformButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ function openPlatformLink(platform) {
}
}

export function openOtherPlatform() {
openPlatformLink(getOtherPlatform());
}

/**
* This button recommends the other available platform on the device.
* iOS -> website
Expand Down
15 changes: 6 additions & 9 deletions client/src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import LicensesButton from "./Button/LicensesButton";
import PWAButton, { usePWAInstallable } from "./Button/PWAButton";
import ShareButton from "./Button/Share";
import SoundButton from "./Button/Sound";
import PreferencesButton from "./Button/PreferencesButton";
import SwapPlatformButton, {
getOtherPlatform,
} from "./Button/SwapPlatformButton";
Expand Down Expand Up @@ -44,31 +45,27 @@ function Footer({ game, screenshot, navigation }) {
// This state toggles when the user installs so the button isn't rendered anymore
const [showPWA, setShowPWA] = React.useState(true);
const animation = game === GameStates.Menu ? "zoomIn" : "zoomOut";
const onLicensesPress = () => {
// dispatch.presentAchievement.set({ name: "Nerdy boi", score: null });
navigation.navigate("Licenses");
};

const onChallengesPress = () => {
navigation.navigate("Challenges");
};
const onPreferencesPress = () => {
navigation.navigate("Preferences");
};
const views = [];

if (Platform.OS !== "web") {
views.push(<SoundButton />);
}

if (!Settings.isPromo && getOtherPlatform()) {
views.push(<SwapPlatformButton />);
}

if (canInstallPwa && showPWA) {
views.push(<PWAButton onInstall={() => setShowPWA(false)} />);
}

if (!Settings.isPromo) {
views.push(<ChallengesButton onPress={onChallengesPress} />);
views.push(<LicensesButton onPress={onLicensesPress} />);
}
views.push(<PreferencesButton onPress={onPreferencesPress} />);

const onLeaderboardPress = () => {
if (Settings.isFirebaseEnabled) {
Expand Down
35 changes: 28 additions & 7 deletions client/src/rematch/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type AchievementsShape = Record<string, true>;
export const achievements = {
state: {},
reducers: {
_reset: () => ({}),
set: (
state: AchievementsShape,
val: AchievementsShape
Expand Down Expand Up @@ -81,6 +82,7 @@ import { promptToReviewAsync } from "../utils/promptStoreReview";
export const bestRounds = {
state: 0,
reducers: {
_reset: () => 0,
set: (state: number, rounds: number): number => rounds,
},
effects: {
Expand All @@ -105,6 +107,20 @@ export const bestRounds = {
},
};

type DeveloperShape = {
isActive: boolean;
};
export const developer = {
state: { isActive: false },
reducers: {
set: (
state: DeveloperShape,
updates: Partial<DeveloperShape>
): DeveloperShape => ({ ...state, ...updates }),
},
effects: {},
};

function hasBeenAtLeastOneDaySinceTime(time: number): boolean {
// 1 Day after the last prompt time (or since the app was first opened).
const appropriateTimeToAskAgain = new Date(time);
Expand All @@ -125,6 +141,7 @@ export type StoreReviewShape = {
export const storeReview = {
state: { promptTime: Date.now() },
reducers: {
_reset: () => ({ promptTime: Date.now() }),
set: (
state: StoreReviewShape,
value: Partial<StoreReviewShape>
Expand All @@ -150,6 +167,7 @@ export const storeReview = {
export const rounds = {
state: 0,
reducers: {
_reset: () => 0,
set: (state: number, rounds: number): number => rounds,
},
effects: {
Expand Down Expand Up @@ -179,15 +197,18 @@ export type ScoreShape = {
isBest: boolean;
};

const initialScoreState: ScoreShape = {
current: 0,
best: 0,
total: 0,
last: null,
isBest: false,
};

export const score = {
state: {
current: 0,
best: 0,
total: 0,
last: null,
isBest: false,
},
state: { ...initialScoreState },
reducers: {
_hardReset: () => ({ ...initialScoreState }),
setBest: (state: ScoreShape, best: number): ScoreShape => ({
...state,
best,
Expand Down
Loading

0 comments on commit 5198fd6

Please sign in to comment.