Skip to content

Commit 17a67cd

Browse files
committed
Rename recent coffees to recent donations and add internationalization support
- translate [Fragment]
1 parent 11a4d0f commit 17a67cd

13 files changed

Lines changed: 246 additions & 92 deletions

File tree

‎apps/editor/src/views/panel/frontend/Home/Home.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export const Home: React.FC<Props> = (props) => {
9393
<span className={styles['header__text']}>{t('header.home')}</span>
9494
</div>
9595
<UiDonateButton
96-
label="Buy Me A Coffee"
96+
label={t('recent-donations.buy-me-a-coffee')}
9797
on_click={props.on_donate_click}
9898
/>
9999
</div>

‎apps/editor/src/views/panel/frontend/Panel.tsx‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import { LayoutContext } from './contexts/LayoutContext'
2020
import { ResponseHistoryItem } from '@shared/types/response-history-item'
2121
import { Layout } from './components/Layout/Layout'
2222
import { ResponsePreviewFooter as UiResponsePreviewFooter } from '@ui/components/editor/panel/ResponsePreviewFooter'
23-
import { RecentCoffees as UiRecentCoffees } from '@ui/components/editor/panel/RecentCoffees/RecentCoffees'
24-
import { use_recent_coffees } from './hooks/recent-coffees'
25-
import { RecentCoffeesFooter } from './components/recent-coffees/RecentCoffeesFooter'
23+
import { RecentDonations as UiRecentDonations } from '@ui/components/editor/panel/RecentDonations/RecentDonations'
24+
import { use_recent_donations } from './hooks/recent-donations'
25+
import { RecentDonationsFooter } from './components/recent-donations/RecentDonationsFooter'
2626
import { IconButton as UiIconButton } from '@ui/components/editor/common/IconButton'
2727
import { use_modal_manager } from './hooks/use-modal-manager'
2828
import { use_response_history } from './hooks/panel/use-response-history'
@@ -31,10 +31,12 @@ import { use_editor_sync } from './hooks/panel/use-editor-sync'
3131
import { use_web_configuration_editing } from './hooks/panel/use-web-configuration-editing'
3232
import { use_api_configuration_editing } from './hooks/panel/use-api-configuration-editing'
3333
import { EditApiConfigurationForm } from '@/views/shared/forms/EditApiConfigurationForm'
34+
import { use_translation } from './i18n/use-translation'
3435

3536
const vscode = acquireVsCodeApi()
3637

3738
export const Panel = () => {
39+
const { t } = use_translation()
3840
const {
3941
active_view,
4042
set_active_view,
@@ -147,8 +149,8 @@ export const Panel = () => {
147149
address: string
148150
}>()
149151

150-
const { viewing_coffees, set_viewing_coffees, ...coffees_state } =
151-
use_recent_coffees()
152+
const { viewing_donations, set_viewing_donations, ...donations_state } =
153+
use_recent_donations()
152154

153155
if (
154156
ask_about_context_instructions === undefined ||
@@ -462,7 +464,7 @@ export const Panel = () => {
462464
}
463465
on_task_forward={handle_task_forward}
464466
is_setup_complete={is_setup_complete}
465-
on_donate_click={() => set_viewing_coffees(true)}
467+
on_donate_click={() => set_viewing_donations(true)}
466468
/>
467469
</div>
468470
</Layout>
@@ -555,24 +557,30 @@ export const Panel = () => {
555557
</div>
556558
)}
557559

558-
{viewing_coffees && (
560+
{viewing_donations && (
559561
<div className={styles.slot}>
560562
<UiPage
561-
title="Recent Coffees"
562-
on_back_click={() => set_viewing_coffees(false)}
563+
title={t('recent-donations.title')}
564+
on_back_click={() => set_viewing_donations(false)}
563565
footer_slot={
564-
<RecentCoffeesFooter
565-
on_close={() => set_viewing_coffees(false)}
566+
<RecentDonationsFooter
567+
on_close={() => set_viewing_donations(false)}
566568
/>
567569
}
568570
>
569-
<UiRecentCoffees
570-
coffees={coffees_state.coffees}
571-
is_fetching={coffees_state.is_fetching}
572-
is_revalidating={coffees_state.is_revalidating}
573-
on_fetch_next_page={coffees_state.on_fetch_next_page}
574-
has_more={coffees_state.has_more}
571+
<UiRecentDonations
572+
donations={donations_state.donations}
573+
is_fetching={donations_state.is_fetching}
574+
is_revalidating={donations_state.is_revalidating}
575+
on_fetch_next_page={donations_state.on_fetch_next_page}
576+
has_more={donations_state.has_more}
575577
on_show_qr_code={set_active_qr_wallet}
578+
translations={{
579+
about: t('recent-donations.about'),
580+
platforms: t('recent-donations.platforms'),
581+
wallets: t('recent-donations.wallets'),
582+
scan_qr: t('recent-donations.scan-qr')
583+
}}
576584
/>
577585
</UiPage>
578586
</div>

‎apps/editor/src/views/panel/frontend/components/recent-coffees/RecentCoffeesFooter/index.ts‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

apps/editor/src/views/panel/frontend/components/recent-coffees/RecentCoffeesFooter/RecentCoffeesFooter.module.scss renamed to apps/editor/src/views/panel/frontend/components/recent-donations/RecentDonationsFooter/RecentDonationsFooter.module.scss

File renamed without changes.

apps/editor/src/views/panel/frontend/components/recent-coffees/RecentCoffeesFooter/RecentCoffeesFooter.tsx renamed to apps/editor/src/views/panel/frontend/components/recent-donations/RecentDonationsFooter/RecentDonationsFooter.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@ import { useRef, useLayoutEffect } from 'react'
22
import cn from 'classnames'
33
import { use_compacting } from '@shared/hooks'
44
import { Button as UiButton } from '@ui/components/editor/common/Button'
5-
import styles from './RecentCoffeesFooter.module.scss'
5+
import styles from './RecentDonationsFooter.module.scss'
6+
import { use_translation } from '../../../i18n/use-translation'
67

78
type Props = {
89
on_close: () => void
910
}
1011

11-
export const RecentCoffeesFooter: React.FC<Props> = (props) => {
12+
export const RecentDonationsFooter: React.FC<Props> = (props) => {
13+
const { t } = use_translation()
1214
const { container_ref, compact_step, report_width } = use_compacting(2)
1315
const close_ref = useRef<HTMLSpanElement>(null)
14-
const coffee_ref = useRef<HTMLSpanElement>(null)
16+
const donation_ref = useRef<HTMLSpanElement>(null)
1517

1618
useLayoutEffect(() => {
17-
if (close_ref.current && coffee_ref.current) {
19+
if (close_ref.current && donation_ref.current) {
1820
const padding_and_gap = 2 * 24 + 8
1921
const width =
2022
close_ref.current.getBoundingClientRect().width +
21-
coffee_ref.current.getBoundingClientRect().width +
23+
donation_ref.current.getBoundingClientRect().width +
2224
padding_and_gap
2325
report_width(width, compact_step)
2426
}
@@ -28,7 +30,7 @@ export const RecentCoffeesFooter: React.FC<Props> = (props) => {
2830
<div className={styles.container} ref={container_ref}>
2931
<UiButton on_click={props.on_close} is_secondary>
3032
<span className={styles['button-content']} ref={close_ref}>
31-
{compact_step < 1 && 'Close'}
33+
{compact_step < 1 && t('recent-donations.close')}
3234
{compact_step >= 1 && (
3335
<span className={cn('codicon', 'codicon-chevron-left')} />
3436
)}
@@ -38,8 +40,8 @@ export const RecentCoffeesFooter: React.FC<Props> = (props) => {
3840
url="https://buymeacoffee.com/robertpiosik"
3941
title="buymeacoffee.com/robertpiosik"
4042
>
41-
<span className={styles['button-content']} ref={coffee_ref}>
42-
{compact_step < 2 && 'Buy Me A Coffee ↗'}
43+
<span className={styles['button-content']} ref={donation_ref}>
44+
{compact_step < 2 && `${t('recent-donations.buy-me-a-coffee')} ↗`}
4345
{compact_step >= 2 && (
4446
<span className={cn('codicon', 'codicon-coffee')} />
4547
)}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './RecentDonationsFooter'

apps/editor/src/views/panel/frontend/hooks/recent-coffees.ts renamed to apps/editor/src/views/panel/frontend/hooks/recent-donations.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { useCallback, useEffect, useState, useRef } from 'react'
22
import axios from 'axios'
33

4-
type Coffee = {
4+
type Donation = {
55
support_message: string
66
support_note: string
77
}
88

9-
export const use_recent_coffees = () => {
10-
const [viewing_coffees, set_viewing_coffees] = useState(false)
11-
const [coffees, set_coffees] = useState<Coffee[]>([])
9+
export const use_recent_donations = () => {
10+
const [viewing_donations, set_viewing_donations] = useState(false)
11+
const [donations, set_donations] = useState<Donation[]>([])
1212
const [is_fetching, set_is_fetching] = useState(false)
1313
const [is_revalidating, set_is_revalidating] = useState(false)
1414
const [fetched_once, set_fetched_once] = useState(false)
1515
const [page, set_page] = useState(1)
1616
const [is_fetching_next, set_is_fetching_next] = useState(false)
1717
const [has_more, set_has_more] = useState(true)
18-
const cached_coffees = useRef<Coffee[]>([])
18+
const cached_donations = useRef<Donation[]>([])
1919

20-
const fetch_coffees = useCallback(async (is_revalidation = false) => {
20+
const fetch_donations = useCallback(async (is_revalidation = false) => {
2121
try {
2222
if (is_revalidation) {
2323
set_is_revalidating(true)
@@ -30,23 +30,23 @@ export const use_recent_coffees = () => {
3030
)
3131

3232
if (response.data?.data) {
33-
const new_coffees = response.data.data.map((raw: any) => ({
33+
const new_donations = response.data.data.map((raw: any) => ({
3434
support_message: raw.support_message,
3535
support_note: raw.support_note ?? ''
3636
}))
3737

38-
set_coffees(new_coffees)
39-
cached_coffees.current = new_coffees
38+
set_donations(new_donations)
39+
cached_donations.current = new_donations
4040
set_page(2)
4141

42-
if (new_coffees.length < 10) {
42+
if (new_donations.length < 10) {
4343
set_has_more(false)
4444
} else {
4545
set_has_more(true)
4646
}
4747
}
4848
} catch (error) {
49-
console.error('Failed to fetch coffees', error)
49+
console.error('Failed to fetch donations', error)
5050
} finally {
5151
if (is_revalidation) {
5252
set_is_revalidating(false)
@@ -58,23 +58,23 @@ export const use_recent_coffees = () => {
5858
}, [])
5959

6060
useEffect(() => {
61-
if (!viewing_coffees) {
61+
if (!viewing_donations) {
6262
set_page(1)
6363
set_has_more(true)
6464
return
6565
}
6666

6767
// Stale-while-revalidate strategy
68-
if (fetched_once && cached_coffees.current.length > 0) {
68+
if (fetched_once && cached_donations.current.length > 0) {
6969
// Show stale data immediately
70-
set_coffees(cached_coffees.current)
70+
set_donations(cached_donations.current)
7171
// Then revalidate in background
72-
fetch_coffees(true)
72+
fetch_donations(true)
7373
} else {
7474
// First time fetch
75-
fetch_coffees(false)
75+
fetch_donations(false)
7676
}
77-
}, [viewing_coffees, fetch_coffees])
77+
}, [viewing_donations, fetch_donations])
7878

7979
const on_fetch_next_page = useCallback(async () => {
8080
if (
@@ -92,26 +92,26 @@ export const use_recent_coffees = () => {
9292
`https://app.buymeacoffee.com/api/creators/slug/robertpiosik/coffees?web=1&page=${page}&per_page=10`
9393
)
9494
if (response.data?.data) {
95-
const new_coffees = response.data.data.map((raw: any) => ({
95+
const new_donations = response.data.data.map((raw: any) => ({
9696
support_message: raw.support_message,
9797
support_note: raw.support_note ?? ''
9898
}))
99-
if (new_coffees.length > 0) {
100-
set_coffees((prev) => {
101-
const updated = [...prev, ...new_coffees]
102-
cached_coffees.current = updated
99+
if (new_donations.length > 0) {
100+
set_donations((prev) => {
101+
const updated = [...prev, ...new_donations]
102+
cached_donations.current = updated
103103
return updated
104104
})
105105
set_page((prev) => prev + 1)
106106
}
107-
if (new_coffees.length < 10) {
107+
if (new_donations.length < 10) {
108108
set_has_more(false)
109109
}
110110
} else {
111111
set_has_more(false)
112112
}
113113
} catch (error) {
114-
console.error('Failed to fetch coffees', error)
114+
console.error('Failed to fetch donations', error)
115115
set_has_more(false)
116116
} finally {
117117
set_is_fetching_next(false)
@@ -126,12 +126,12 @@ export const use_recent_coffees = () => {
126126
])
127127

128128
return {
129-
viewing_coffees,
130-
set_viewing_coffees,
131-
coffees,
129+
viewing_donations,
130+
set_viewing_donations,
131+
donations,
132132
is_fetching,
133133
is_revalidating,
134-
coffees_fetched_once: fetched_once,
134+
donations_fetched_once: fetched_once,
135135
on_fetch_next_page,
136136
has_more
137137
}

‎apps/editor/src/views/panel/frontend/i18n/translations/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { home } from './home'
33
import { configurations } from './configurations'
44
import { actions } from './actions'
55
import { prompt_field } from './prompt-field'
6+
import { recent_donations } from './recent-donations'
67

78
export const translations = {
89
...header,
910
...home,
1011
...configurations,
1112
...actions,
12-
...prompt_field
13+
...prompt_field,
14+
...recent_donations
1315
}

0 commit comments

Comments
 (0)