diff --git a/app/components/page-layout.tsx b/app/components/page-layout.tsx
index 6eaa191..5076166 100644
--- a/app/components/page-layout.tsx
+++ b/app/components/page-layout.tsx
@@ -46,6 +46,9 @@ export function PageLayout({ children }: PageLayoutProps) {
Listen
+
+ Home
+
Music
diff --git a/app/components/station-player.tsx b/app/components/station-player.tsx
index 1542925..fb095b6 100644
--- a/app/components/station-player.tsx
+++ b/app/components/station-player.tsx
@@ -1,8 +1,7 @@
-import type { StationWithTags } from "~/models/station.server";
-import type { ConvertDatesToStrings } from "~/utils";
+import type { StationWithTagsClientSide } from "~/models/station.server";
export type StationPlayerProps = {
- station: ConvertDatesToStrings>
+ station: StationWithTagsClientSide
};
export function StationPlayer({ station }: StationPlayerProps) {
diff --git a/app/components/stations-gallery.tsx b/app/components/stations-gallery.tsx
index 5d2fc4e..40ea4da 100644
--- a/app/components/stations-gallery.tsx
+++ b/app/components/stations-gallery.tsx
@@ -1,11 +1,11 @@
import type { Tag } from "@prisma/client";
import { Link } from "@remix-run/react";
-import type { StationWithTags } from "~/models/station.server";
+import type { StationWithTagsClientSide } from "~/models/station.server";
import type { Channel } from "~/routes/listen.channel.$channel";
import type { ConvertDatesToStrings } from "~/utils";
export type StationsGalleryProps = {
- stations: ConvertDatesToStrings>[];
+ stations: StationWithTagsClientSide[];
tag?: ConvertDatesToStrings;
channel?: ConvertDatesToStrings;
};
@@ -19,7 +19,7 @@ export function StationsGallery({ stations, tag, channel }: StationsGalleryProps
if (tag) {
return `/listen/tag/${tag?.slug}/${id}`;
}
- return `/listen/station/${id}`;
+ return `/listen/home/${id}`;
}
return (
diff --git a/app/models/station.server.ts b/app/models/station.server.ts
index 219bdd5..a1937ef 100644
--- a/app/models/station.server.ts
+++ b/app/models/station.server.ts
@@ -1,6 +1,7 @@
import type { Prisma, PrismaClient, Station, Tag } from "@prisma/client";
import { prisma } from "~/db.server";
import { upsertTagOnName } from "~/models/tag.server";
+import type { ConvertDatesToStrings } from "~/utils";
import { slugify } from "~/utils";
export type StationInput = {
@@ -16,9 +17,27 @@ export type StationInput = {
export type PrismaTxClient = Omit;
-export function findStationsByTags(tags: string[]) {
+export function getStations(reliability: number = 80) {
+ return prisma.station.findMany({
+ where: { reliability: { gte: reliability } },
+ include: {
+ tags: {
+ include: {
+ tag: true
+ }
+ }
+ },
+ orderBy: [
+ { popularity: "desc" }
+ ]
+ });
+}
+
+
+export function findStationsByTags(tags: string[], reliability: number = 80) {
return prisma.station.findMany({
where: {
+ reliability: { gte: reliability },
tags: {
some: {
tag: {
@@ -33,11 +52,15 @@ export function findStationsByTags(tags: string[]) {
tag: true
}
}
- }
+ },
+ orderBy: [
+ { popularity: "desc" }
+ ]
});
}
-export type StationWithTags = Prisma.PromiseReturnType;
+export type StationWithTags = NonNullable>;
+export type StationWithTagsClientSide = ConvertDatesToStrings;
export function getStationById(id: string) {
return prisma.station.findUnique({
diff --git a/app/routes/listen._index.tsx b/app/routes/listen._index.tsx
deleted file mode 100644
index 63509f6..0000000
--- a/app/routes/listen._index.tsx
+++ /dev/null
@@ -1,13 +0,0 @@
-import { Link } from "@remix-run/react";
-import { Breadcrumbs } from "~/components/breadcrumbs";
-
-export default function ListenHome() {
- return (
- <>
-
- Home
-
- >
- );
-
-}
diff --git a/app/routes/listen.channel.$channel.tsx b/app/routes/listen.channel.$channel.tsx
index 3ba0e25..42d83ce 100644
--- a/app/routes/listen.channel.$channel.tsx
+++ b/app/routes/listen.channel.$channel.tsx
@@ -38,7 +38,7 @@ export async function loader({ params }: LoaderArgs) {
throw notFound();
}
- const stations: NonNullable[] = await findStationsByTags(channel.tags);
+ const stations: StationWithTags[] = await findStationsByTags(channel.tags);
return json({ channel, stations });
}
diff --git a/app/routes/listen.home.$station.tsx b/app/routes/listen.home.$station.tsx
new file mode 100644
index 0000000..cd545d9
--- /dev/null
+++ b/app/routes/listen.home.$station.tsx
@@ -0,0 +1,4 @@
+import ListenChanelStation from "~/routes/listen.channel.$channel.$station";
+
+export { loader } from "~/routes/listen.channel.$channel.$station";
+export default ListenChanelStation;
diff --git a/app/routes/listen.home.tsx b/app/routes/listen.home.tsx
new file mode 100644
index 0000000..b1e93f2
--- /dev/null
+++ b/app/routes/listen.home.tsx
@@ -0,0 +1,27 @@
+import { json } from "@remix-run/node";
+import { Link, Outlet, useLoaderData } from "@remix-run/react";
+import { Breadcrumbs } from "~/components/breadcrumbs";
+import { StationsGallery } from "~/components/stations-gallery";
+import type { StationWithTags } from "~/models/station.server";
+import { getStations } from "~/models/station.server";
+
+
+export async function loader() {
+ const stations: StationWithTags[] = await getStations();
+ return json({ stations });
+}
+
+export default function ListenHome() {
+ const { stations } = useLoaderData();
+
+ return (
+ <>
+
+ Home
+
+
+
+ >
+ );
+
+}
diff --git a/app/routes/listen.tag.$tag.tsx b/app/routes/listen.tag.$tag.tsx
index 53c7948..f36b7f3 100644
--- a/app/routes/listen.tag.$tag.tsx
+++ b/app/routes/listen.tag.$tag.tsx
@@ -19,7 +19,7 @@ export async function loader({ params }: LoaderArgs) {
throw notFound();
}
- const stations: NonNullable[] = await findStationsByTags([tag.name]);
+ const stations: StationWithTags[] = await findStationsByTags([tag.name]);
return json({ tag, stations });