From f8eaef5b6b59e1cc5153cdf9c67a4251b2323dfe Mon Sep 17 00:00:00 2001 From: Michael St Clair Date: Sat, 11 May 2024 12:11:27 -0600 Subject: [PATCH 1/7] setup lvn --- config/config.exs | 20 + config/dev.exs | 6 +- lib/spendable_native.ex | 73 +++ lib/spendable_web.ex | 6 + .../components/layouts.swiftui.ex | 5 + .../layouts_swiftui/app.swiftui.neex | 1 + .../layouts_swiftui/root.swiftui.neex | 5 + .../controllers/auth_controller.ex | 5 +- .../controllers/page_controller.ex | 7 + lib/spendable_web/controllers/page_html.ex | 5 + .../page_html/privacy_policy.html.heex | 56 ++ lib/spendable_web/endpoint.ex | 1 + lib/spendable_web/live/budgets_swiftui.ex | 15 + lib/spendable_web/live/login.ex | 143 +++++ lib/spendable_web/live/login_swiftui.ex | 17 + lib/spendable_web/live/user_auth.ex | 4 +- lib/spendable_web/router.ex | 7 +- lib/spendable_web/styles/app.swiftui.ex | 28 + mix.exs | 9 +- mix.lock | 26 +- .../Spendable.xcodeproj/project.pbxproj | 522 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../xcshareddata/swiftpm/Package.resolved | 141 +++++ .../UserInterfaceState.xcuserstate | Bin 0 -> 24717 bytes .../xcschemes/xcschememanagement.plist | 40 ++ .../AppIcon.appiconset/1024-mac.png | Bin 0 -> 108623 bytes .../AppIcon.appiconset/128-mac.png | Bin 0 -> 7154 bytes .../AppIcon.appiconset/16-mac.png | Bin 0 -> 589 bytes .../AppIcon.appiconset/256-mac 1.png | Bin 0 -> 17057 bytes .../AppIcon.appiconset/256-mac.png | Bin 0 -> 17057 bytes .../AppIcon.appiconset/32-mac 1.png | Bin 0 -> 1496 bytes .../AppIcon.appiconset/32-mac.png | Bin 0 -> 1496 bytes .../AppIcon.appiconset/512-mac 1.png | Bin 0 -> 42698 bytes .../AppIcon.appiconset/512-mac.png | Bin 0 -> 42698 bytes .../AppIcon.appiconset/64-mac.png | Bin 0 -> 3026 bytes .../AppIcon.appiconset/AppIcon 1.jpg | Bin 0 -> 71306 bytes .../AppIcon.appiconset/AppIcon.jpg | Bin 0 -> 71306 bytes .../AppIcon.appiconset/Contents.json | 80 +++ .../Spendable/Assets.xcassets/Contents.json | 6 + native/swiftui/Spendable/ConnectingView.swift | 16 + native/swiftui/Spendable/ContentView.swift | 29 + .../swiftui/Spendable/DisconnectedView.swift | 29 + native/swiftui/Spendable/ErrorView.swift | 95 ++++ .../Preview Assets.xcassets/Contents.json | 6 + .../swiftui/Spendable/ReconnectingView.swift | 49 ++ native/swiftui/Spendable/Spendable.swift | 15 + 47 files changed, 1467 insertions(+), 15 deletions(-) create mode 100644 lib/spendable_native.ex create mode 100644 lib/spendable_web/components/layouts.swiftui.ex create mode 100644 lib/spendable_web/components/layouts_swiftui/app.swiftui.neex create mode 100644 lib/spendable_web/components/layouts_swiftui/root.swiftui.neex create mode 100644 lib/spendable_web/controllers/page_controller.ex create mode 100644 lib/spendable_web/controllers/page_html.ex create mode 100644 lib/spendable_web/controllers/page_html/privacy_policy.html.heex create mode 100644 lib/spendable_web/live/budgets_swiftui.ex create mode 100644 lib/spendable_web/live/login.ex create mode 100644 lib/spendable_web/live/login_swiftui.ex create mode 100644 lib/spendable_web/styles/app.swiftui.ex create mode 100644 native/swiftui/Spendable.xcodeproj/project.pbxproj create mode 100644 native/swiftui/Spendable.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 native/swiftui/Spendable.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 native/swiftui/Spendable.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved create mode 100644 native/swiftui/Spendable.xcodeproj/project.xcworkspace/xcuserdata/michael.xcuserdatad/UserInterfaceState.xcuserstate create mode 100644 native/swiftui/Spendable.xcodeproj/xcuserdata/michael.xcuserdatad/xcschemes/xcschememanagement.plist create mode 100644 native/swiftui/Spendable/Assets.xcassets/AppIcon.appiconset/1024-mac.png create mode 100644 native/swiftui/Spendable/Assets.xcassets/AppIcon.appiconset/128-mac.png create mode 100644 native/swiftui/Spendable/Assets.xcassets/AppIcon.appiconset/16-mac.png create mode 100644 native/swiftui/Spendable/Assets.xcassets/AppIcon.appiconset/256-mac 1.png create mode 100644 native/swiftui/Spendable/Assets.xcassets/AppIcon.appiconset/256-mac.png create mode 100644 native/swiftui/Spendable/Assets.xcassets/AppIcon.appiconset/32-mac 1.png create mode 100644 native/swiftui/Spendable/Assets.xcassets/AppIcon.appiconset/32-mac.png create mode 100644 native/swiftui/Spendable/Assets.xcassets/AppIcon.appiconset/512-mac 1.png create mode 100644 native/swiftui/Spendable/Assets.xcassets/AppIcon.appiconset/512-mac.png create mode 100644 native/swiftui/Spendable/Assets.xcassets/AppIcon.appiconset/64-mac.png create mode 100644 native/swiftui/Spendable/Assets.xcassets/AppIcon.appiconset/AppIcon 1.jpg create mode 100644 native/swiftui/Spendable/Assets.xcassets/AppIcon.appiconset/AppIcon.jpg create mode 100644 native/swiftui/Spendable/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 native/swiftui/Spendable/Assets.xcassets/Contents.json create mode 100644 native/swiftui/Spendable/ConnectingView.swift create mode 100644 native/swiftui/Spendable/ContentView.swift create mode 100644 native/swiftui/Spendable/DisconnectedView.swift create mode 100644 native/swiftui/Spendable/ErrorView.swift create mode 100644 native/swiftui/Spendable/Preview Content/Preview Assets.xcassets/Contents.json create mode 100644 native/swiftui/Spendable/ReconnectingView.swift create mode 100644 native/swiftui/Spendable/Spendable.swift diff --git a/config/config.exs b/config/config.exs index 2327c3c6..b707f225 100644 --- a/config/config.exs +++ b/config/config.exs @@ -52,6 +52,13 @@ config :logger, :console, # Use Jason for JSON parsing in Phoenix config :phoenix, :json_library, Jason +config :phoenix, :template_engines, neex: LiveViewNative.Engine +config :phoenix_template, :format_encoders, swiftui: Phoenix.HTML.Engine + +config :live_view_native, + plugins: [ + LiveViewNative.SwiftUI + ] config :ash, :use_all_identities_in_manage_relationship?, false @@ -65,6 +72,19 @@ config :ueberauth, Ueberauth, google: {Ueberauth.Strategy.Google, []} ] +config :mime, :types, %{ + "text/swiftui" => ["swiftui"], + "text/styles" => ["styles"] +} + +config :live_view_native_stylesheet, + content: [ + swiftui: [ + "lib/**/*swiftui*" + ] + ], + output: "priv/static/assets" + # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. import_config "#{config_env()}.exs" diff --git a/config/dev.exs b/config/dev.exs index 8adf80ae..6974e147 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -35,7 +35,7 @@ config :spendable, SpendableWeb.Endpoint, patterns: [ ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", ~r"priv/gettext/.*(po)$", - ~r"lib/spendable_web/(controllers|live|components)/.*(ex|heex)$" + ~r"lib/spendable_web/(controllers|live|components|styles)/.*(ex|heex,neex)$" ] ] @@ -53,3 +53,7 @@ config :phoenix, :stacktrace_depth, 20 config :phoenix, :plug_init_mode, :runtime config :spendable, Plaid, base_url: "https://sandbox.plaid.com" + +config :live_view_native_stylesheet, + annotations: true, + pretty: true diff --git a/lib/spendable_native.ex b/lib/spendable_native.ex new file mode 100644 index 00000000..c426a7e8 --- /dev/null +++ b/lib/spendable_native.ex @@ -0,0 +1,73 @@ +defmodule SpendableNative do + import SpendableWeb, only: [verified_routes: 0] + + def live_view() do + quote do + use LiveViewNative.LiveView, + formats: [ + :swiftui + ], + layouts: [ + swiftui: {SpendableWeb.Layouts.SwiftUI, :app} + ] + + unquote(verified_routes()) + end + end + + def render_component(opts) do + opts = + opts + |> Keyword.take([:format]) + |> Keyword.put(:as, :render) + + quote do + use LiveViewNative.Component, unquote(opts) + + unquote(helpers(opts[:format])) + end + end + + def component(opts) do + opts = Keyword.take(opts, [:format, :root, :as]) + + quote do + use LiveViewNative.Component, unquote(opts) + + unquote(helpers(opts[:format])) + end + end + + def layout(opts) do + opts = Keyword.take(opts, [:format, :root]) + + quote do + use LiveViewNative.Component, unquote(opts) + + import LiveViewNative.Component, only: [csrf_token: 1] + + unquote(helpers(opts[:format])) + end + end + + defp helpers(_format) do + gettext_quoted = quote do + import SpendableWeb.Gettext + end + + + [gettext_quoted, verified_routes()] + + end + + @doc """ + When used, dispatch to the appropriate controller/view/etc. + """ + defmacro __using__([which | opts]) when is_atom(which) do + apply(__MODULE__, which, [opts]) + end + + defmacro __using__(which) when is_atom(which) do + apply(__MODULE__, which, []) + end +end diff --git a/lib/spendable_web.ex b/lib/spendable_web.ex index d1a97a21..40808ddc 100644 --- a/lib/spendable_web.ex +++ b/lib/spendable_web.ex @@ -54,6 +54,12 @@ defmodule SpendableWeb do use Phoenix.LiveView, layout: {SpendableWeb.Layouts, :app} + use LiveViewNative.LiveView, + formats: [:swiftui], + layouts: [ + swiftui: {SpendableWeb.Layouts.SwiftUI, :app} + ] + unquote(html_helpers()) end end diff --git a/lib/spendable_web/components/layouts.swiftui.ex b/lib/spendable_web/components/layouts.swiftui.ex new file mode 100644 index 00000000..66a6d07b --- /dev/null +++ b/lib/spendable_web/components/layouts.swiftui.ex @@ -0,0 +1,5 @@ +defmodule SpendableWeb.Layouts.SwiftUI do + use SpendableNative, [:layout, format: :swiftui] + + embed_templates "layouts_swiftui/*" +end diff --git a/lib/spendable_web/components/layouts_swiftui/app.swiftui.neex b/lib/spendable_web/components/layouts_swiftui/app.swiftui.neex new file mode 100644 index 00000000..f3985a1e --- /dev/null +++ b/lib/spendable_web/components/layouts_swiftui/app.swiftui.neex @@ -0,0 +1 @@ +<%= @inner_content %> \ No newline at end of file diff --git a/lib/spendable_web/components/layouts_swiftui/root.swiftui.neex b/lib/spendable_web/components/layouts_swiftui/root.swiftui.neex new file mode 100644 index 00000000..3ef2df95 --- /dev/null +++ b/lib/spendable_web/components/layouts_swiftui/root.swiftui.neex @@ -0,0 +1,5 @@ +<.csrf_token /> +