<commit_before>import { Component, OnInit, OnDestroy, Input } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { AlertService } from '../alert/alert.service';
import { UserService } from '../user/user.service';
import { BidService } from '../bid/bid.service';

@Component({
    selector: "auction",
    templateUrl: "./auction.component.html",
})
export class AuctionComponent implements OnInit, OnDestroy{

    private userSignedIn: boolean = false;
    subscription: Subscription;
    private currentUser: any = {};

    @Input() private auction: any;

    constructor(private _userService: UserService, private alertService: AlertService, private bidService: BidService) {
        let user = _userService.getCurrentUser();
        if(user){
            this.currentUser = user;
            this.userSignedIn = true;
        }
    }

    public bid() {
        this.bidService.bidAuction(this.currentUser, this.auction).then(
            (bid) => {
                // THIS SHOULD OCCUR IN PARSE SERVER
                this.auction.increment("bids");
                this.auction.increment("currentPrice", 0.01);
                this.auction.save();
                this.alertService.success("Subastado con éxito!");
                // THIS SHOULD OCCUR IN PARSE SERVER
            }).catch(
                (error) => {
                    this.alertService.error(error.message);
                }
            );
    }

    public ngOnInit() {
        this.determineUserSignedIn();
    }

    public ngOnDestroy() {
        this.subscription.unsubscribe();
        this.currentUser = null;
        this.userSignedIn = false;
    }


    public determineUserSignedIn() {
        this.subscription = this._userService.userLoggedIn.subscribe(
            user => {
                if (user) {
                    this.currentUser = user;
                    this.userSignedIn = true;
                }
            }
        );
    }

    public isUserSignedIn() {<commit_msg>#16 refresh current user when doing thingsg<commit_after>import { Component, OnInit, OnDestroy, Input } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { AlertService } from '../alert/alert.service';
import { UserService } from '../user/user.service';
import { BidService } from '../bid/bid.service';

@Component({
    selector: "auction",
    templateUrl: "./auction.component.html",
})
export class AuctionComponent implements OnInit, OnDestroy{

    private userSignedIn: boolean = false;
    subscription: Subscription;
    private currentUser: any = {};

    @Input() private auction: any;

    constructor(private _userService: UserService, private alertService: AlertService, private bidService: BidService) {
        let user = _userService.getCurrentUser();
        if(user){
            this.currentUser = user;
            this.userSignedIn = true;
        }
    }

    public bid() {
        this.currentUser.fetch(); // REMOTE THIS WHEN WE HAVE A WAY OF ADDING CREDITS
        console.log("this.currentUser.get('credits') = " + this.currentUser.get('credits'));
        if ( this.currentUser.get('credits') <= 0 ) {
            this.alertService.error("No tienes suficientes créditos.");
        } else {
            this.bidService.bidAuction(this.currentUser, this.auction).then(
                (bid) => {
                    // THIS SHOULD OCCUR IN PARSE SERVER
                    this.currentUser.increment('credits', -1);
                    this.currentUser.save();
                    this.auction.increment("bids");
                    this.auction.increment("currentPrice", 0.01);
                    this.auction.save();
                    // THIS SHOULD OCCUR IN PARSE SERVER
                    this.currentUser.fetch();
                    this.alertService.success("Subastado con éxito!");
                }).catch(
                    (error) => {
                        this.alertService.error(error.message);
                    }
                );
        }
    }

    public ngOnInit() {
        this.determineUserSignedIn();
    }

    public ngOnDestroy() {
        this.subscription.unsubscribe();
        this.currentUser = null;
        this.userSignedIn = false;
    }


    public determineUserSignedIn() {
        this.subscription = this._userService.userLoggedIn.subscribe(
            user => {
                if (user) {
                    this.currentUser = user;
                    this.userSignedIn = true;
                }
            }
        );
    }

    public isUserSignedIn() {
{'fraction_non_alphanumeric': 0.11472902097902098, 'fraction_numerical': 0.0021853146853146855, 'mean_word_length': 1.8822418136020151, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '804852', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1213, 'n_words': 259}