From b329c3c7b67357d86e36e64b5dc8e43cff0a06b2 Mon Sep 17 00:00:00 2001 From: Skander Mzali Date: Wed, 26 Jul 2023 15:09:37 -0700 Subject: [PATCH 01/12] Add longitudeLatitude field to feed - json of 'lng' and 'lat' to make it more explicit --- server/lib/orcasite/radio_legacy/radio_legacy.ex | 2 +- server/lib/orcasite_web/graphql/types/feed.ex | 10 ++++++++++ ui/src/components/Map.tsx | 4 ++-- ui/src/components/MapLayout.tsx | 2 +- ui/src/components/Player/Player.tsx | 2 +- ui/src/graphql/generated/index.ts | 5 +++++ ui/src/graphql/queries/getFeed.graphql | 1 + ui/src/graphql/queries/listFeeds.graphql | 1 + 8 files changed, 22 insertions(+), 5 deletions(-) diff --git a/server/lib/orcasite/radio_legacy/radio_legacy.ex b/server/lib/orcasite/radio_legacy/radio_legacy.ex index d593cf60..373224f0 100644 --- a/server/lib/orcasite/radio_legacy/radio_legacy.ex +++ b/server/lib/orcasite/radio_legacy/radio_legacy.ex @@ -5,7 +5,7 @@ defmodule Orcasite.RadioLegacy do import Ecto.Query, warn: false alias Orcasite.Repo - alias Orcasite.RadioLegacy.{Feed, Detection, Candidate} + alias Orcasite.RadioLegacy.{Detection, Candidate} def verify_can_submit_detection( feed_id, diff --git a/server/lib/orcasite_web/graphql/types/feed.ex b/server/lib/orcasite_web/graphql/types/feed.ex index 65b1a34c..1887d2fb 100644 --- a/server/lib/orcasite_web/graphql/types/feed.ex +++ b/server/lib/orcasite_web/graphql/types/feed.ex @@ -20,6 +20,16 @@ defmodule OrcasiteWeb.Types.Feed do end) end + field :longitude_latitude, non_null(:json) do + resolve(fn + %{location_point: %{coordinates: {lng, lat}}}, _, _ -> + {:ok, %{lng: lng, lat: lat}} + + _, _, _ -> + {:ok, %{}} + end) + end + field :thumb_url, non_null(:string) do resolve(fn %{node_name: node_name}, _, _ -> {:ok, feed_s3_url(node_name, "thumbnail.png")} diff --git a/ui/src/components/Map.tsx b/ui/src/components/Map.tsx index b6b71ce6..0fadb36c 100644 --- a/ui/src/components/Map.tsx +++ b/ui/src/components/Map.tsx @@ -17,7 +17,7 @@ export default function Map({ feeds, }: { setMap?: (map: LeafletMap) => void - currentFeed?: Pick + currentFeed?: Pick feeds: FeedsQuery['feeds'] }) { const router = useRouter() @@ -50,7 +50,7 @@ export default function Map({ {feeds.map((feed) => ( { if (feed && feed.slug !== currentFeed?.slug) { setCurrentFeed(feed) - map?.panTo(feed.locationPoint.coordinates) + map?.panTo(feed.longitudeLatitude) } }, [feed, map, currentFeed]) diff --git a/ui/src/components/Player/Player.tsx b/ui/src/components/Player/Player.tsx index 79044b67..8da0af66 100644 --- a/ui/src/components/Player/Player.tsx +++ b/ui/src/components/Player/Player.tsx @@ -153,7 +153,7 @@ export default function Player({ {currentFeed && - `${currentFeed.locationPoint.coordinates[0]}, ${currentFeed.locationPoint.coordinates[1]}`} + `${currentFeed.longitudeLatitude["lng"]}, ${currentFeed.longitudeLatitude["lat"]}`} ) diff --git a/ui/src/graphql/generated/index.ts b/ui/src/graphql/generated/index.ts index 6fd21982..f61d205d 100644 --- a/ui/src/graphql/generated/index.ts +++ b/ui/src/graphql/generated/index.ts @@ -105,6 +105,7 @@ export type Feed = { id: Scalars['ID']['output'] introHtml: Scalars['String']['output'] locationPoint: Scalars['Json']['output'] + longitudeLatitude: Scalars['Json']['output'] mapUrl: Scalars['String']['output'] name: Scalars['String']['output'] nodeName: Scalars['String']['output'] @@ -254,6 +255,7 @@ export type FeedQuery = { slug: string nodeName: string locationPoint: any + longitudeLatitude: any introHtml: string thumbUrl: string mapUrl: string @@ -271,6 +273,7 @@ export type FeedsQuery = { slug: string nodeName: string locationPoint: any + longitudeLatitude: any thumbUrl: string mapUrl: string }> @@ -335,6 +338,7 @@ export const FeedDocument = ` slug nodeName locationPoint + longitudeLatitude introHtml thumbUrl mapUrl @@ -363,6 +367,7 @@ export const FeedsDocument = ` slug nodeName locationPoint + longitudeLatitude thumbUrl mapUrl } diff --git a/ui/src/graphql/queries/getFeed.graphql b/ui/src/graphql/queries/getFeed.graphql index c4a27918..58af7627 100644 --- a/ui/src/graphql/queries/getFeed.graphql +++ b/ui/src/graphql/queries/getFeed.graphql @@ -5,6 +5,7 @@ query feed($slug: String!) { slug nodeName locationPoint + longitudeLatitude introHtml thumbUrl mapUrl diff --git a/ui/src/graphql/queries/listFeeds.graphql b/ui/src/graphql/queries/listFeeds.graphql index 8b786f04..64c4f300 100644 --- a/ui/src/graphql/queries/listFeeds.graphql +++ b/ui/src/graphql/queries/listFeeds.graphql @@ -5,6 +5,7 @@ query feeds { slug nodeName locationPoint + longitudeLatitude thumbUrl mapUrl } From c32e6fb296cf2986b19384e63b22472cb4f7d168 Mon Sep 17 00:00:00 2001 From: Skander Mzali Date: Wed, 26 Jul 2023 15:13:11 -0700 Subject: [PATCH 02/12] Fix small type error --- ui/src/components/MapLayout.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/src/components/MapLayout.tsx b/ui/src/components/MapLayout.tsx index 4b3feb41..c45fc57d 100644 --- a/ui/src/components/MapLayout.tsx +++ b/ui/src/components/MapLayout.tsx @@ -20,6 +20,7 @@ const feedFromSlug = (feedSlug: string) => ({ name: feedSlug, slug: feedSlug, nodeName: feedSlug, + longitudeLatitude: {lng: -122.3, lat: 47.6}, // TODO: figure out which coordinates to use for dynamic feeds locationPoint: { coordinates: [47.6, -122.3], From ea7373be22a57439e9ad9ccdf8a9bb3f888c6cdb Mon Sep 17 00:00:00 2001 From: Skander Mzali Date: Wed, 26 Jul 2023 17:57:05 -0700 Subject: [PATCH 03/12] Add longitudeLatitude to Player type --- ui/src/components/Player/Player.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/components/Player/Player.tsx b/ui/src/components/Player/Player.tsx index 8da0af66..c95e49f0 100644 --- a/ui/src/components/Player/Player.tsx +++ b/ui/src/components/Player/Player.tsx @@ -22,7 +22,7 @@ export default function Player({ }: { currentFeed?: Pick< Feed, - 'id' | 'slug' | 'nodeName' | 'name' | 'locationPoint' + 'id' | 'slug' | 'nodeName' | 'name' | 'locationPoint' | 'longitudeLatitude' > }) { const [playerStatus, setPlayerStatus] = useState('idle') From f15e23954db5c850e67e94bd2547b11f5944c936 Mon Sep 17 00:00:00 2001 From: Skander Mzali Date: Thu, 27 Jul 2023 15:14:59 -0700 Subject: [PATCH 04/12] Update variable name, seeds, and add admin account on seed --- server/assets_v2/src/queries/feeds.js | 1 - server/assets_v2/src/types/feedType.js | 1 - server/lib/orcasite/radio/feed.ex | 20 +++++++++---------- server/lib/orcasite_web/graphql/types/feed.ex | 12 +---------- server/priv/repo/seeds.exs | 18 ++++++++++++----- ui/src/components/Map.tsx | 4 ++-- ui/src/components/MapLayout.tsx | 8 ++------ ui/src/components/Player/Player.tsx | 4 ++-- ui/src/graphql/generated/index.ts | 15 +++++--------- ui/src/graphql/queries/getFeed.graphql | 3 +-- ui/src/graphql/queries/listFeeds.graphql | 3 +-- 11 files changed, 37 insertions(+), 52 deletions(-) diff --git a/server/assets_v2/src/queries/feeds.js b/server/assets_v2/src/queries/feeds.js index 1f3a279f..5c28e826 100644 --- a/server/assets_v2/src/queries/feeds.js +++ b/server/assets_v2/src/queries/feeds.js @@ -20,7 +20,6 @@ export const GET_FEED = gql` name slug nodeName - locationPoint introHtml thumbUrl mapUrl diff --git a/server/assets_v2/src/types/feedType.js b/server/assets_v2/src/types/feedType.js index b78b414d..86d89ced 100644 --- a/server/assets_v2/src/types/feedType.js +++ b/server/assets_v2/src/types/feedType.js @@ -3,6 +3,5 @@ export const feedType = shape({ name: string.isRequired, slug: string.isRequired, nodeName: string.isRequired, - locationPoint: object, introHtml: string }) diff --git a/server/lib/orcasite/radio/feed.ex b/server/lib/orcasite/radio/feed.ex index 9d8ae11f..3862a5b9 100644 --- a/server/lib/orcasite/radio/feed.ex +++ b/server/lib/orcasite/radio/feed.ex @@ -32,7 +32,7 @@ defmodule Orcasite.Radio.Feed do prepare fn query, _context -> query - |> Ash.Query.load(:longitude_latitude) + |> Ash.Query.load(:latitude_longitude) end end @@ -44,22 +44,22 @@ defmodule Orcasite.Radio.Feed do primary? true reject [:location_point] - argument :longitude_latitude, :string do + argument :latitude_longitude, :string do description "A comma-separated string of longitude and latitude" end - change &change_longitude_latitude/2 + change &change_latitude_longitude/2 end update :update do primary? true reject [:location_point] - argument :longitude_latitude, :string do + argument :latitude_longitude, :string do description "A comma-separated string of longitude and latitude" end - change &change_longitude_latitude/2 + change &change_latitude_longitude/2 end end @@ -70,15 +70,15 @@ defmodule Orcasite.Radio.Feed do end calculations do - calculate :longitude_latitude, + calculate :latitude_longitude, :string, {Orcasite.Radio.Calculations.LongitudeLatitude, keys: [:location_point], select: [:location_point]} end - defp change_longitude_latitude(changeset, _context) do + defp change_latitude_longitude(changeset, _context) do with {:is_string, lng_lat} when is_binary(lng_lat) <- - {:is_string, Ash.Changeset.get_argument(changeset, :longitude_latitude)}, + {:is_string, Ash.Changeset.get_argument(changeset, :latitude_longitude)}, {:two_els, [lng, lat]} <- {:two_els, lng_lat |> String.split(",") |> Enum.map(&String.trim/1)}, {:two_floats, [{longitude, _}, {latitude, _}]} <- @@ -95,13 +95,13 @@ defmodule Orcasite.Radio.Feed do {:two_els, _} -> changeset |> Ash.Changeset.add_error( - field: :longitude_latitude, + field: :latitude_longitude, message: "must be a comma-separated string" ) {:two_floats, _} -> changeset - |> Ash.Changeset.add_error(field: :longitude_latitude, message: "must be two floats") + |> Ash.Changeset.add_error(field: :latitude_longitude, message: "must be two floats") end end diff --git a/server/lib/orcasite_web/graphql/types/feed.ex b/server/lib/orcasite_web/graphql/types/feed.ex index 1887d2fb..8ff0b746 100644 --- a/server/lib/orcasite_web/graphql/types/feed.ex +++ b/server/lib/orcasite_web/graphql/types/feed.ex @@ -10,17 +10,7 @@ defmodule OrcasiteWeb.Types.Feed do field(:node_name, non_null(:string)) field(:slug, non_null(:string)) - field :location_point, non_null(:json) do - resolve(fn - %{location_point: point}, _, _ when not is_nil(point) -> - Geo.JSON.encode(point) - - _, _, _ -> - {:ok, %{}} - end) - end - - field :longitude_latitude, non_null(:json) do + field :latitude_longitude, non_null(:json) do resolve(fn %{location_point: %{coordinates: {lng, lat}}}, _, _ -> {:ok, %{lng: lng, lat: lat}} diff --git a/server/priv/repo/seeds.exs b/server/priv/repo/seeds.exs index 6f2f2370..bcabc7a1 100644 --- a/server/priv/repo/seeds.exs +++ b/server/priv/repo/seeds.exs @@ -13,33 +13,41 @@ import Ecto.Query alias Orcasite.RadioLegacy.Feed +Orcasite.Accounts.User +|> Ash.Changeset.for_create(:create, %{ + email: "admin@example.com", + password: "password", + admin: true +}) +|> Orcasite.Accounts.create!() + feeds = [ %{ - location_point: Geo.WKT.decode!("SRID=4326;POINT(48.5583362 -123.1735774)"), + location_point: Geo.WKT.decode!("SRID=4326;POINT(-123.1735774 48.5583362)"), name: "Orcasound Lab (Haro Strait)", node_name: "rpi_orcasound_lab", slug: "orcasound-lab" }, %{ - location_point: Geo.WKT.decode!("SRID=4326;POINT(48.0336664 -122.6040035)"), + location_point: Geo.WKT.decode!("SRID=4326;POINT(-122.6040035 48.0336664)"), name: "Bush Point", node_name: "rpi_bush_point", slug: "bush-point" }, %{ - location_point: Geo.WKT.decode!("SRID=4326;POINT(48.135743 -122.760614)"), + location_point: Geo.WKT.decode!("SRID=4326;POINT(-122.760614 48.135743)"), name: "Port Townsend", node_name: "rpi_port_townsend", slug: "port-townsend" }, %{ - location_point: Geo.WKT.decode!("SRID=4326;POINT(47.86497296593844 -122.33393605795372)"), + location_point: Geo.WKT.decode!("SRID=4326;POINT(-122.33393605795372 47.86497296593844)"), name: "Sunset Bay", node_name: "rpi_sunset_bay", slug: "sunset-bay" }, %{ - location_point: Geo.WKT.decode!("SRID=4326;POINT(48.591294 -123.058779)"), + location_point: Geo.WKT.decode!("SRID=4326;POINT(-123.058779 48.591294)"), name: "North San Juan Channel", node_name: "rpi_north_sjc", slug: "north-sjc" diff --git a/ui/src/components/Map.tsx b/ui/src/components/Map.tsx index 0fadb36c..3c002131 100644 --- a/ui/src/components/Map.tsx +++ b/ui/src/components/Map.tsx @@ -17,7 +17,7 @@ export default function Map({ feeds, }: { setMap?: (map: LeafletMap) => void - currentFeed?: Pick + currentFeed?: Pick feeds: FeedsQuery['feeds'] }) { const router = useRouter() @@ -50,7 +50,7 @@ export default function Map({ {feeds.map((feed) => ( ({ name: feedSlug, slug: feedSlug, nodeName: feedSlug, - longitudeLatitude: {lng: -122.3, lat: 47.6}, - // TODO: figure out which coordinates to use for dynamic feeds - locationPoint: { - coordinates: [47.6, -122.3], - }, + latitudeLongitude: {lat: 47.6, lng: -122.3}, }) function MapLayout({ children }: { children: ReactNode }) { @@ -47,7 +43,7 @@ function MapLayout({ children }: { children: ReactNode }) { useEffect(() => { if (feed && feed.slug !== currentFeed?.slug) { setCurrentFeed(feed) - map?.panTo(feed.longitudeLatitude) + map?.panTo(feed.latitudeLongitude) } }, [feed, map, currentFeed]) diff --git a/ui/src/components/Player/Player.tsx b/ui/src/components/Player/Player.tsx index c95e49f0..9fbe96d5 100644 --- a/ui/src/components/Player/Player.tsx +++ b/ui/src/components/Player/Player.tsx @@ -22,7 +22,7 @@ export default function Player({ }: { currentFeed?: Pick< Feed, - 'id' | 'slug' | 'nodeName' | 'name' | 'locationPoint' | 'longitudeLatitude' + 'id' | 'slug' | 'nodeName' | 'name' | 'latitudeLongitude' > }) { const [playerStatus, setPlayerStatus] = useState('idle') @@ -153,7 +153,7 @@ export default function Player({ {currentFeed && - `${currentFeed.longitudeLatitude["lng"]}, ${currentFeed.longitudeLatitude["lat"]}`} + `${currentFeed.latitudeLongitude["lng"]}, ${currentFeed.latitudeLongitude["lat"]}`} ) diff --git a/ui/src/graphql/generated/index.ts b/ui/src/graphql/generated/index.ts index f61d205d..f2cda47c 100644 --- a/ui/src/graphql/generated/index.ts +++ b/ui/src/graphql/generated/index.ts @@ -104,8 +104,7 @@ export type Feed = { __typename?: 'Feed' id: Scalars['ID']['output'] introHtml: Scalars['String']['output'] - locationPoint: Scalars['Json']['output'] - longitudeLatitude: Scalars['Json']['output'] + latitudeLongitude: Scalars['Json']['output'] mapUrl: Scalars['String']['output'] name: Scalars['String']['output'] nodeName: Scalars['String']['output'] @@ -254,8 +253,7 @@ export type FeedQuery = { name: string slug: string nodeName: string - locationPoint: any - longitudeLatitude: any + latitudeLongitude: any introHtml: string thumbUrl: string mapUrl: string @@ -272,8 +270,7 @@ export type FeedsQuery = { name: string slug: string nodeName: string - locationPoint: any - longitudeLatitude: any + latitudeLongitude: any thumbUrl: string mapUrl: string }> @@ -337,8 +334,7 @@ export const FeedDocument = ` name slug nodeName - locationPoint - longitudeLatitude + latitudeLongitude introHtml thumbUrl mapUrl @@ -366,8 +362,7 @@ export const FeedsDocument = ` name slug nodeName - locationPoint - longitudeLatitude + latitudeLongitude thumbUrl mapUrl } diff --git a/ui/src/graphql/queries/getFeed.graphql b/ui/src/graphql/queries/getFeed.graphql index 58af7627..667e1c24 100644 --- a/ui/src/graphql/queries/getFeed.graphql +++ b/ui/src/graphql/queries/getFeed.graphql @@ -4,8 +4,7 @@ query feed($slug: String!) { name slug nodeName - locationPoint - longitudeLatitude + latitudeLongitude introHtml thumbUrl mapUrl diff --git a/ui/src/graphql/queries/listFeeds.graphql b/ui/src/graphql/queries/listFeeds.graphql index 64c4f300..3374163a 100644 --- a/ui/src/graphql/queries/listFeeds.graphql +++ b/ui/src/graphql/queries/listFeeds.graphql @@ -4,8 +4,7 @@ query feeds { name slug nodeName - locationPoint - longitudeLatitude + latitudeLongitude thumbUrl mapUrl } From 9e80a552b62717bff61a285fdb1917a7b93ba4bf Mon Sep 17 00:00:00 2001 From: Skander Mzali Date: Thu, 27 Jul 2023 15:16:15 -0700 Subject: [PATCH 05/12] Blank commit to trigger github actions From 06ac86bb758990fed48c851644632074c0bb7fa6 Mon Sep 17 00:00:00 2001 From: skanderm Date: Thu, 27 Jul 2023 17:17:57 -0700 Subject: [PATCH 06/12] Update ui/src/components/MapLayout.tsx Co-authored-by: Paul Cretu --- ui/src/components/MapLayout.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/src/components/MapLayout.tsx b/ui/src/components/MapLayout.tsx index 4a491df0..3e7d13f4 100644 --- a/ui/src/components/MapLayout.tsx +++ b/ui/src/components/MapLayout.tsx @@ -20,6 +20,7 @@ const feedFromSlug = (feedSlug: string) => ({ name: feedSlug, slug: feedSlug, nodeName: feedSlug, + // TODO: figure out which coordinates to use for dynamic feeds latitudeLongitude: {lat: 47.6, lng: -122.3}, }) From 78f08f5ad474d459c482358fc0768d58304daf10 Mon Sep 17 00:00:00 2001 From: Paul Cretu Date: Fri, 28 Jul 2023 01:02:51 +0000 Subject: [PATCH 07/12] `latitudeLongitude` -> `latLng` --- server/lib/orcasite/radio/feed.ex | 20 +++++++++---------- server/lib/orcasite_web/graphql/types/feed.ex | 2 +- ui/src/components/Map.tsx | 4 ++-- ui/src/components/MapLayout.tsx | 4 ++-- ui/src/components/Player/Player.tsx | 7 ++----- ui/src/graphql/generated/index.ts | 10 +++++----- ui/src/graphql/queries/getFeed.graphql | 2 +- ui/src/graphql/queries/listFeeds.graphql | 2 +- 8 files changed, 24 insertions(+), 27 deletions(-) diff --git a/server/lib/orcasite/radio/feed.ex b/server/lib/orcasite/radio/feed.ex index 3862a5b9..71764b64 100644 --- a/server/lib/orcasite/radio/feed.ex +++ b/server/lib/orcasite/radio/feed.ex @@ -32,7 +32,7 @@ defmodule Orcasite.Radio.Feed do prepare fn query, _context -> query - |> Ash.Query.load(:latitude_longitude) + |> Ash.Query.load(:lat_lng) end end @@ -44,22 +44,22 @@ defmodule Orcasite.Radio.Feed do primary? true reject [:location_point] - argument :latitude_longitude, :string do + argument :lat_lng, :string do description "A comma-separated string of longitude and latitude" end - change &change_latitude_longitude/2 + change &change_lat_lng/2 end update :update do primary? true reject [:location_point] - argument :latitude_longitude, :string do + argument :lat_lng, :string do description "A comma-separated string of longitude and latitude" end - change &change_latitude_longitude/2 + change &change_lat_lng/2 end end @@ -70,15 +70,15 @@ defmodule Orcasite.Radio.Feed do end calculations do - calculate :latitude_longitude, + calculate :lat_lng, :string, {Orcasite.Radio.Calculations.LongitudeLatitude, keys: [:location_point], select: [:location_point]} end - defp change_latitude_longitude(changeset, _context) do + defp change_lat_lng(changeset, _context) do with {:is_string, lng_lat} when is_binary(lng_lat) <- - {:is_string, Ash.Changeset.get_argument(changeset, :latitude_longitude)}, + {:is_string, Ash.Changeset.get_argument(changeset, :lat_lng)}, {:two_els, [lng, lat]} <- {:two_els, lng_lat |> String.split(",") |> Enum.map(&String.trim/1)}, {:two_floats, [{longitude, _}, {latitude, _}]} <- @@ -95,13 +95,13 @@ defmodule Orcasite.Radio.Feed do {:two_els, _} -> changeset |> Ash.Changeset.add_error( - field: :latitude_longitude, + field: :lat_lng, message: "must be a comma-separated string" ) {:two_floats, _} -> changeset - |> Ash.Changeset.add_error(field: :latitude_longitude, message: "must be two floats") + |> Ash.Changeset.add_error(field: :lat_lng, message: "must be two floats") end end diff --git a/server/lib/orcasite_web/graphql/types/feed.ex b/server/lib/orcasite_web/graphql/types/feed.ex index 8ff0b746..4f367bb3 100644 --- a/server/lib/orcasite_web/graphql/types/feed.ex +++ b/server/lib/orcasite_web/graphql/types/feed.ex @@ -10,7 +10,7 @@ defmodule OrcasiteWeb.Types.Feed do field(:node_name, non_null(:string)) field(:slug, non_null(:string)) - field :latitude_longitude, non_null(:json) do + field :lat_lng, non_null(:json) do resolve(fn %{location_point: %{coordinates: {lng, lat}}}, _, _ -> {:ok, %{lng: lng, lat: lat}} diff --git a/ui/src/components/Map.tsx b/ui/src/components/Map.tsx index 3c002131..055361fa 100644 --- a/ui/src/components/Map.tsx +++ b/ui/src/components/Map.tsx @@ -17,7 +17,7 @@ export default function Map({ feeds, }: { setMap?: (map: LeafletMap) => void - currentFeed?: Pick + currentFeed?: Pick feeds: FeedsQuery['feeds'] }) { const router = useRouter() @@ -50,7 +50,7 @@ export default function Map({ {feeds.map((feed) => ( ({ slug: feedSlug, nodeName: feedSlug, // TODO: figure out which coordinates to use for dynamic feeds - latitudeLongitude: {lat: 47.6, lng: -122.3}, + latLng: { lat: 47.6, lng: -122.3 }, }) function MapLayout({ children }: { children: ReactNode }) { @@ -44,7 +44,7 @@ function MapLayout({ children }: { children: ReactNode }) { useEffect(() => { if (feed && feed.slug !== currentFeed?.slug) { setCurrentFeed(feed) - map?.panTo(feed.latitudeLongitude) + map?.panTo(feed.latLng) } }, [feed, map, currentFeed]) diff --git a/ui/src/components/Player/Player.tsx b/ui/src/components/Player/Player.tsx index 9fbe96d5..80cb21fa 100644 --- a/ui/src/components/Player/Player.tsx +++ b/ui/src/components/Player/Player.tsx @@ -20,10 +20,7 @@ export type PlayerStatus = 'idle' | 'loading' | 'playing' | 'paused' | 'error' export default function Player({ currentFeed, }: { - currentFeed?: Pick< - Feed, - 'id' | 'slug' | 'nodeName' | 'name' | 'latitudeLongitude' - > + currentFeed?: Pick }) { const [playerStatus, setPlayerStatus] = useState('idle') const playerRef = useRef(null) @@ -153,7 +150,7 @@ export default function Player({ {currentFeed && - `${currentFeed.latitudeLongitude["lng"]}, ${currentFeed.latitudeLongitude["lat"]}`} + `${currentFeed.latLng['lng']}, ${currentFeed.latLng['lat']}`} ) diff --git a/ui/src/graphql/generated/index.ts b/ui/src/graphql/generated/index.ts index f2cda47c..ac1f18c1 100644 --- a/ui/src/graphql/generated/index.ts +++ b/ui/src/graphql/generated/index.ts @@ -104,7 +104,7 @@ export type Feed = { __typename?: 'Feed' id: Scalars['ID']['output'] introHtml: Scalars['String']['output'] - latitudeLongitude: Scalars['Json']['output'] + latLng: Scalars['Json']['output'] mapUrl: Scalars['String']['output'] name: Scalars['String']['output'] nodeName: Scalars['String']['output'] @@ -253,7 +253,7 @@ export type FeedQuery = { name: string slug: string nodeName: string - latitudeLongitude: any + latLng: any introHtml: string thumbUrl: string mapUrl: string @@ -270,7 +270,7 @@ export type FeedsQuery = { name: string slug: string nodeName: string - latitudeLongitude: any + latLng: any thumbUrl: string mapUrl: string }> @@ -334,7 +334,7 @@ export const FeedDocument = ` name slug nodeName - latitudeLongitude + latLng introHtml thumbUrl mapUrl @@ -362,7 +362,7 @@ export const FeedsDocument = ` name slug nodeName - latitudeLongitude + latLng thumbUrl mapUrl } diff --git a/ui/src/graphql/queries/getFeed.graphql b/ui/src/graphql/queries/getFeed.graphql index 667e1c24..8c8e0d59 100644 --- a/ui/src/graphql/queries/getFeed.graphql +++ b/ui/src/graphql/queries/getFeed.graphql @@ -4,7 +4,7 @@ query feed($slug: String!) { name slug nodeName - latitudeLongitude + latLng introHtml thumbUrl mapUrl diff --git a/ui/src/graphql/queries/listFeeds.graphql b/ui/src/graphql/queries/listFeeds.graphql index 3374163a..f8085871 100644 --- a/ui/src/graphql/queries/listFeeds.graphql +++ b/ui/src/graphql/queries/listFeeds.graphql @@ -4,7 +4,7 @@ query feeds { name slug nodeName - latitudeLongitude + latLng thumbUrl mapUrl } From 5416afbae7e46c9e86b414a1b8f3652530779f83 Mon Sep 17 00:00:00 2001 From: Skander Mzali Date: Thu, 27 Jul 2023 19:10:44 -0700 Subject: [PATCH 08/12] Update user admin creation --- server/priv/repo/seeds.exs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/server/priv/repo/seeds.exs b/server/priv/repo/seeds.exs index bcabc7a1..a02dd978 100644 --- a/server/priv/repo/seeds.exs +++ b/server/priv/repo/seeds.exs @@ -13,14 +13,6 @@ import Ecto.Query alias Orcasite.RadioLegacy.Feed -Orcasite.Accounts.User -|> Ash.Changeset.for_create(:create, %{ - email: "admin@example.com", - password: "password", - admin: true -}) -|> Orcasite.Accounts.create!() - feeds = [ %{ location_point: Geo.WKT.decode!("SRID=4326;POINT(-123.1735774 48.5583362)"), @@ -68,3 +60,14 @@ for attrs <- feeds do |> Orcasite.Repo.insert!() end end + +# Create admin account +strategy = AshAuthentication.Info.strategy!(Orcasite.Accounts.User, :password) +Orcasite.Accounts.User +|> Ash.Changeset.for_create(strategy.register_action_name, %{ + email: "admin@example.com", + password: "password", + password_confirmation: "password", +}) +|> Ash.Changeset.force_change_attribute(:admin, true) +|> Orcasite.Accounts.create!() From effe44eed0e3183c75b03c646eb89ad0ed68217f Mon Sep 17 00:00:00 2001 From: Paul Cretu Date: Fri, 28 Jul 2023 02:31:06 +0000 Subject: [PATCH 09/12] Finish swapping around lat and lng --- .../{longitude_latitude.ex => lat_lng.ex} | 4 ++-- server/lib/orcasite/radio/feed.ex | 12 ++++++------ server/lib/orcasite_web/graphql/types/feed.ex | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) rename server/lib/orcasite/radio/calculations/{longitude_latitude.ex => lat_lng.ex} (76%) diff --git a/server/lib/orcasite/radio/calculations/longitude_latitude.ex b/server/lib/orcasite/radio/calculations/lat_lng.ex similarity index 76% rename from server/lib/orcasite/radio/calculations/longitude_latitude.ex rename to server/lib/orcasite/radio/calculations/lat_lng.ex index 7f6abec2..d68f3bf0 100644 --- a/server/lib/orcasite/radio/calculations/longitude_latitude.ex +++ b/server/lib/orcasite/radio/calculations/lat_lng.ex @@ -1,4 +1,4 @@ -defmodule Orcasite.Radio.Calculations.LongitudeLatitude do +defmodule Orcasite.Radio.Calculations.LatLng do use Ash.Calculation @impl true @@ -9,7 +9,7 @@ defmodule Orcasite.Radio.Calculations.LongitudeLatitude do @impl true def calculate(records, _opts, _arguments) do Enum.map(records, fn %{location_point: %{coordinates: {lng, lat}}} -> - "#{lng},#{lat}" + "#{lat},#{lng}" end) end end diff --git a/server/lib/orcasite/radio/feed.ex b/server/lib/orcasite/radio/feed.ex index 71764b64..07ad25e9 100644 --- a/server/lib/orcasite/radio/feed.ex +++ b/server/lib/orcasite/radio/feed.ex @@ -72,17 +72,17 @@ defmodule Orcasite.Radio.Feed do calculations do calculate :lat_lng, :string, - {Orcasite.Radio.Calculations.LongitudeLatitude, + {Orcasite.Radio.Calculations.LatLng, keys: [:location_point], select: [:location_point]} end defp change_lat_lng(changeset, _context) do - with {:is_string, lng_lat} when is_binary(lng_lat) <- + with {:is_string, lat_lng} when is_binary(lat_lng) <- {:is_string, Ash.Changeset.get_argument(changeset, :lat_lng)}, - {:two_els, [lng, lat]} <- - {:two_els, lng_lat |> String.split(",") |> Enum.map(&String.trim/1)}, - {:two_floats, [{longitude, _}, {latitude, _}]} <- - {:two_floats, [lng, lat] |> Enum.map(&Float.parse/1)} do + {:two_els, [lat, lng]} <- + {:two_els, lat_lng |> String.split(",") |> Enum.map(&String.trim/1)}, + {:two_floats, [{latitude, _}, {longitude, _}]} <- + {:two_floats, [lat, lng] |> Enum.map(&Float.parse/1)} do changeset |> Ash.Changeset.change_attribute(:location_point, %Geo.Point{ coordinates: {longitude, latitude}, diff --git a/server/lib/orcasite_web/graphql/types/feed.ex b/server/lib/orcasite_web/graphql/types/feed.ex index 4f367bb3..bf8a511f 100644 --- a/server/lib/orcasite_web/graphql/types/feed.ex +++ b/server/lib/orcasite_web/graphql/types/feed.ex @@ -13,7 +13,7 @@ defmodule OrcasiteWeb.Types.Feed do field :lat_lng, non_null(:json) do resolve(fn %{location_point: %{coordinates: {lng, lat}}}, _, _ -> - {:ok, %{lng: lng, lat: lat}} + {:ok, %{lat: lat, lng: lng}} _, _, _ -> {:ok, %{}} From de3161aa2a2c8aa7796207b6b44f1b82fdff20ed Mon Sep 17 00:00:00 2001 From: Paul Cretu Date: Fri, 28 Jul 2023 02:36:13 +0000 Subject: [PATCH 10/12] array -> property accessor --- ui/src/components/Player/Player.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/src/components/Player/Player.tsx b/ui/src/components/Player/Player.tsx index 80cb21fa..5362fcda 100644 --- a/ui/src/components/Player/Player.tsx +++ b/ui/src/components/Player/Player.tsx @@ -149,8 +149,7 @@ export default function Player({ : 'Select a location to start listening live'} - {currentFeed && - `${currentFeed.latLng['lng']}, ${currentFeed.latLng['lat']}`} + {currentFeed && `${currentFeed.latLng.lng}, ${currentFeed.latLng.lat}`} ) From 108cfd8f316fbf3746684df65b0bbfb94adb6f84 Mon Sep 17 00:00:00 2001 From: Paul Cretu Date: Fri, 28 Jul 2023 02:56:21 +0000 Subject: [PATCH 11/12] Add types for latLng --- server/lib/orcasite_web/graphql/types/feed.ex | 7 +++++- ui/src/graphql/generated/index.ts | 23 ++++++++++++++----- ui/src/graphql/queries/getFeed.graphql | 5 +++- ui/src/graphql/queries/listFeeds.graphql | 5 +++- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/server/lib/orcasite_web/graphql/types/feed.ex b/server/lib/orcasite_web/graphql/types/feed.ex index bf8a511f..a9834aa2 100644 --- a/server/lib/orcasite_web/graphql/types/feed.ex +++ b/server/lib/orcasite_web/graphql/types/feed.ex @@ -4,13 +4,18 @@ defmodule OrcasiteWeb.Types.Feed do """ use Absinthe.Schema.Notation + object :latLng do + field(:lat, non_null(:float)) + field(:lng, non_null(:float)) + end + object :feed do field(:id, non_null(:id)) field(:name, non_null(:string)) field(:node_name, non_null(:string)) field(:slug, non_null(:string)) - field :lat_lng, non_null(:json) do + field :lat_lng, non_null(:latLng) do resolve(fn %{location_point: %{coordinates: {lng, lat}}}, _, _ -> {:ok, %{lat: lat, lng: lng}} diff --git a/ui/src/graphql/generated/index.ts b/ui/src/graphql/generated/index.ts index ac1f18c1..07f8cb30 100644 --- a/ui/src/graphql/generated/index.ts +++ b/ui/src/graphql/generated/index.ts @@ -54,7 +54,6 @@ export type Scalars = { Float: { input: number; output: number } DateTime: { input: any; output: any } Decimal: { input: any; output: any } - Json: { input: any; output: any } } export type Candidate = { @@ -104,7 +103,7 @@ export type Feed = { __typename?: 'Feed' id: Scalars['ID']['output'] introHtml: Scalars['String']['output'] - latLng: Scalars['Json']['output'] + latLng: LatLng mapUrl: Scalars['String']['output'] name: Scalars['String']['output'] nodeName: Scalars['String']['output'] @@ -112,6 +111,12 @@ export type Feed = { thumbUrl: Scalars['String']['output'] } +export type LatLng = { + __typename?: 'LatLng' + lat: Scalars['Float']['output'] + lng: Scalars['Float']['output'] +} + /** Pagination options */ export type Pagination = { page: Scalars['Int']['input'] @@ -253,10 +258,10 @@ export type FeedQuery = { name: string slug: string nodeName: string - latLng: any introHtml: string thumbUrl: string mapUrl: string + latLng: { __typename?: 'LatLng'; lat: number; lng: number } } } @@ -270,9 +275,9 @@ export type FeedsQuery = { name: string slug: string nodeName: string - latLng: any thumbUrl: string mapUrl: string + latLng: { __typename?: 'LatLng'; lat: number; lng: number } }> } @@ -334,7 +339,10 @@ export const FeedDocument = ` name slug nodeName - latLng + latLng { + lat + lng + } introHtml thumbUrl mapUrl @@ -362,7 +370,10 @@ export const FeedsDocument = ` name slug nodeName - latLng + latLng { + lat + lng + } thumbUrl mapUrl } diff --git a/ui/src/graphql/queries/getFeed.graphql b/ui/src/graphql/queries/getFeed.graphql index 8c8e0d59..7d574b3b 100644 --- a/ui/src/graphql/queries/getFeed.graphql +++ b/ui/src/graphql/queries/getFeed.graphql @@ -4,7 +4,10 @@ query feed($slug: String!) { name slug nodeName - latLng + latLng { + lat + lng + } introHtml thumbUrl mapUrl diff --git a/ui/src/graphql/queries/listFeeds.graphql b/ui/src/graphql/queries/listFeeds.graphql index f8085871..819b6de9 100644 --- a/ui/src/graphql/queries/listFeeds.graphql +++ b/ui/src/graphql/queries/listFeeds.graphql @@ -4,7 +4,10 @@ query feeds { name slug nodeName - latLng + latLng { + lat + lng + } thumbUrl mapUrl } From f7ec2de32b02f53404e23e2b7248b509fa16b81e Mon Sep 17 00:00:00 2001 From: Paul Cretu Date: Fri, 28 Jul 2023 03:24:46 +0000 Subject: [PATCH 12/12] Make locationPoint non-nil --- server/lib/orcasite/radio/feed.ex | 2 +- server/lib/orcasite_web/graphql/types/feed.ex | 7 +- ...0728032134_make_location_point_non_nil.exs | 21 ++++ .../repo/feeds/20230728032135.json | 98 +++++++++++++++++++ 4 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 server/priv/repo/migrations/20230728032134_make_location_point_non_nil.exs create mode 100644 server/priv/resource_snapshots/repo/feeds/20230728032135.json diff --git a/server/lib/orcasite/radio/feed.ex b/server/lib/orcasite/radio/feed.ex index 07ad25e9..80951f5f 100644 --- a/server/lib/orcasite/radio/feed.ex +++ b/server/lib/orcasite/radio/feed.ex @@ -9,7 +9,7 @@ defmodule Orcasite.Radio.Feed do attribute :name, :string attribute :node_name, :string attribute :slug, :string - attribute :location_point, :geometry + attribute :location_point, :geometry, allow_nil?: false create_timestamp :inserted_at update_timestamp :updated_at diff --git a/server/lib/orcasite_web/graphql/types/feed.ex b/server/lib/orcasite_web/graphql/types/feed.ex index a9834aa2..dfd52d04 100644 --- a/server/lib/orcasite_web/graphql/types/feed.ex +++ b/server/lib/orcasite_web/graphql/types/feed.ex @@ -4,7 +4,7 @@ defmodule OrcasiteWeb.Types.Feed do """ use Absinthe.Schema.Notation - object :latLng do + object :lat_lng do field(:lat, non_null(:float)) field(:lng, non_null(:float)) end @@ -15,13 +15,10 @@ defmodule OrcasiteWeb.Types.Feed do field(:node_name, non_null(:string)) field(:slug, non_null(:string)) - field :lat_lng, non_null(:latLng) do + field :lat_lng, non_null(:lat_lng) do resolve(fn %{location_point: %{coordinates: {lng, lat}}}, _, _ -> {:ok, %{lat: lat, lng: lng}} - - _, _, _ -> - {:ok, %{}} end) end diff --git a/server/priv/repo/migrations/20230728032134_make_location_point_non_nil.exs b/server/priv/repo/migrations/20230728032134_make_location_point_non_nil.exs new file mode 100644 index 00000000..6e910674 --- /dev/null +++ b/server/priv/repo/migrations/20230728032134_make_location_point_non_nil.exs @@ -0,0 +1,21 @@ +defmodule Orcasite.Repo.Migrations.MakeLocationPointNonNil do + @moduledoc """ + Updates resources based on their most recent snapshots. + + This file was autogenerated with `mix ash_postgres.generate_migrations` + """ + + use Ecto.Migration + + def up do + alter table(:feeds) do + modify :location_point, :geometry, null: false + end + end + + def down do + alter table(:feeds) do + modify :location_point, :geometry, null: true + end + end +end \ No newline at end of file diff --git a/server/priv/resource_snapshots/repo/feeds/20230728032135.json b/server/priv/resource_snapshots/repo/feeds/20230728032135.json new file mode 100644 index 00000000..3181676d --- /dev/null +++ b/server/priv/resource_snapshots/repo/feeds/20230728032135.json @@ -0,0 +1,98 @@ +{ + "attributes": [ + { + "default": "nil", + "size": null, + "type": "bigint", + "source": "id", + "references": null, + "allow_nil?": false, + "primary_key?": true, + "generated?": true + }, + { + "default": "nil", + "size": null, + "type": "text", + "source": "name", + "references": null, + "allow_nil?": true, + "primary_key?": false, + "generated?": false + }, + { + "default": "nil", + "size": null, + "type": "text", + "source": "node_name", + "references": null, + "allow_nil?": true, + "primary_key?": false, + "generated?": false + }, + { + "default": "nil", + "size": null, + "type": "text", + "source": "slug", + "references": null, + "allow_nil?": true, + "primary_key?": false, + "generated?": false + }, + { + "default": "nil", + "size": null, + "type": "geometry", + "source": "location_point", + "references": null, + "allow_nil?": false, + "primary_key?": false, + "generated?": false + }, + { + "default": "fragment(\"now()\")", + "size": null, + "type": "utc_datetime_usec", + "source": "inserted_at", + "references": null, + "allow_nil?": false, + "primary_key?": false, + "generated?": false + }, + { + "default": "fragment(\"now()\")", + "size": null, + "type": "utc_datetime_usec", + "source": "updated_at", + "references": null, + "allow_nil?": false, + "primary_key?": false, + "generated?": false + } + ], + "table": "feeds", + "hash": "CFF5AB9134C541B23476FBE8EEE1739B188560E3D2BBC8E5B318F60127E90B06", + "repo": "Elixir.Orcasite.Repo", + "identities": [ + { + "name": "unique_slug", + "keys": [ + "slug" + ], + "base_filter": null, + "index_name": "feeds_unique_slug_index" + } + ], + "schema": null, + "multitenancy": { + "global": null, + "attribute": null, + "strategy": null + }, + "base_filter": null, + "check_constraints": [], + "custom_indexes": [], + "custom_statements": [], + "has_create_action": true +} \ No newline at end of file