-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwatchapps.tsx
More file actions
152 lines (147 loc) · 4.77 KB
/
Copy pathwatchapps.tsx
File metadata and controls
152 lines (147 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { NavLink, Link } from 'react-router';
import Carousel from "../components/carousel";
import AppCard from "../components/app_card";
import { mergeMeta } from "../utils/meta"
import type { Route } from './+types/watchapps';
import type { CollectionOverview } from '~/types/AppstoreApi';
/**
* Runs before page load and populates loaderData
*/
export async function loader({ params }: Route.LoaderArgs) {
const res = await fetch(`https://appstore-api.rebble.io/api/v1/home/apps`);
const watchapps = await res.json();
return watchapps as CollectionOverview;
}
export const handle = {
type: () => 'watchapp',
};
export const meta: Route.MetaFunction = ({ matches }) => mergeMeta(matches, [
{ title: "Watch apps | Rebble Appstore" },
{ name: "og:title", content: "Watch apps" },
{ name: "og:description", content: "Browse the watch apps on the Rebble Appstore" },
]);
export default function Watchapps({
loaderData,
}: Route.ComponentProps) {
const applicationLink = (applicationId: string) => {
return `/application/${applicationId}`;
};
const applicationById = (applicationId: string) => {
return loaderData.applications.find((application) => application.id == applicationId);
};
return (
<div className="home-page">
{loaderData.banners.length > 0 &&
<Carousel>
{loaderData.banners.map((banner) => {
return (
<NavLink to={applicationLink(banner.application_id)} key={banner.application_id}>
<img draggable="false" className="banner" src={banner.image['720x320']} />
</NavLink>
);
})}
</Carousel>
}
<div className="categories">
{loaderData.categories.map((category) => {
return (
<NavLink to={`/category/${category.slug}`} key={category.slug} style={{ backgroundColor: `rgb(from #${category.color} r g b / 50%)` }}>
<img src={category.icon['88x88']} />
{category.name}
</NavLink>
);
})}
</div>
{loaderData.collections.map((collection) => {
return (
<div className="collection" key={collection.slug}>
<div className="name">
<NavLink to={`/collection/${collection.slug}/apps/1`}>
<h2>{collection.name}</h2>
<span>See more</span>
</NavLink>
</div>
<div className="apps">
{collection.application_ids.slice(0, 6).map((applicationId) => {
const application = applicationById(applicationId);
if(!application) {
console.warn(`Application ${applicationId} was in collection.application_ids but as not found in known applications!`)
return <></>
}
return <AppCard info={application} key={applicationId} />
})}
</div>
</div>
);
})}
<style>{`
.home-page {
}
.home-page .banner {
border-radius: 2rem;
width: 100%;
}
.home-page .categories {
display: grid;
gap: 2rem;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr
}
.home-page .categories a {
display: flex;
flex-direction: column;
align-items: center;
justify-items: center;
gap: 1rem;
padding: 2rem 1rem;
border-radius: 2rem;
color: var(--as-fg-primary);
font-weight: 600;
text-decoration: none;
text-align: center;
}
.home-page .collection {
display: flex;
flex-direction: column;
gap: 1rem;
background: var(--as-bg-secondary);
padding: 2rem;
border-radius: 2rem;
margin-top: 2rem;
}
.home-page .collection .name a {
display: flex;
justify-content: space-between;
align-items: center;
text-decoration: none;
}
.home-page .collection .name a h2 {
margin: 0;
color: var(--as-fg-primary)
}
.home-page .collection .apps {
display: grid;
gap: 2rem;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr;
}
@media(max-width: 1200px) {
.home-page .categories {
grid-template-columns: 1fr 1fr 1fr
}
.home-page .collection .apps {
grid-template-columns: 1fr 1fr 1fr
}
}
@media(max-width: 800px) {
.home-page .categories {
grid-template-columns: 1fr 1fr
}
}
@media(max-width: 600px) {
.home-page .collection .apps {
grid-template-columns: 1fr 1fr
}
}
`}</style>
</div>
);
}