From 55dd67d28e691338b4ecbe928436c4f2a41ad5cb Mon Sep 17 00:00:00 2001 From: kytwb Date: Sun, 2 Jan 2022 00:40:42 +0100 Subject: Revert "Removed straggling code related to popular services." This reverts commit a9c1abc6f11cb193388fad505c0304f1efe60a30. --- src/api/server/ServerApi.ts | 3 +- .../settings/recipes/RecipesDashboard.js | 4 +- src/containers/auth/WelcomeScreen.js | 2 +- src/containers/settings/RecipesScreen.js | 15 +- src/i18n/locales/fa.json | 23 +-- .../app/Controllers/Http/StaticController.js | 195 +++++++++++++++++++++ src/internal-server/start/routes.js | 2 + src/stores/RecipePreviewsStore.js | 11 +- 8 files changed, 221 insertions(+), 34 deletions(-) create mode 100644 src/internal-server/app/Controllers/Http/StaticController.js (limited to 'src') diff --git a/src/api/server/ServerApi.ts b/src/api/server/ServerApi.ts index 2fd1a8d0d..0144a1069 100644 --- a/src/api/server/ServerApi.ts +++ b/src/api/server/ServerApi.ts @@ -368,11 +368,12 @@ export default class ServerApi { } async getFeaturedRecipePreviews() { - // TODO: If we are hitting the internal-server, we need to return an empty list, else we can hit the remote server and get the data const request = await sendAuthRequest(`${apiBase()}/recipes/popular`); if (!request.ok) throw new Error(request.statusText); const data = await request.json(); + // data = this._addLocalRecipesToPreviews(data); + const recipePreviews = this._mapRecipePreviewModel(data); debug('ServerApi::getFeaturedRecipes resolves', recipePreviews); return recipePreviews; diff --git a/src/components/settings/recipes/RecipesDashboard.js b/src/components/settings/recipes/RecipesDashboard.js index 2d0d83376..96207445c 100644 --- a/src/components/settings/recipes/RecipesDashboard.js +++ b/src/components/settings/recipes/RecipesDashboard.js @@ -114,6 +114,7 @@ class RecipesDashboard extends Component { recipes: MobxPropTypes.arrayOrObservableArray.isRequired, customWebsiteRecipe: PropTypes.instanceOf(RecipePreview).isRequired, isLoading: PropTypes.bool.isRequired, + hasLoadedRecipes: PropTypes.bool.isRequired, showAddServiceInterface: PropTypes.func.isRequired, searchRecipes: PropTypes.func.isRequired, resetSearch: PropTypes.func.isRequired, @@ -136,6 +137,7 @@ class RecipesDashboard extends Component { recipes, customWebsiteRecipe, isLoading, + hasLoadedRecipes, showAddServiceInterface, searchRecipes, resetSearch, @@ -255,7 +257,7 @@ class RecipesDashboard extends Component { /> ))} - {recipes.length === 0 && recipeFilter !== 'dev' && ( + {hasLoadedRecipes && recipes.length === 0 && recipeFilter !== 'dev' && (
{customWebsiteRecipe && customWebsiteRecipe.id && ( ); } diff --git a/src/containers/settings/RecipesScreen.js b/src/containers/settings/RecipesScreen.js index b81336c12..e8f0a7282 100644 --- a/src/containers/settings/RecipesScreen.js +++ b/src/containers/settings/RecipesScreen.js @@ -54,6 +54,8 @@ class RecipesScreen extends Component { if (filter === 'all' && currentFilter !== 'all') { this.setState({ currentFilter: 'all' }); + } else if (filter === 'featured' && currentFilter !== 'featured') { + this.setState({ currentFilter: 'featured' }); } else if (filter === 'dev' && currentFilter !== 'dev') { this.setState({ currentFilter: 'dev' }); } @@ -113,7 +115,7 @@ class RecipesScreen extends Component { const { app: appActions, service: serviceActions } = this.props.actions; - const { filter } = { filter: 'all', ...this.props.params }; + const { filter } = this.props.params; let recipeFilter; if (filter === 'all') { @@ -123,6 +125,8 @@ class RecipesScreen extends Component { ]); } else if (filter === 'dev') { recipeFilter = communityRecipesStore.communityRecipes; + } else { + recipeFilter = recipePreviews.featured; } recipeFilter = recipeFilter.sort(this._sortByName); @@ -149,10 +153,10 @@ class RecipesScreen extends Component { service => service.id === CUSTOM_WEBSITE_RECIPE_ID, ); - const isLoading = - recipePreviews.allRecipePreviewsRequest.isExecuting || - recipes.installRecipeRequest.isExecuting || - recipePreviews.searchRecipePreviewsRequest.isExecuting; + const isLoading = recipePreviews.featuredRecipePreviewsRequest.isExecuting + || recipePreviews.allRecipePreviewsRequest.isExecuting + || recipes.installRecipeRequest.isExecuting + || recipePreviews.searchRecipePreviewsRequest.isExecuting; const recipeDirectory = userDataRecipesPath('dev'); @@ -163,6 +167,7 @@ class RecipesScreen extends Component { customWebsiteRecipe={customWebsiteRecipe} isLoading={isLoading} addedServiceCount={services.all.length} + hasLoadedRecipes={recipePreviews.featuredRecipePreviewsRequest.wasExecuted} showAddServiceInterface={serviceActions.showAddServiceInterface} searchRecipes={e => this.searchRecipes(e)} resetSearch={() => this.resetSearch()} diff --git a/src/i18n/locales/fa.json b/src/i18n/locales/fa.json index 1e72905d7..cb0a521e0 100644 --- a/src/i18n/locales/fa.json +++ b/src/i18n/locales/fa.json @@ -284,9 +284,9 @@ "settings.recipes.customService.intro": "To add a custom service, copy the service recipe folder inside:", "settings.recipes.customService.openDevDocs": "Developer Documentation", "settings.recipes.customService.openFolder": "Open folder", -<<<<<<< HEAD "settings.recipes.headline": "Available services", "settings.recipes.missingService": "Missing a service?", + "settings.recipes.mostPopular": "Most popular", "settings.recipes.nothingFound": "Sorry, but no service matched your search term - but you can still probably add it using the \"Custom Website\" option. Please note that the website might show more services that have been added to Ferdi since the version that you are currently on. To get those new services, please consider upgrading to a newer version of Ferdi.", "settings.recipes.servicesSuccessfulAddedInfo": "Service successfully added", "settings.searchService": "Search service", @@ -305,27 +305,6 @@ "settings.service.form.enableAudio": "Enable audio", "settings.service.form.enableBadge": "Show unread message badges", "settings.service.form.enableDarkMode": "Enable Dark Mode", -======= - "settings.recipes.headline": "سرویس های موجود", - "settings.recipes.missingService": "سرویسی را نیاز دارید ؟", - "settings.recipes.mostPopular": "مشهورترین ها", - "settings.recipes.nothingFound": "متاسفیم ، اما هیچ سرویسی با آنچه که جستجو کردید مطابقت نداشت .", - "settings.recipes.servicesSuccessfulAddedInfo": "سرویس با موفقیت اضافه شد", - "settings.searchService": "جستجوی سرویس ها", - "settings.service.error.goBack": "بازگشت به سرویس ها", - "settings.service.error.headline": "خطا ", - "settings.service.error.message": "دستورالعمل سرویس بارگذاری نشد.", - "settings.service.form.addServiceHeadline": "اضافه کردن {نام}", - "settings.service.form.availableServices": "سرویس های موجود", - "settings.service.form.customUrl": "سرور سفارشی", - "settings.service.form.customUrlPremiumInfo": "برای اضافه کردن سرویس هایی که خود دارید ، نیاز به پشتیبانی پیشرفته فرانز را دارید", - "settings.service.form.customUrlValidationError": "نتوانستیم سرور {نام} را تایید اعتبار کنیم", - "settings.service.form.deleteButton": "حذف سرویس", - "settings.service.form.editServiceHeadline": "ویرایش {name}", - "settings.service.form.enableAudio": "فعال‌سازی صدا", - "settings.service.form.enableBadge": "نماد پیام خوانده نشده را نشان بده ", - "settings.service.form.enableDarkMode": "فعالسازی حالت شب", ->>>>>>> parent of 1c1b3e1f... Removed 'Most Popular' services since it alludes to user-tracking (#1718) "settings.service.form.enableHibernation": "Enable hibernation", "settings.service.form.enableNotification": "Enable notifications", "settings.service.form.enableService": "Enable service", diff --git a/src/internal-server/app/Controllers/Http/StaticController.js b/src/internal-server/app/Controllers/Http/StaticController.js new file mode 100644 index 000000000..ef5764881 --- /dev/null +++ b/src/internal-server/app/Controllers/Http/StaticController.js @@ -0,0 +1,195 @@ +/** + * Controller for routes with static responses + */ + +class StaticController { + // Enable all features + features({ + response, + }) { + return response.send({ + isServiceProxyEnabled: true, + isWorkspaceEnabled: true, + isAnnouncementsEnabled: true, + isSettingsWSEnabled: false, + isMagicBarEnabled: true, + isTodosEnabled: true, + subscribeURL: 'https://getferdi.com', + hasInlineCheckout: true, + }); + } + + // Return an empty array + emptyArray({ + response, + }) { + return response.send([]); + } + + // Return list of popular recipes (copy of the response Franz's API is returning) + popularRecipes({ + response, + }) { + return response.send([{ + // TODO: Why is this list hardcoded? + author: 'Stefan Malzner ', + featured: false, + id: 'slack', + name: 'Slack', + version: '1.0.4', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/slack/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/slack/src/icon.svg', + }, + }, { + author: 'Stefan Malzner ', + featured: false, + id: 'whatsapp', + name: 'WhatsApp', + version: '1.0.1', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/whatsapp/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/whatsapp/src/icon.svg', + }, + }, { + author: 'Stefan Malzner ', + featured: false, + id: 'messenger', + name: 'Messenger', + version: '1.0.6', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/messenger/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/messenger/src/icon.svg', + }, + }, { + author: 'Stefan Malzner ', + featured: false, + id: 'telegram', + name: 'Telegram', + version: '1.0.0', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/telegram/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/telegram/src/icon.svg', + }, + }, { + author: 'Stefan Malzner ', + featured: false, + id: 'gmail', + name: 'Gmail', + version: '1.0.0', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/gmail/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/gmail/src/icon.svg', + }, + }, { + author: 'Stefan Malzner ', + featured: false, + id: 'skype', + name: 'Skype', + version: '1.0.0', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/skype/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/skype/src/icon.svg', + }, + }, { + author: 'Stefan Malzner ', + featured: false, + id: 'hangouts', + name: 'Hangouts', + version: '1.0.0', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/hangouts/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/hangouts/src/icon.svg', + }, + }, { + author: 'Stefan Malzner ', + featured: false, + id: 'discord', + name: 'Discord', + version: '1.0.0', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/discord/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/discord/src/icon.svg', + }, + }, { + author: 'Stefan Malzner ', + featured: false, + id: 'tweetdeck', + name: 'Tweetdeck', + version: '1.0.1', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/tweetdeck/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/tweetdeck/src/icon.svg', + }, + }, { + author: 'Stefan Malzner ', + featured: false, + id: 'hipchat', + name: 'HipChat', + version: '1.0.1', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/hipchat/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/hipchat/src/icon.svg', + }, + }, { + author: 'Stefan Malzner ', + featured: false, + id: 'rocketchat', + name: 'Rocket.Chat', + version: '1.0.1', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/rocketchat/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/rocketchat/src/icon.svg', + }, + }, { + author: 'Brian Gilbert ', + featured: false, + id: 'gitter', + name: 'Gitter', + version: '1.0.0', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/gitter/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/gitter/src/icon.svg', + }, + }, { + author: 'Stefan Malzner ', + featured: false, + id: 'mattermost', + name: 'Mattermost', + version: '1.0.0', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/mattermost/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/mattermost/src/icon.svg', + }, + }, { + author: 'Franz ', + featured: false, + id: 'toggl', + name: 'Toggl', + version: '1.0.0', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/toggl/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/toggl/src/icon.svg', + }, + }, { + author: 'Stuart Clark ', + featured: false, + id: 'twist', + name: 'Twist', + version: '1.0.0', + icons: { + png: 'https://cdn.franzinfra.com/recipes/dist/twist/src/icon.png', + svg: 'https://cdn.franzinfra.com/recipes/dist/twist/src/icon.svg', + }, + }]); + } + + // Show announcements + announcement({ + response, + }) { + return response.send({}); + } +} + +module.exports = StaticController; diff --git a/src/internal-server/start/routes.js b/src/internal-server/start/routes.js index 177035dac..4a63b51f2 100644 --- a/src/internal-server/start/routes.js +++ b/src/internal-server/start/routes.js @@ -55,6 +55,8 @@ Route.group(() => { Route.get('recipes', 'RecipeController.list'); Route.get('recipes/download/:recipe', 'RecipeController.download'); Route.get('recipes/search', 'RecipeController.search'); + Route.get('recipes/popular', 'StaticController.popularRecipes'); + Route.get('recipes/update', 'StaticController.emptyArray'); // Workspaces Route.put('workspace/:id', 'WorkspaceController.edit'); diff --git a/src/stores/RecipePreviewsStore.js b/src/stores/RecipePreviewsStore.js index e01e8fc6f..ef0bca430 100644 --- a/src/stores/RecipePreviewsStore.js +++ b/src/stores/RecipePreviewsStore.js @@ -10,10 +10,9 @@ export default class RecipePreviewsStore extends Store { 'all', ); - @observable searchRecipePreviewsRequest = new Request( - this.api.recipePreviews, - 'search', - ); + @observable featuredRecipePreviewsRequest = new CachedRequest(this.api.recipePreviews, 'featured'); + + @observable searchRecipePreviewsRequest = new Request(this.api.recipePreviews, 'search'); constructor(...args) { super(...args); @@ -26,6 +25,10 @@ export default class RecipePreviewsStore extends Store { return this.allRecipePreviewsRequest.execute().result || []; } + @computed get featured() { + return this.featuredRecipePreviewsRequest.execute().result || []; + } + @computed get searchResults() { return this.searchRecipePreviewsRequest.result || []; } -- cgit v1.2.3-70-g09d2