-
Notifications
You must be signed in to change notification settings - Fork 37
Restore revenue widget #145
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
695d014
iOS widget
binary-koan 5774f90
Android widget
binary-koan 99d55ba
Merge branch 'main' into revenue-widget
binary-koan d2b5269
Fix
binary-koan ef82375
Fix
binary-koan cda9a36
Fix
binary-koan 8b53fb9
Merge branch 'main' into revenue-widget
binary-koan a65be5f
Fix
binary-koan 61af174
Fix
binary-koan 822e57f
[autofix.ci] apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| "use no memo"; | ||
|
|
||
| import { buildApiUrl, request } from "@/lib/request"; | ||
| import * as SecureStore from "expo-secure-store"; | ||
| import { registerWidgetTaskHandler, type WidgetTaskHandlerProps } from "react-native-android-widget"; | ||
| import { RevenueWidgetAndroid } from "./revenue-widget-android"; | ||
|
|
||
| interface RevenueTotalsResponse { | ||
| day: { formatted_revenue: string }; | ||
| week: { formatted_revenue: string }; | ||
| month: { formatted_revenue: string }; | ||
| year: { formatted_revenue: string }; | ||
| } | ||
|
|
||
| const renderRevenueWidget = async () => { | ||
| const accessToken = await SecureStore.getItemAsync("gumroad_access_token"); | ||
|
|
||
| if (!accessToken) { | ||
| return <RevenueWidgetAndroid today="" week="" month="" year="" isLoggedIn={false} hasError={false} />; | ||
| } | ||
|
|
||
| try { | ||
| const url = buildApiUrl("mobile/analytics/revenue_totals.json"); | ||
| const data = await request<RevenueTotalsResponse>(url, { | ||
| headers: { Authorization: `Bearer ${accessToken}` }, | ||
| }); | ||
|
|
||
| return ( | ||
| <RevenueWidgetAndroid | ||
| today={data.day.formatted_revenue} | ||
| week={data.week.formatted_revenue} | ||
| month={data.month.formatted_revenue} | ||
| year={data.year.formatted_revenue} | ||
| isLoggedIn={true} | ||
| hasError={false} | ||
| /> | ||
| ); | ||
| } catch { | ||
| return <RevenueWidgetAndroid today="" week="" month="" year="" isLoggedIn={true} hasError={true} />; | ||
| } | ||
| }; | ||
|
|
||
| registerWidgetTaskHandler(async (props: WidgetTaskHandlerProps) => { | ||
| switch (props.widgetAction) { | ||
| case "WIDGET_ADDED": | ||
| case "WIDGET_UPDATE": | ||
| case "WIDGET_RESIZED": | ||
| props.renderWidget(await renderRevenueWidget()); | ||
| break; | ||
| case "WIDGET_DELETED": | ||
| break; | ||
| case "WIDGET_CLICK": | ||
| break; | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| "use no memo"; | ||
|
|
||
| import { FlexWidget, SvgWidget, TextWidget } from "react-native-android-widget"; | ||
|
|
||
| const LOGO_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="81" height="81" fill="none"><path fill="#000" d="M43.741 80.186c20.455 0 37.037-16.582 37.037-37.037S64.196 6.112 43.741 6.112 6.704 22.694 6.704 43.149s16.582 37.037 37.037 37.037"/><path fill="#FF90E8" stroke="#000" stroke-width="1.557" d="M38.605 76.433c20.892 0 37.828-16.936 37.828-37.828 0-20.89-16.936-37.827-37.828-37.827C17.715.778.779 17.714.779 38.606c0 20.89 16.936 37.827 37.828 37.827Z"/><path fill="#000" d="M35.392 57.272c-10.849 0-17.23-8.701-17.23-19.526 0-11.249 7.02-20.375 20.421-20.375 13.828 0 18.508 9.339 18.72 14.645h-9.998c-.213-2.972-2.765-7.429-8.935-7.429-6.594 0-10.849 5.73-10.849 12.735s4.255 12.734 10.85 12.734c5.956 0 8.509-4.67 9.572-9.338H38.37v-3.82h20.087v19.525h-8.812v-12.31c-.638 4.458-3.404 13.16-14.253 13.16Z"/></svg>`; | ||
|
|
||
| const RevenueRow = ({ label, value }: { label: string; value: string }) => ( | ||
| <FlexWidget style={{ flexDirection: "row", width: "match_parent" }}> | ||
| <TextWidget text={label} style={{ fontSize: 13, fontFamily: "ABCFavorit-Regular-custom", color: "#999999" }} /> | ||
| <FlexWidget style={{ flex: 1 }} /> | ||
| <TextWidget | ||
| text={value} | ||
| style={{ fontSize: 13, fontFamily: "ABCFavorit-Bold-custom", fontWeight: "bold", color: "#ffffff" }} | ||
| /> | ||
| </FlexWidget> | ||
| ); | ||
|
|
||
| export const RevenueWidgetAndroid = ({ | ||
| today, | ||
| week, | ||
| month, | ||
| year, | ||
| isLoggedIn, | ||
| hasError, | ||
| }: { | ||
| today: string; | ||
| week: string; | ||
| month: string; | ||
| year: string; | ||
| isLoggedIn: boolean; | ||
| hasError: boolean; | ||
| }) => { | ||
| if (!isLoggedIn) { | ||
| return ( | ||
| <FlexWidget | ||
| style={{ | ||
| width: "match_parent", | ||
| height: "match_parent", | ||
| justifyContent: "center", | ||
| alignItems: "center", | ||
| backgroundColor: "#000000", | ||
| borderRadius: 16, | ||
| padding: 16, | ||
| }} | ||
| > | ||
| <TextWidget | ||
| text="Open Gumroad to log in" | ||
| style={{ fontSize: 13, fontFamily: "ABCFavorit-Bold-custom", fontWeight: "bold", color: "#ffffff" }} | ||
| /> | ||
| </FlexWidget> | ||
| ); | ||
| } | ||
|
|
||
| if (hasError) { | ||
| return ( | ||
| <FlexWidget | ||
| style={{ | ||
| width: "match_parent", | ||
| height: "match_parent", | ||
| justifyContent: "center", | ||
| alignItems: "center", | ||
| backgroundColor: "#000000", | ||
| borderRadius: 16, | ||
| padding: 16, | ||
| }} | ||
| > | ||
| <TextWidget | ||
| text="Sorry, something went wrong. Try again later." | ||
| style={{ fontSize: 13, fontFamily: "ABCFavorit-Regular-custom", color: "#ffffff", textAlign: "center" }} | ||
| /> | ||
| </FlexWidget> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <FlexWidget | ||
| style={{ | ||
| width: "match_parent", | ||
| height: "match_parent", | ||
| flexDirection: "column", | ||
| backgroundColor: "#000000", | ||
| borderRadius: 16, | ||
| paddingVertical: 16, | ||
| paddingHorizontal: 14, | ||
| }} | ||
| > | ||
| <FlexWidget style={{ flexDirection: "row", alignItems: "center", flexGap: 6 }}> | ||
| <SvgWidget svg={LOGO_SVG} style={{ width: 20, height: 20 }} /> | ||
| <TextWidget | ||
| text="Gumroad Totals" | ||
| style={{ fontSize: 15, fontFamily: "ABCFavorit-Bold-custom", fontWeight: "bold", color: "#ffffff" }} | ||
| /> | ||
| </FlexWidget> | ||
| <FlexWidget style={{ height: 16 }} /> | ||
| <FlexWidget style={{ flexDirection: "column", flexGap: 8, width: "match_parent" }}> | ||
| <RevenueRow label="Today" value={today} /> | ||
| <RevenueRow label="Week" value={week} /> | ||
| <RevenueRow label="Month" value={month} /> | ||
| <RevenueRow label="Year" value={year} /> | ||
| </FlexWidget> | ||
| <FlexWidget style={{ flex: 1 }} /> | ||
| </FlexWidget> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import { HStack, Spacer, Text, VStack } from "@expo/ui/swift-ui"; | ||
| import { | ||
| bold, | ||
| font, | ||
| foregroundStyle, | ||
| frame, | ||
| lineSpacing, | ||
| multilineTextAlignment, | ||
| padding, | ||
| } from "@expo/ui/swift-ui/modifiers"; | ||
| import { createWidget, type WidgetEnvironment } from "expo-widgets"; | ||
|
|
||
| type RevenueWidgetProps = { | ||
| today: string; | ||
| week: string; | ||
| month: string; | ||
| year: string; | ||
| isLoggedIn: boolean; | ||
| hasError: boolean; | ||
| }; | ||
|
|
||
| const RevenueWidget = (props: RevenueWidgetProps, _environment: WidgetEnvironment) => { | ||
| "widget"; | ||
|
|
||
| if (!props.isLoggedIn) { | ||
| return ( | ||
| <VStack modifiers={[padding()]}> | ||
| <HStack spacing={4} alignment="center"> | ||
| <Text | ||
| modifiers={[ | ||
| font({ size: 13 }), | ||
| bold(), | ||
| foregroundStyle({ type: "hierarchical", style: "primary" }), | ||
| multilineTextAlignment("center"), | ||
| lineSpacing(4), | ||
| ]} | ||
| > | ||
| Open Gumroad to log in | ||
| </Text> | ||
| </HStack> | ||
| </VStack> | ||
| ); | ||
| } | ||
|
|
||
| if (props.hasError) { | ||
| return ( | ||
| <VStack alignment="center" modifiers={[padding({ all: 16 })]}> | ||
| <Spacer /> | ||
| <Text | ||
| modifiers={[ | ||
| font({ size: 13 }), | ||
| bold(), | ||
| foregroundStyle({ type: "hierarchical", style: "primary" }), | ||
| multilineTextAlignment("center"), | ||
| lineSpacing(4), | ||
| ]} | ||
| > | ||
| Sorry, something went wrong. Try again later. | ||
| </Text> | ||
| <Spacer /> | ||
| </VStack> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <VStack alignment="leading" modifiers={[padding({ vertical: 16, horizontal: 14 })]} spacing={8}> | ||
| <Spacer /> | ||
| <HStack spacing={5} alignment="center"> | ||
| <Text modifiers={[font({ size: 15 }), bold(), foregroundStyle({ type: "hierarchical", style: "primary" })]}> | ||
| Gumroad Totals | ||
| </Text> | ||
| </HStack> | ||
| <Spacer modifiers={[frame({ height: 1 })]} /> | ||
|
|
||
| <HStack> | ||
| <Text modifiers={[font({ size: 13 }), foregroundStyle({ type: "hierarchical", style: "primary" })]}>Today</Text> | ||
| <Spacer /> | ||
| <Text modifiers={[font({ size: 13 }), bold(), foregroundStyle({ type: "hierarchical", style: "primary" })]}> | ||
| {props.today} | ||
| </Text> | ||
| </HStack> | ||
|
|
||
| <HStack> | ||
| <Text modifiers={[font({ size: 13 }), foregroundStyle({ type: "hierarchical", style: "primary" })]}>Week</Text> | ||
| <Spacer /> | ||
| <Text modifiers={[font({ size: 13 }), bold(), foregroundStyle({ type: "hierarchical", style: "primary" })]}> | ||
| {props.week} | ||
| </Text> | ||
| </HStack> | ||
|
|
||
| <HStack> | ||
| <Text modifiers={[font({ size: 13 }), foregroundStyle({ type: "hierarchical", style: "primary" })]}>Month</Text> | ||
| <Spacer /> | ||
| <Text modifiers={[font({ size: 13 }), bold(), foregroundStyle({ type: "hierarchical", style: "primary" })]}> | ||
| {props.month} | ||
| </Text> | ||
| </HStack> | ||
|
|
||
| <HStack> | ||
| <Text modifiers={[font({ size: 13 }), foregroundStyle({ type: "hierarchical", style: "primary" })]}>Year</Text> | ||
| <Spacer /> | ||
| <Text modifiers={[font({ size: 13 }), bold(), foregroundStyle({ type: "hierarchical", style: "primary" })]}> | ||
| {props.year} | ||
| </Text> | ||
| </HStack> | ||
| <Spacer /> | ||
| </VStack> | ||
| ); | ||
| }; | ||
|
|
||
| export default createWidget("RevenueWidget", RevenueWidget); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The iOS widget seems to break if we extract a component for this