Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Adiciona projetos em pré-lançamento nos cards de explore. #1250

Merged
merged 1 commit into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions services/catarse/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ def update_reminders
if params[:user][:reminders][:"#{project_id}"] == 'false'
Project.find(project_id).delete_from_reminder_queue(@user.id)
@user.reminders.where(project_id: project_id).destroy_all
else
ProjectMetricStorageRefreshWorker.perform_async(project_id)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,22 @@ class ProjectMetricStorageRefreshWorker < ProjectBaseWorker

def perform(id)
_resource = resource(id)
can_refresh = !%w[draft deleted].include?(_resource.state)

_resource.refresh_project_metric_storage if can_refresh
_resource.refresh_project_metric_storage if can_refresh?(_resource)
end

private

def not_comming_soon_landing_page?(project)
project.state != 'draft' ||
(project.state == 'draft' && project.has_comming_soon_landing_page_integration?)
end

def not_in_deleted?(project)
project.state != 'deleted'
end

def can_refresh?(project)
not_in_deleted?(project) && not_comming_soon_landing_page?(project)
end
end
19 changes: 8 additions & 11 deletions services/catarse/catarse.js/legacy/spec/lib/mocks/project.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ beforeAll(function(){
"open_for_contributions":false,
"online_days":60,
"remaining_time":{
"total" : 0,
"total" : 0,
"unit" : "seconds"
},
"elapsed_time":{
"total" : 0,
"total" : 0,
"unit" : "seconds"
},
"posts_count":0,
"address":{
"city" : "fda",
"state_acronym" : "RS",
"city" : "fda",
"state_acronym" : "RS",
"state" : "Rio Grande do Sul"
},
"user":{
"id" : 3,
"name" : "test test",
"id" : 3,
"name" : "test test",
"public_name" : "Test1"
},
"reminder_count":0,
Expand Down Expand Up @@ -133,7 +133,7 @@ beforeAll(function(){


ProjectsGenerator = function(numberOfProjects, overrides, url) {

const projectBase = {
project_id: 5,
category_id: 1,
Expand Down Expand Up @@ -172,7 +172,7 @@ beforeAll(function(){
common_id: "a60eec2e-dbe0-4efb-876c-e8c5ec0c8adc",
is_adult_content: false,
content_rating: 1,
saved_projects: true
active_saved_projects: true
};

const projects = [];
Expand All @@ -190,6 +190,3 @@ beforeAll(function(){
});

});



Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const ExploreProjectsList = {
if (project.score >= 1) {
ref = 'ctrse_explore_featured';
}
} else if (filterKeyName === 'saved_projects') {
} else if (filterKeyName === 'active_saved_projects') {
ref = 'ctrse_explore_saved_project';
} else if (filterKeyName === 'projects_we_love') {
ref = 'ctrse_explore_projects_we_love';
Expand All @@ -44,4 +44,4 @@ export const ExploreProjectsList = {
])
]);
}
};
};
45 changes: 28 additions & 17 deletions services/catarse/catarse.js/legacy/src/c/project-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import h from '../h';
import projectVM from '../vms/project-vm';
import projectFriends from './project-friends';
import progressMeter from './progress-meter';
import { ComingSoonLandingPageExploreRemindButton } from '../root/projects/coming-soon-landing-page-explore-remind-button';

const I18nScope = _.partial(h.i18nScope, 'projects.card');
const projectCard = {
Expand Down Expand Up @@ -88,12 +89,12 @@ const projectCard = {
view: function({state, attrs}) {
const project = attrs.project;
const projectOwnerName = project.user ? (project.user.public_name || project.user.name) : (project.owner_public_name || project.owner_name);

const projectLocalizationObject = {
filter: 'all',
city_name: project.address ? project.address.city : project.city_name,
state_acronym: project.address ? project.address.state_acronym : project.state_acronym,
};
};
const projectLocalizationSearchUrl = `/explore?${m.buildQueryString(projectLocalizationObject)}`
const projectLocalizationName = project.address ? `${project.address.city}, ${project.address.state_acronym}` : `${project.city_name}, ${project.state_acronym}`;

Expand All @@ -115,7 +116,7 @@ const projectCard = {
}),
(
project.recommended &&
m('div.loved-projects-container',
m('div.loved-projects-container',
m(`a.loved-projects-badge[href="/${window.I18n.locale}/explore?filter=projects_we_love"]`, 'Projeto que amamos')
)
),
Expand All @@ -135,21 +136,31 @@ const projectCard = {
}, project.headline)
])
]),
m(progressMeter, { progress: state.progress, project }),
m('.card-project-stats', [
m('.w-row', [
m('.w-col.w-col-4.w-col-small-4.w-col-tiny-4', [
m('.fontsize-base.fontweight-semibold', `${Math.floor(project.progress)}%`)
]),
m('.w-col.w-col-4.w-col-small-4.w-col-tiny-4.u-text-center-small-only', [
m('.fontsize-smaller.fontweight-semibold', `R$ ${h.formatNumber(project.pledged)}`),
m('.fontsize-smallest.lineheight-tightest', window.I18n.t(`pledged.${project.mode}`, I18nScope()))
project.state === 'draft' ?
[
m(ComingSoonLandingPageExploreRemindButton, {
project: project,
isFollowing: project.in_reminder
})
] :
[
m(progressMeter, { progress: state.progress, project }),
m('.card-project-stats', [
m('.w-row', [
m('.w-col.w-col-4.w-col-small-4.w-col-tiny-4', [
m('.fontsize-base.fontweight-semibold', `${Math.floor(project.progress)}%`)
]),
m('.w-col.w-col-4.w-col-small-4.w-col-tiny-4.u-text-center-small-only', [
m('.fontsize-smaller.fontweight-semibold', `R$ ${h.formatNumber(project.pledged)}`),
m('.fontsize-smallest.lineheight-tightest', window.I18n.t(`pledged.${project.mode}`, I18nScope()))
]),
m('.w-col.w-col-4.w-col-small-4.w-col-tiny-4.u-text-right', state.cardCopy(project)),
])
]),
m('.w-col.w-col-4.w-col-small-4.w-col-tiny-4.u-text-right', state.cardCopy(project)),
])
]),
m(state.css().city,
],
m(state.css().city,
m('div', [
project.state != 'draft' ?
m('div',
m(`a.link-hidden-dark.fontsize-smallest.fontcolor-secondary[href="${projectLocalizationSearchUrl}"]`, {
onclick: (/** @type {Event} */ event) => {
Expand All @@ -160,7 +171,7 @@ const projectCard = {
m('span.fa.fa-map-marker.fa-sm', ' '),
` ${projectLocalizationName}`
])
),
) : m('br'),
m('div',
m(`a.link-hidden-dark.fontsize-smallest.fontcolor-secondary[href="${projectCategorySearchUrl}"]`, {
onclick: (/** @type {Event} */ event) => {
Expand Down
4 changes: 2 additions & 2 deletions services/catarse/catarse.js/legacy/src/c/projects-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const projectsDisplay = {
sample3 = _.partial(_.sample, _, 3),
loader = catarse.loaderWithToken,
project = models.project,
subHomeWith6CollectionsFilters = ['projects_we_love_not_sub', 'sub', 'covid_19', 'contributed_by_friends'],
subHomeWith6CollectionsFilters = ['projects_we_love_not_sub', 'sub', 'covid_19', 'contributed_by_friends', 'coming_soon_landing_page'],
windowEventNOTDispatched = true;

project.pageSize(20);
Expand Down Expand Up @@ -52,7 +52,7 @@ const projectsDisplay = {
.then(() => m.redraw());

const query = f.query || {};

if (!f.query) {
if (f.mode) {
query.mode = f.mode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ interface Platform {
}

interface Project {
project_id: number;
in_reminder: boolean;
id: string;
mode: string;
name: string;
Expand Down
5 changes: 3 additions & 2 deletions services/catarse/catarse.js/legacy/src/entities/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export type Project = {
common_id: string;
is_adult_content: boolean;
content_rating: number;
saved_projects: boolean;
integrations: ProjectIntegration[];
category_name: string;
};
active_saved_projects: boolean;
in_reminder: boolean;
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ export class ExploreLightBox {
mode: 'covid_19',
}
},
{
name: 'Em breve no Catarse',
query: {
filter: 'coming_soon_landing_page',
}
},
userVM.isLoggedIn ? {
name: 'Projetos Salvos',
query: {
filter: 'saved_projects',
filter: 'active_saved_projects',
}
} : null,
userVM.isLoggedIn ? {
Expand Down Expand Up @@ -80,7 +86,7 @@ export class ExploreLightBox {
};

/**
* @param {{name: string, keyName: string}} filter
* @param {{name: string, keyName: string}} filter
* @returns {ListItem}
*/
const mapFiltersToItems = (filter) => {
Expand All @@ -103,7 +109,7 @@ export class ExploreLightBox {
};
};

return m('div.explore-lightbox',
return m('div.explore-lightbox',
m('div.explore-lightbox-container.w-clearfix', [
m('a.modal-close-container.fa.fa-2x.fa-close.w-inline-block[href="#"]', { onclick: closePreventRedirect }),

Expand Down Expand Up @@ -137,7 +143,7 @@ class ExploreLightBoxList {
*/

/**
* @param {{ attrs: Attrs }} vnode
* @param {{ attrs: Attrs }} vnode
*/
view({attrs}) {

Expand All @@ -147,7 +153,7 @@ class ExploreLightBoxList {
const onSelect = attrs.onSelect;

return m('div.u-marginbottom-30', [
m('div.u-margintop-30',
m('div.u-margintop-30',
m('div.fontsize-base.fontcolor-terciary', title)
),
items.map(item => {
Expand All @@ -165,16 +171,16 @@ class ExploreLightBoxList {
}

class ExploreLightBoxListItem {

/**
* @typedef Attrs
* @property {() => void} onSelect
* @property {() => void} onSelect
* @property {string} url
* @property {string} label
*/

/**
* @param {{ attrs: Attrs }} vnode
* @param {{ attrs: Attrs }} vnode
*/
view({attrs}) {
const label = attrs.label;
Expand All @@ -189,4 +195,4 @@ class ExploreLightBoxListItem {
}
}, label);
}
}
}
31 changes: 31 additions & 0 deletions services/catarse/catarse.js/legacy/src/root/projects-explore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { I18ScopeType, ThisWindow } from '../entities/window';
import ExploreMobileSearch from '../c/explore/explore-mobile-search';
import { getCurrentUserCached } from '../shared/services/user/get-current-user-cached';
import { isLoggedIn } from '../shared/services/user/is-logged-in';
import { removeRemindProject } from './projects/controllers/removeRemindProject'
import { remindProject } from './projects/controllers/remindProject'
import { catarse } from '../api'
import models from '../models';

declare var window : ThisWindow

Expand Down Expand Up @@ -109,6 +113,33 @@ const projectsExplore : m.Component<ProjectExploreAttrs, ProjectExploreState> =
return cityState as CityState;
};

function findRemindProjectInLocalStorage() {
const reminder = parseInt(localStorage.getItem('reminder'));

if (isLoggedIn(getCurrentUserCached()) && reminder) {
const lProjectsDetails = catarse.loaderWithToken(models.projectDetail.getPageOptions(
catarse.filtersVM({ project_id: 'eq' }).project_id(reminder).parameters())
);
lProjectsDetails.load().then((data) => { remindProjectInLocalStorage(_.first(data)) });
}

localStorage.removeItem('reminder');
}

function remindProjectInLocalStorage(projectsDetails) {
try {
remindProject(projectsDetails)
h.redraw()
h.storeAction('display_pop', 'success')
h.storeAction('set_bookmarked', projectsDetails.id)
} catch (error) {
h.redraw()
h.storeAction('display_pop', 'error')
}
}

findRemindProjectInLocalStorage()

vnode.state = {
projectsExploreVM,
hasFBAuth,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.save-project-card-wrapper {
-webkit-box-align: stretch;
-webkit-box-direction: normal;
-webkit-box-orient: vertical;
-webkit-box-pack: center;
align-items: stretch;
box-sizing: border-box;
color: #3f4752;
display: flex;
flex-direction: column;
font-family: proxima-nova, sans-serif;
font-size: 14px;
height: 82px;
justify-content: center;
line-height: 20px;
padding-left: 13px;
padding-right: 13px;
}
Loading