Skip to content

Commit 4c3db68

Browse files
committed
Rename donations components and logic to recent coffees
- rename 'donations' to 'recent coffees' - rename 'lastest coffees' to 'recent coffees'
1 parent eda48ef commit 4c3db68

9 files changed

Lines changed: 79 additions & 90 deletions

File tree

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import { LayoutContext } from './contexts/LayoutContext'
2121
import { ResponseHistoryItem } from '@shared/types/response-history-item'
2222
import { Layout } from './components/Layout/Layout'
2323
import { ResponsePreviewFooter as UiResponsePreviewFooter } from '@ui/components/editor/panel/ResponsePreviewFooter'
24-
import { Donations as UiDonations } from '@ui/components/editor/panel/Donations/Donations'
25-
import { use_latest_donations } from './hooks/latest-donations'
26-
import { DonationsFooter } from './components/donations/DonationsFooter'
24+
import { RecentCoffees as UiRecentCoffees } from '@ui/components/editor/panel/RecentCoffees/RecentCoffees'
25+
import { use_recent_coffees } from './hooks/recent-coffees'
26+
import { RecentCoffeesFooter } from './components/recent-coffees/RecentCoffeesFooter'
2727
import { IconButton as UiIconButton } from '@ui/components/editor/common/IconButton'
2828
import { use_modal_manager } from './hooks/use-modal-manager'
2929
import { use_response_history } from './hooks/panel/use-response-history'
@@ -152,8 +152,8 @@ export const Panel = () => {
152152
address: string
153153
}>()
154154

155-
const { viewing_donations, set_viewing_donations, ...donations_state } =
156-
use_latest_donations()
155+
const { viewing_coffees, set_viewing_coffees, ...coffees_state } =
156+
use_recent_coffees()
157157

158158
if (
159159
ask_about_context_instructions === undefined ||
@@ -500,7 +500,7 @@ export const Panel = () => {
500500
}}
501501
on_task_forward={handle_task_forward}
502502
is_setup_complete={is_setup_complete}
503-
on_donate_click={() => set_viewing_donations(true)}
503+
on_donate_click={() => set_viewing_coffees(true)}
504504
/>
505505
</div>
506506
</Layout>
@@ -593,23 +593,23 @@ export const Panel = () => {
593593
</div>
594594
)}
595595

596-
{viewing_donations && (
596+
{viewing_coffees && (
597597
<div className={styles.slot}>
598598
<UiPage
599-
title="Donations"
600-
on_back_click={() => set_viewing_donations(false)}
599+
title="Recent Coffees"
600+
on_back_click={() => set_viewing_coffees(false)}
601601
footer_slot={
602-
<DonationsFooter
603-
on_close={() => set_viewing_donations(false)}
602+
<RecentCoffeesFooter
603+
on_close={() => set_viewing_coffees(false)}
604604
/>
605605
}
606606
>
607-
<UiDonations
608-
donations={donations_state.donations}
609-
is_fetching={donations_state.is_fetching}
610-
is_revalidating={donations_state.is_revalidating}
611-
on_fetch_next_page={donations_state.on_fetch_next_page}
612-
has_more={donations_state.has_more}
607+
<UiRecentCoffees
608+
coffees={coffees_state.coffees}
609+
is_fetching={coffees_state.is_fetching}
610+
is_revalidating={coffees_state.is_revalidating}
611+
on_fetch_next_page={coffees_state.on_fetch_next_page}
612+
has_more={coffees_state.has_more}
613613
on_show_qr_code={set_active_qr_wallet}
614614
/>
615615
</UiPage>

‎apps/editor/src/views/panel/frontend/components/donations/DonationsFooter/index.ts‎

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

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

File renamed without changes.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ 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 './DonationsFooter.module.scss'
5+
import styles from './RecentCoffeesFooter.module.scss'
66

77
type Props = {
88
on_close: () => void
99
}
1010

11-
export const DonationsFooter: React.FC<Props> = (props) => {
11+
export const RecentCoffeesFooter: React.FC<Props> = (props) => {
1212
const { container_ref, compact_step, report_width } = use_compacting(2)
1313
const close_ref = useRef<HTMLSpanElement>(null)
1414
const coffee_ref = useRef<HTMLSpanElement>(null)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './RecentCoffeesFooter'

apps/editor/src/views/panel/frontend/hooks/latest-donations.ts renamed to apps/editor/src/views/panel/frontend/hooks/recent-coffees.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 Donation = {
4+
type Coffee = {
55
support_message: string
66
support_note: string
77
}
88

9-
export const use_latest_donations = () => {
10-
const [viewing_donations, set_viewing_donations] = useState(false)
11-
const [donations, set_donations] = useState<Donation[]>([])
9+
export const use_recent_coffees = () => {
10+
const [viewing_coffees, set_viewing_coffees] = useState(false)
11+
const [coffees, set_coffees] = useState<Coffee[]>([])
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_donations = useRef<Donation[]>([])
18+
const cached_coffees = useRef<Coffee[]>([])
1919

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

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

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

42-
if (new_donations.length < 10) {
42+
if (new_coffees.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 donations', error)
49+
console.error('Failed to fetch coffees', error)
5050
} finally {
5151
if (is_revalidation) {
5252
set_is_revalidating(false)
@@ -58,23 +58,23 @@ export const use_latest_donations = () => {
5858
}, [])
5959

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

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

7979
const on_fetch_next_page = useCallback(async () => {
8080
if (
@@ -92,26 +92,26 @@ export const use_latest_donations = () => {
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_donations = response.data.data.map((raw: any) => ({
95+
const new_coffees = response.data.data.map((raw: any) => ({
9696
support_message: raw.support_message,
9797
support_note: raw.support_note ?? ''
9898
}))
99-
if (new_donations.length > 0) {
100-
set_donations((prev) => {
101-
const updated = [...prev, ...new_donations]
102-
cached_donations.current = updated
99+
if (new_coffees.length > 0) {
100+
set_coffees((prev) => {
101+
const updated = [...prev, ...new_coffees]
102+
cached_coffees.current = updated
103103
return updated
104104
})
105105
set_page((prev) => prev + 1)
106106
}
107-
if (new_donations.length < 10) {
107+
if (new_coffees.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 donations', error)
114+
console.error('Failed to fetch coffees', error)
115115
set_has_more(false)
116116
} finally {
117117
set_is_fetching_next(false)
@@ -126,12 +126,12 @@ export const use_latest_donations = () => {
126126
])
127127

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

packages/ui/src/components/editor/panel/Donations/Donations.module.scss renamed to packages/ui/src/components/editor/panel/RecentCoffees/RecentCoffees.module.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@
8484
}
8585
}
8686

87-
.donations {
87+
.coffees {
8888
padding: 4px 12px 12px 12px;
8989
}
9090

91-
.donations__inner {
91+
.coffees__inner {
9292
display: flex;
9393
flex-direction: column;
9494
gap: 8px;
@@ -97,7 +97,7 @@
9797
opacity: var(--dimmed-opacity);
9898
}
9999

100-
&__donation {
100+
&__coffee {
101101
display: flex;
102102
flex-direction: column;
103103
gap: 4px;

packages/ui/src/components/editor/panel/Donations/Donations.stories.tsx renamed to packages/ui/src/components/editor/panel/RecentCoffees/RecentCoffees.stories.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Donations, DonationsProps } from './Donations'
1+
import { RecentCoffees, RecentCoffeesProps } from './RecentCoffees'
22

33
export default {
4-
component: Donations
4+
component: RecentCoffees
55
}
66

7-
const sample_donations: DonationsProps['donations'] = [
7+
const sample_coffees: RecentCoffeesProps['coffees'] = [
88
{
99
support_message:
1010
'<span class="suppUsername"><a href="https://github.com/johndoe">JohnDoe</a></span> bought 2 coffees.',
@@ -22,8 +22,8 @@ const sample_donations: DonationsProps['donations'] = [
2222

2323
export const Default = () => {
2424
return (
25-
<Donations
26-
donations={sample_donations}
25+
<RecentCoffees
26+
coffees={sample_coffees}
2727
is_fetching={false}
2828
on_show_qr_code={(wallet) => console.log('Show QR code', wallet)}
2929
is_revalidating={false}
@@ -35,7 +35,7 @@ export const Default = () => {
3535

3636
export const Loading = () => {
3737
return (
38-
<Donations
38+
<RecentCoffees
3939
is_fetching={true}
4040
on_show_qr_code={(wallet) => console.log('Show QR code', wallet)}
4141
is_revalidating={false}
@@ -47,8 +47,8 @@ export const Loading = () => {
4747

4848
export const Revalidating = () => {
4949
return (
50-
<Donations
51-
donations={sample_donations}
50+
<RecentCoffees
51+
coffees={sample_coffees}
5252
on_show_qr_code={(wallet) => console.log('Show QR code', wallet)}
5353
is_fetching={false}
5454
is_revalidating={true}

0 commit comments

Comments
 (0)