@@ -13,7 +13,6 @@ import {
1313} from "../util/list/toast-component/display-toast" ;
1414import EventDatabaseApiFeedTypeTemplate from "./feed-source-type-templates/EventDatabaseApiFeedType.template" ;
1515import NotifiedFeedTypeTemplate from "./feed-source-type-templates/NotifiedFeedType.template" ;
16- import SparkleIOFeedTypeTemplate from "./feed-source-type-templates/SparkleIOFeedType.template" ;
1716import CalendarFeedTypeTemplate from "./feed-source-type-templates/CalendarFeedType.template" ;
1817
1918/**
@@ -25,6 +24,7 @@ import CalendarFeedTypeTemplate from "./feed-source-type-templates/CalendarFeedT
2524 * @param {string | null } props.id Theme id.
2625 * @param {boolean } props.isLoading Is the theme state loading?
2726 * @param {object } props.loadingError Loading error.
27+ * @param props.mode
2828 * @returns {object } The theme form.
2929 */
3030function FeedSourceManager ( {
@@ -33,13 +33,15 @@ function FeedSourceManager({
3333 isLoading = false ,
3434 loadingError = null ,
3535 initialState = null ,
36+ mode = null ,
3637} ) {
3738 // Hooks
3839 const { t } = useTranslation ( "common" , {
3940 keyPrefix : "feed-source-manager" ,
4041 } ) ;
4142 const navigate = useNavigate ( ) ;
4243
44+ const [ currentMode , setCurrentMode ] = useState ( ) ;
4345 // State
4446 const [ headerText ] = useState (
4547 saveMethod === "PUT" ? t ( "edit-feed-source" ) : t ( "create-new-feed-source" )
@@ -68,25 +70,19 @@ function FeedSourceManager({
6870 value : "App\\Feed\\EventDatabaseApiFeedType" ,
6971 title : t ( "dynamic-fields.EventDatabaseApiFeedType.title" ) ,
7072 key : "1" ,
71- template : < EventDatabaseApiFeedTypeTemplate /> ,
73+ template : < EventDatabaseApiFeedTypeTemplate mode = { currentMode } /> ,
7274 } ,
7375 {
7476 value : "App\\Feed\\NotifiedFeedType" ,
7577 title : t ( "dynamic-fields.NotifiedFeedType.title" ) ,
7678 key : "2" ,
77- template : < NotifiedFeedTypeTemplate /> ,
79+ template : < NotifiedFeedTypeTemplate mode = { currentMode } /> ,
7880 } ,
7981 {
8082 value : "App\\Feed\\CalendarApiFeedType" ,
8183 title : t ( "dynamic-fields.CalendarApiFeedType.title" ) ,
8284 key : "3" ,
83- template : < CalendarFeedTypeTemplate /> ,
84- } ,
85- {
86- value : "App\\Feed\\SparkleIOFeedType" ,
87- title : t ( "dynamic-fields.SparkleIOFeedType.title" ) ,
88- key : "4" ,
89- template : < SparkleIOFeedTypeTemplate /> ,
85+ template : < CalendarFeedTypeTemplate mode = { currentMode } /> ,
9086 } ,
9187 {
9288 value : "App\\Feed\\RssFeedType" ,
@@ -101,6 +97,9 @@ function FeedSourceManager({
10197 setFormStateObject ( initialState ) ;
10298 } , [ initialState ] ) ;
10399
100+ useEffect ( ( ) => {
101+ setCurrentMode ( mode ) ;
102+ } , [ mode ] ) ;
104103 const [ requiredSecrets , setRequiredSecrets ] = useState ( [ ] ) ;
105104
106105 useEffect ( ( ) => {
@@ -109,24 +108,17 @@ function FeedSourceManager({
109108 switch ( formStateObject . feedType ) {
110109 case "App\\Feed\\EventDatabaseApiFeedType" :
111110 newSecrets = {
112- host : formStateObject . host ,
111+ host : formStateObject . host ?? "" ,
113112 } ;
114113 break ;
115114 case "App\\Feed\\NotifiedFeedType" :
116115 newSecrets = {
117- token : formStateObject . token ,
116+ token : formStateObject . token ?? "" ,
118117 } ;
119118 break ;
120119 case "App\\Feed\\CalendarApiFeedType" :
121120 newSecrets = {
122- resources : formStateObject . resources ,
123- } ;
124- break ;
125- case "App\\Feed\\SparkleIOFeedType" :
126- newSecrets = {
127- BaseUrl : formStateObject . BaseUrl ,
128- clientId : formStateObject . clientId ,
129- clientSecret : formStateObject . clientSecret ,
121+ resources : formStateObject . resources ?? "" ,
130122 } ;
131123 break ;
132124 }
@@ -137,7 +129,7 @@ function FeedSourceManager({
137129 /** Save feed source. */
138130 function saveFeedSource ( ) {
139131 setLoadingMessage ( t ( "loading-messages.saving-feed-source" ) ) ;
140- const saveData = {
132+ let saveData = {
141133 title : formStateObject . title ,
142134 description : formStateObject . description ,
143135 feedType : formStateObject . feedType ,
@@ -149,6 +141,10 @@ function FeedSourceManager({
149141 } ,
150142 ] ,
151143 } ;
144+ if ( currentMode === "edit" ) {
145+ saveData = { ...formStateObject , ...saveData } ;
146+ }
147+
152148 if ( saveMethod === "POST" ) {
153149 postV2FeedSources ( {
154150 feedSourceFeedSourceInput : JSON . stringify ( saveData ) ,
@@ -265,6 +261,7 @@ FeedSourceManager.propTypes = {
265261 status : PropTypes . number ,
266262 } ) ,
267263 } ) ,
264+ mode : PropTypes . string ,
268265} ;
269266
270267export default FeedSourceManager ;
0 commit comments