Skip to content

Commit

Permalink
Merge pull request #41 from podlove/feat/onboarding-settings
Browse files Browse the repository at this point in the history
feat(onboarding) - set default settings
  • Loading branch information
dnkbln authored Aug 9, 2024
2 parents 8881745 + 4e19416 commit f829477
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
4 changes: 4 additions & 0 deletions client/src/sagas/helpers/podcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { type locales } from '../../types/locales.types';
import { type category } from '../../types/categories.types';
import { extractImageType } from '../../lib/image';

export function* setOnboardingPodcastSettings() {
yield request.post(request.origin('/api/v1/set_podcast_settings'), { params: {}, data: {} });
}

function transferPodcastCoverFromData(imageData: string, imageName: string) {
const parts: string[] = imageData.split(',');
const imageType: string | null = extractImageType(parts[0]);
Expand Down
3 changes: 2 additions & 1 deletion client/src/sagas/import.saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as request from '../lib/request';
import { findCategories } from '../helper/categories';
import { LanguageLocales } from '../types/locales.types';
import { type Episode, type EpisodeDetailsPayload } from '../types/episode.types';
import { savePodcastMetadata } from './helpers/podcast';
import { setOnboardingPodcastSettings, savePodcastMetadata } from './helpers/podcast';

function* validateFeedUrl({ payload }: Action<validateFeedUrlPayload>) {
const feed = payload.trim();
Expand Down Expand Up @@ -107,6 +107,7 @@ function* fetchEpisodes(): any {
}

function* importPodcast() {
yield setOnboardingPodcastSettings();
yield savePodcastMetadata();
yield fetchEpisodes();
yield put(actions.onboarding.next());
Expand Down
3 changes: 2 additions & 1 deletion client/src/sagas/podcast.saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { convertImageToBase64 } from '../lib/image';
import { actions } from '../store';
import * as request from '../lib/request';
import { type setPodcastCoverPayload } from '../store/podcast.store';
import { savePodcastMetadata } from './helpers/podcast';
import { setOnboardingPodcastSettings, savePodcastMetadata } from './helpers/podcast';


function readImage(file: File): Promise<string> {
Expand Down Expand Up @@ -34,6 +34,7 @@ function* removeImage() {


function* transferPodcast() {
yield setOnboardingPodcastSettings();
yield savePodcastMetadata();
yield put(actions.podcast.readFeedUrl());
yield put(actions.onboarding.next());
Expand Down
15 changes: 14 additions & 1 deletion server/lib/publisher/wordpress/podcast.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,21 @@ defmodule Publisher.WordPress.Podcast do
end
end

def set_settings(headers, _body) do
Logger.info("Padcast.set_settings")

req = API.new(headers)

with {:ok, response} <- Req.post(req, url: "podlove/v2/onboarding/setup"),
{:ok, _} <- extract_status(response) do
:ok
else
error -> error
end
end

def save_podcast_data(headers, body) do
Logger.log(:info, "Podcast.save_podcast_data")
Logger.info("Podcast.save_podcast_data")

payload = %{
title: body.name,
Expand Down
9 changes: 9 additions & 0 deletions server/lib/publisher_web/controllers/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ defmodule PublisherWeb.Controllers.API do
end)
end

def set_podcast_settings(conn, headers, body) do
with_validation(conn, headers_to_map(headers), Validator.WordPressAuthHeaders, fn conn, _ ->
case Podcast.set_settings(headers, body) do
:ok -> json(conn, %{})
{:error, reason} -> send_resp(conn, 400, "Error: #{reason}")
end
end)
end

def save_podcast(conn, headers, body) do
with_validation(conn, headers_to_map(headers), Validator.WordPressAuthHeaders, fn conn, _ ->
with_validation(conn, body, Validator.SavePodcast, fn conn, body_data ->
Expand Down
4 changes: 4 additions & 0 deletions server/lib/publisher_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ defmodule PublisherWeb.Router do
API.podcast_feed_url(conn, conn.req_headers)
end

post "api/v1/set_podcast_settings" do
API.set_podcast_settings(conn, conn.req_headers, conn.params)
end

post "/api/v1/save_podcast" do
API.save_podcast(conn, conn.req_headers, conn.params)
end
Expand Down

0 comments on commit f829477

Please sign in to comment.